]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/doc/md.texi
dbxout.c (dbxout_symbol_location): Pass new argument to alter_subreg.
[thirdparty/gcc.git] / gcc / doc / md.texi
CommitLineData
b5e01d4b 1@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001,
55a2c322 2@c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
66647d44 3@c Free Software Foundation, Inc.
03dda8e3
RK
4@c This is part of the GCC manual.
5@c For copying conditions, see the file gcc.texi.
6
7@ifset INTERNALS
8@node Machine Desc
9@chapter Machine Descriptions
10@cindex machine descriptions
11
12A machine description has two parts: a file of instruction patterns
13(@file{.md} file) and a C header file of macro definitions.
14
15The @file{.md} file for a target machine contains a pattern for each
16instruction that the target machine supports (or at least each instruction
17that is worth telling the compiler about). It may also contain comments.
18A semicolon causes the rest of the line to be a comment, unless the semicolon
19is inside a quoted string.
20
21See the next chapter for information on the C header file.
22
23@menu
55e4756f 24* Overview:: How the machine description is used.
03dda8e3
RK
25* Patterns:: How to write instruction patterns.
26* Example:: An explained example of a @code{define_insn} pattern.
27* RTL Template:: The RTL template defines what insns match a pattern.
28* Output Template:: The output template says how to make assembler code
6ccde948 29 from such an insn.
03dda8e3 30* Output Statement:: For more generality, write C code to output
6ccde948 31 the assembler code.
e543e219 32* Predicates:: Controlling what kinds of operands can be used
6ccde948 33 for an insn.
e543e219 34* Constraints:: Fine-tuning operand selection.
03dda8e3
RK
35* Standard Names:: Names mark patterns to use for code generation.
36* Pattern Ordering:: When the order of patterns makes a difference.
37* Dependent Patterns:: Having one pattern may make you need another.
38* Jump Patterns:: Special considerations for patterns for jump insns.
6e4fcc95 39* Looping Patterns:: How to define patterns for special looping insns.
03dda8e3 40* Insn Canonicalizations::Canonicalization of Instructions
03dda8e3 41* Expander Definitions::Generating a sequence of several RTL insns
6ccde948 42 for a standard operation.
f3a3d0d3 43* Insn Splitting:: Splitting Instructions into Multiple Instructions.
6ccde948 44* Including Patterns:: Including Patterns in Machine Descriptions.
f3a3d0d3 45* Peephole Definitions::Defining machine-specific peephole optimizations.
03dda8e3 46* Insn Attributes:: Specifying the value of attributes for generated insns.
3262c1f5 47* Conditional Execution::Generating @code{define_insn} patterns for
6ccde948 48 predication.
c25c12b8
R
49* Constant Definitions::Defining symbolic constants that can be used in the
50 md file.
3abcb3a7 51* Iterators:: Using iterators to generate patterns from a template.
03dda8e3
RK
52@end menu
53
55e4756f
DD
54@node Overview
55@section Overview of How the Machine Description is Used
56
57There are three main conversions that happen in the compiler:
58
59@enumerate
60
61@item
62The front end reads the source code and builds a parse tree.
63
64@item
65The parse tree is used to generate an RTL insn list based on named
66instruction patterns.
67
68@item
69The insn list is matched against the RTL templates to produce assembler
70code.
71
72@end enumerate
73
74For the generate pass, only the names of the insns matter, from either a
75named @code{define_insn} or a @code{define_expand}. The compiler will
76choose the pattern with the right name and apply the operands according
77to the documentation later in this chapter, without regard for the RTL
78template or operand constraints. Note that the names the compiler looks
d7d9c429 79for are hard-coded in the compiler---it will ignore unnamed patterns and
55e4756f
DD
80patterns with names it doesn't know about, but if you don't provide a
81named pattern it needs, it will abort.
82
83If a @code{define_insn} is used, the template given is inserted into the
84insn list. If a @code{define_expand} is used, one of three things
85happens, based on the condition logic. The condition logic may manually
86create new insns for the insn list, say via @code{emit_insn()}, and
aee96fe9 87invoke @code{DONE}. For certain named patterns, it may invoke @code{FAIL} to tell the
55e4756f
DD
88compiler to use an alternate way of performing that task. If it invokes
89neither @code{DONE} nor @code{FAIL}, the template given in the pattern
90is inserted, as if the @code{define_expand} were a @code{define_insn}.
91
92Once the insn list is generated, various optimization passes convert,
93replace, and rearrange the insns in the insn list. This is where the
94@code{define_split} and @code{define_peephole} patterns get used, for
95example.
96
97Finally, the insn list's RTL is matched up with the RTL templates in the
98@code{define_insn} patterns, and those patterns are used to emit the
99final assembly code. For this purpose, each named @code{define_insn}
100acts like it's unnamed, since the names are ignored.
101
03dda8e3
RK
102@node Patterns
103@section Everything about Instruction Patterns
104@cindex patterns
105@cindex instruction patterns
106
107@findex define_insn
108Each instruction pattern contains an incomplete RTL expression, with pieces
109to be filled in later, operand constraints that restrict how the pieces can
110be filled in, and an output pattern or C code to generate the assembler
111output, all wrapped up in a @code{define_insn} expression.
112
113A @code{define_insn} is an RTL expression containing four or five operands:
114
115@enumerate
116@item
117An optional name. The presence of a name indicate that this instruction
118pattern can perform a certain standard job for the RTL-generation
119pass of the compiler. This pass knows certain names and will use
120the instruction patterns with those names, if the names are defined
121in the machine description.
122
123The absence of a name is indicated by writing an empty string
124where the name should go. Nameless instruction patterns are never
125used for generating RTL code, but they may permit several simpler insns
126to be combined later on.
127
128Names that are not thus known and used in RTL-generation have no
129effect; they are equivalent to no name at all.
130
661cb0b7
RK
131For the purpose of debugging the compiler, you may also specify a
132name beginning with the @samp{*} character. Such a name is used only
133for identifying the instruction in RTL dumps; it is entirely equivalent
134to having a nameless pattern for all other purposes.
135
03dda8e3
RK
136@item
137The @dfn{RTL template} (@pxref{RTL Template}) is a vector of incomplete
138RTL expressions which show what the instruction should look like. It is
139incomplete because it may contain @code{match_operand},
140@code{match_operator}, and @code{match_dup} expressions that stand for
141operands of the instruction.
142
143If the vector has only one element, that element is the template for the
144instruction pattern. If the vector has multiple elements, then the
145instruction pattern is a @code{parallel} expression containing the
146elements described.
147
148@item
149@cindex pattern conditions
150@cindex conditions, in patterns
151A condition. This is a string which contains a C expression that is
152the final test to decide whether an insn body matches this pattern.
153
154@cindex named patterns and conditions
155For a named pattern, the condition (if present) may not depend on
156the data in the insn being matched, but only the target-machine-type
157flags. The compiler needs to test these conditions during
158initialization in order to learn exactly which named instructions are
159available in a particular run.
160
161@findex operands
162For nameless patterns, the condition is applied only when matching an
163individual insn, and only after the insn has matched the pattern's
164recognition template. The insn's operands may be found in the vector
fde6d81f
HPN
165@code{operands}. For an insn where the condition has once matched, it
166can't be used to control register allocation, for example by excluding
167certain hard registers or hard register combinations.
03dda8e3
RK
168
169@item
170The @dfn{output template}: a string that says how to output matching
171insns as assembler code. @samp{%} in this string specifies where
172to substitute the value of an operand. @xref{Output Template}.
173
174When simple substitution isn't general enough, you can specify a piece
175of C code to compute the output. @xref{Output Statement}.
176
177@item
178Optionally, a vector containing the values of attributes for insns matching
179this pattern. @xref{Insn Attributes}.
180@end enumerate
181
182@node Example
183@section Example of @code{define_insn}
184@cindex @code{define_insn} example
185
186Here is an actual example of an instruction pattern, for the 68000/68020.
187
3ab51846 188@smallexample
03dda8e3
RK
189(define_insn "tstsi"
190 [(set (cc0)
191 (match_operand:SI 0 "general_operand" "rm"))]
192 ""
193 "*
f282ffb3 194@{
0f40f9f7 195 if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
03dda8e3 196 return \"tstl %0\";
f282ffb3 197 return \"cmpl #0,%0\";
0f40f9f7 198@}")
3ab51846 199@end smallexample
0f40f9f7
ZW
200
201@noindent
202This can also be written using braced strings:
203
3ab51846 204@smallexample
0f40f9f7
ZW
205(define_insn "tstsi"
206 [(set (cc0)
207 (match_operand:SI 0 "general_operand" "rm"))]
208 ""
f282ffb3 209@{
0f40f9f7
ZW
210 if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
211 return "tstl %0";
f282ffb3 212 return "cmpl #0,%0";
0f40f9f7 213@})
3ab51846 214@end smallexample
03dda8e3
RK
215
216This is an instruction that sets the condition codes based on the value of
217a general operand. It has no condition, so any insn whose RTL description
218has the form shown may be handled according to this pattern. The name
219@samp{tstsi} means ``test a @code{SImode} value'' and tells the RTL generation
220pass that, when it is necessary to test such a value, an insn to do so
221can be constructed using this pattern.
222
223The output control string is a piece of C code which chooses which
224output template to return based on the kind of operand and the specific
225type of CPU for which code is being generated.
226
227@samp{"rm"} is an operand constraint. Its meaning is explained below.
228
229@node RTL Template
230@section RTL Template
231@cindex RTL insn template
232@cindex generating insns
233@cindex insns, generating
234@cindex recognizing insns
235@cindex insns, recognizing
236
237The RTL template is used to define which insns match the particular pattern
238and how to find their operands. For named patterns, the RTL template also
239says how to construct an insn from specified operands.
240
241Construction involves substituting specified operands into a copy of the
242template. Matching involves determining the values that serve as the
243operands in the insn being matched. Both of these activities are
244controlled by special expression types that direct matching and
245substitution of the operands.
246
247@table @code
248@findex match_operand
249@item (match_operand:@var{m} @var{n} @var{predicate} @var{constraint})
250This expression is a placeholder for operand number @var{n} of
251the insn. When constructing an insn, operand number @var{n}
252will be substituted at this point. When matching an insn, whatever
253appears at this position in the insn will be taken as operand
254number @var{n}; but it must satisfy @var{predicate} or this instruction
255pattern will not match at all.
256
257Operand numbers must be chosen consecutively counting from zero in
258each instruction pattern. There may be only one @code{match_operand}
259expression in the pattern for each operand number. Usually operands
260are numbered in the order of appearance in @code{match_operand}
72938a4c
MM
261expressions. In the case of a @code{define_expand}, any operand numbers
262used only in @code{match_dup} expressions have higher values than all
263other operand numbers.
03dda8e3 264
e543e219
ZW
265@var{predicate} is a string that is the name of a function that
266accepts two arguments, an expression and a machine mode.
267@xref{Predicates}. During matching, the function will be called with
268the putative operand as the expression and @var{m} as the mode
269argument (if @var{m} is not specified, @code{VOIDmode} will be used,
270which normally causes @var{predicate} to accept any mode). If it
271returns zero, this instruction pattern fails to match.
272@var{predicate} may be an empty string; then it means no test is to be
273done on the operand, so anything which occurs in this position is
274valid.
03dda8e3
RK
275
276Most of the time, @var{predicate} will reject modes other than @var{m}---but
277not always. For example, the predicate @code{address_operand} uses
278@var{m} as the mode of memory ref that the address should be valid for.
279Many predicates accept @code{const_int} nodes even though their mode is
280@code{VOIDmode}.
281
282@var{constraint} controls reloading and the choice of the best register
283class to use for a value, as explained later (@pxref{Constraints}).
e543e219 284If the constraint would be an empty string, it can be omitted.
03dda8e3
RK
285
286People are often unclear on the difference between the constraint and the
287predicate. The predicate helps decide whether a given insn matches the
288pattern. The constraint plays no role in this decision; instead, it
289controls various decisions in the case of an insn which does match.
290
03dda8e3
RK
291@findex match_scratch
292@item (match_scratch:@var{m} @var{n} @var{constraint})
293This expression is also a placeholder for operand number @var{n}
294and indicates that operand must be a @code{scratch} or @code{reg}
295expression.
296
297When matching patterns, this is equivalent to
298
299@smallexample
300(match_operand:@var{m} @var{n} "scratch_operand" @var{pred})
301@end smallexample
302
303but, when generating RTL, it produces a (@code{scratch}:@var{m})
304expression.
305
306If the last few expressions in a @code{parallel} are @code{clobber}
307expressions whose operands are either a hard register or
308@code{match_scratch}, the combiner can add or delete them when
309necessary. @xref{Side Effects}.
310
311@findex match_dup
312@item (match_dup @var{n})
313This expression is also a placeholder for operand number @var{n}.
314It is used when the operand needs to appear more than once in the
315insn.
316
317In construction, @code{match_dup} acts just like @code{match_operand}:
318the operand is substituted into the insn being constructed. But in
319matching, @code{match_dup} behaves differently. It assumes that operand
320number @var{n} has already been determined by a @code{match_operand}
321appearing earlier in the recognition template, and it matches only an
322identical-looking expression.
323
55e4756f
DD
324Note that @code{match_dup} should not be used to tell the compiler that
325a particular register is being used for two operands (example:
326@code{add} that adds one register to another; the second register is
327both an input operand and the output operand). Use a matching
328constraint (@pxref{Simple Constraints}) for those. @code{match_dup} is for the cases where one
329operand is used in two places in the template, such as an instruction
330that computes both a quotient and a remainder, where the opcode takes
331two input operands but the RTL template has to refer to each of those
332twice; once for the quotient pattern and once for the remainder pattern.
333
03dda8e3
RK
334@findex match_operator
335@item (match_operator:@var{m} @var{n} @var{predicate} [@var{operands}@dots{}])
336This pattern is a kind of placeholder for a variable RTL expression
337code.
338
339When constructing an insn, it stands for an RTL expression whose
340expression code is taken from that of operand @var{n}, and whose
341operands are constructed from the patterns @var{operands}.
342
343When matching an expression, it matches an expression if the function
344@var{predicate} returns nonzero on that expression @emph{and} the
345patterns @var{operands} match the operands of the expression.
346
347Suppose that the function @code{commutative_operator} is defined as
348follows, to match any expression whose operator is one of the
349commutative arithmetic operators of RTL and whose mode is @var{mode}:
350
351@smallexample
352int
ec8e098d 353commutative_integer_operator (x, mode)
03dda8e3
RK
354 rtx x;
355 enum machine_mode mode;
356@{
357 enum rtx_code code = GET_CODE (x);
358 if (GET_MODE (x) != mode)
359 return 0;
ec8e098d 360 return (GET_RTX_CLASS (code) == RTX_COMM_ARITH
03dda8e3
RK
361 || code == EQ || code == NE);
362@}
363@end smallexample
364
365Then the following pattern will match any RTL expression consisting
366of a commutative operator applied to two general operands:
367
368@smallexample
369(match_operator:SI 3 "commutative_operator"
370 [(match_operand:SI 1 "general_operand" "g")
371 (match_operand:SI 2 "general_operand" "g")])
372@end smallexample
373
374Here the vector @code{[@var{operands}@dots{}]} contains two patterns
375because the expressions to be matched all contain two operands.
376
377When this pattern does match, the two operands of the commutative
378operator are recorded as operands 1 and 2 of the insn. (This is done
379by the two instances of @code{match_operand}.) Operand 3 of the insn
380will be the entire commutative expression: use @code{GET_CODE
381(operands[3])} to see which commutative operator was used.
382
383The machine mode @var{m} of @code{match_operator} works like that of
384@code{match_operand}: it is passed as the second argument to the
385predicate function, and that function is solely responsible for
386deciding whether the expression to be matched ``has'' that mode.
387
388When constructing an insn, argument 3 of the gen-function will specify
e979f9e8 389the operation (i.e.@: the expression code) for the expression to be
03dda8e3
RK
390made. It should be an RTL expression, whose expression code is copied
391into a new expression whose operands are arguments 1 and 2 of the
392gen-function. The subexpressions of argument 3 are not used;
393only its expression code matters.
394
395When @code{match_operator} is used in a pattern for matching an insn,
396it usually best if the operand number of the @code{match_operator}
397is higher than that of the actual operands of the insn. This improves
398register allocation because the register allocator often looks at
399operands 1 and 2 of insns to see if it can do register tying.
400
401There is no way to specify constraints in @code{match_operator}. The
402operand of the insn which corresponds to the @code{match_operator}
403never has any constraints because it is never reloaded as a whole.
404However, if parts of its @var{operands} are matched by
405@code{match_operand} patterns, those parts may have constraints of
406their own.
407
408@findex match_op_dup
409@item (match_op_dup:@var{m} @var{n}[@var{operands}@dots{}])
410Like @code{match_dup}, except that it applies to operators instead of
411operands. When constructing an insn, operand number @var{n} will be
412substituted at this point. But in matching, @code{match_op_dup} behaves
413differently. It assumes that operand number @var{n} has already been
414determined by a @code{match_operator} appearing earlier in the
415recognition template, and it matches only an identical-looking
416expression.
417
418@findex match_parallel
419@item (match_parallel @var{n} @var{predicate} [@var{subpat}@dots{}])
420This pattern is a placeholder for an insn that consists of a
421@code{parallel} expression with a variable number of elements. This
422expression should only appear at the top level of an insn pattern.
423
424When constructing an insn, operand number @var{n} will be substituted at
425this point. When matching an insn, it matches if the body of the insn
426is a @code{parallel} expression with at least as many elements as the
427vector of @var{subpat} expressions in the @code{match_parallel}, if each
428@var{subpat} matches the corresponding element of the @code{parallel},
429@emph{and} the function @var{predicate} returns nonzero on the
430@code{parallel} that is the body of the insn. It is the responsibility
431of the predicate to validate elements of the @code{parallel} beyond
bd819a4a 432those listed in the @code{match_parallel}.
03dda8e3
RK
433
434A typical use of @code{match_parallel} is to match load and store
435multiple expressions, which can contain a variable number of elements
436in a @code{parallel}. For example,
03dda8e3
RK
437
438@smallexample
439(define_insn ""
440 [(match_parallel 0 "load_multiple_operation"
441 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
442 (match_operand:SI 2 "memory_operand" "m"))
443 (use (reg:SI 179))
444 (clobber (reg:SI 179))])]
445 ""
446 "loadm 0,0,%1,%2")
447@end smallexample
448
449This example comes from @file{a29k.md}. The function
9c34dbbf 450@code{load_multiple_operation} is defined in @file{a29k.c} and checks
03dda8e3
RK
451that subsequent elements in the @code{parallel} are the same as the
452@code{set} in the pattern, except that they are referencing subsequent
453registers and memory locations.
454
455An insn that matches this pattern might look like:
456
457@smallexample
458(parallel
459 [(set (reg:SI 20) (mem:SI (reg:SI 100)))
460 (use (reg:SI 179))
461 (clobber (reg:SI 179))
462 (set (reg:SI 21)
463 (mem:SI (plus:SI (reg:SI 100)
464 (const_int 4))))
465 (set (reg:SI 22)
466 (mem:SI (plus:SI (reg:SI 100)
467 (const_int 8))))])
468@end smallexample
469
470@findex match_par_dup
471@item (match_par_dup @var{n} [@var{subpat}@dots{}])
472Like @code{match_op_dup}, but for @code{match_parallel} instead of
473@code{match_operator}.
474
03dda8e3
RK
475@end table
476
477@node Output Template
478@section Output Templates and Operand Substitution
479@cindex output templates
480@cindex operand substitution
481
482@cindex @samp{%} in template
483@cindex percent sign
484The @dfn{output template} is a string which specifies how to output the
485assembler code for an instruction pattern. Most of the template is a
486fixed string which is output literally. The character @samp{%} is used
487to specify where to substitute an operand; it can also be used to
488identify places where different variants of the assembler require
489different syntax.
490
491In the simplest case, a @samp{%} followed by a digit @var{n} says to output
492operand @var{n} at that point in the string.
493
494@samp{%} followed by a letter and a digit says to output an operand in an
495alternate fashion. Four letters have standard, built-in meanings described
496below. The machine description macro @code{PRINT_OPERAND} can define
497additional letters with nonstandard meanings.
498
499@samp{%c@var{digit}} can be used to substitute an operand that is a
500constant value without the syntax that normally indicates an immediate
501operand.
502
503@samp{%n@var{digit}} is like @samp{%c@var{digit}} except that the value of
504the constant is negated before printing.
505
506@samp{%a@var{digit}} can be used to substitute an operand as if it were a
507memory reference, with the actual operand treated as the address. This may
508be useful when outputting a ``load address'' instruction, because often the
509assembler syntax for such an instruction requires you to write the operand
510as if it were a memory reference.
511
512@samp{%l@var{digit}} is used to substitute a @code{label_ref} into a jump
513instruction.
514
515@samp{%=} outputs a number which is unique to each instruction in the
516entire compilation. This is useful for making local labels to be
517referred to more than once in a single template that generates multiple
518assembler instructions.
519
520@samp{%} followed by a punctuation character specifies a substitution that
521does not use an operand. Only one case is standard: @samp{%%} outputs a
522@samp{%} into the assembler code. Other nonstandard cases can be
523defined in the @code{PRINT_OPERAND} macro. You must also define
524which punctuation characters are valid with the
525@code{PRINT_OPERAND_PUNCT_VALID_P} macro.
526
527@cindex \
528@cindex backslash
529The template may generate multiple assembler instructions. Write the text
530for the instructions, with @samp{\;} between them.
531
532@cindex matching operands
533When the RTL contains two operands which are required by constraint to match
534each other, the output template must refer only to the lower-numbered operand.
535Matching operands are not always identical, and the rest of the compiler
536arranges to put the proper RTL expression for printing into the lower-numbered
537operand.
538
539One use of nonstandard letters or punctuation following @samp{%} is to
540distinguish between different assembler languages for the same machine; for
541example, Motorola syntax versus MIT syntax for the 68000. Motorola syntax
542requires periods in most opcode names, while MIT syntax does not. For
543example, the opcode @samp{movel} in MIT syntax is @samp{move.l} in Motorola
544syntax. The same file of patterns is used for both kinds of output syntax,
545but the character sequence @samp{%.} is used in each place where Motorola
546syntax wants a period. The @code{PRINT_OPERAND} macro for Motorola syntax
547defines the sequence to output a period; the macro for MIT syntax defines
548it to do nothing.
549
550@cindex @code{#} in template
551As a special case, a template consisting of the single character @code{#}
552instructs the compiler to first split the insn, and then output the
553resulting instructions separately. This helps eliminate redundancy in the
554output templates. If you have a @code{define_insn} that needs to emit
e4ae5e77 555multiple assembler instructions, and there is a matching @code{define_split}
03dda8e3
RK
556already defined, then you can simply use @code{#} as the output template
557instead of writing an output template that emits the multiple assembler
558instructions.
559
560If the macro @code{ASSEMBLER_DIALECT} is defined, you can use construct
561of the form @samp{@{option0|option1|option2@}} in the templates. These
562describe multiple variants of assembler language syntax.
563@xref{Instruction Output}.
564
565@node Output Statement
566@section C Statements for Assembler Output
567@cindex output statements
568@cindex C statements for assembler output
569@cindex generating assembler output
570
571Often a single fixed template string cannot produce correct and efficient
572assembler code for all the cases that are recognized by a single
573instruction pattern. For example, the opcodes may depend on the kinds of
574operands; or some unfortunate combinations of operands may require extra
575machine instructions.
576
577If the output control string starts with a @samp{@@}, then it is actually
578a series of templates, each on a separate line. (Blank lines and
579leading spaces and tabs are ignored.) The templates correspond to the
580pattern's constraint alternatives (@pxref{Multi-Alternative}). For example,
581if a target machine has a two-address add instruction @samp{addr} to add
582into a register and another @samp{addm} to add a register to memory, you
583might write this pattern:
584
585@smallexample
586(define_insn "addsi3"
587 [(set (match_operand:SI 0 "general_operand" "=r,m")
588 (plus:SI (match_operand:SI 1 "general_operand" "0,0")
589 (match_operand:SI 2 "general_operand" "g,r")))]
590 ""
591 "@@
592 addr %2,%0
593 addm %2,%0")
594@end smallexample
595
596@cindex @code{*} in template
597@cindex asterisk in template
598If the output control string starts with a @samp{*}, then it is not an
599output template but rather a piece of C program that should compute a
600template. It should execute a @code{return} statement to return the
601template-string you want. Most such templates use C string literals, which
602require doublequote characters to delimit them. To include these
603doublequote characters in the string, prefix each one with @samp{\}.
604
0f40f9f7
ZW
605If the output control string is written as a brace block instead of a
606double-quoted string, it is automatically assumed to be C code. In that
607case, it is not necessary to put in a leading asterisk, or to escape the
608doublequotes surrounding C string literals.
609
03dda8e3
RK
610The operands may be found in the array @code{operands}, whose C data type
611is @code{rtx []}.
612
613It is very common to select different ways of generating assembler code
614based on whether an immediate operand is within a certain range. Be
615careful when doing this, because the result of @code{INTVAL} is an
616integer on the host machine. If the host machine has more bits in an
617@code{int} than the target machine has in the mode in which the constant
618will be used, then some of the bits you get from @code{INTVAL} will be
619superfluous. For proper results, you must carefully disregard the
620values of those bits.
621
622@findex output_asm_insn
623It is possible to output an assembler instruction and then go on to output
624or compute more of them, using the subroutine @code{output_asm_insn}. This
625receives two arguments: a template-string and a vector of operands. The
626vector may be @code{operands}, or it may be another array of @code{rtx}
627that you declare locally and initialize yourself.
628
629@findex which_alternative
630When an insn pattern has multiple alternatives in its constraints, often
631the appearance of the assembler code is determined mostly by which alternative
632was matched. When this is so, the C code can test the variable
633@code{which_alternative}, which is the ordinal number of the alternative
634that was actually satisfied (0 for the first, 1 for the second alternative,
635etc.).
636
637For example, suppose there are two opcodes for storing zero, @samp{clrreg}
638for registers and @samp{clrmem} for memory locations. Here is how
639a pattern could use @code{which_alternative} to choose between them:
640
641@smallexample
642(define_insn ""
643 [(set (match_operand:SI 0 "general_operand" "=r,m")
644 (const_int 0))]
645 ""
0f40f9f7 646 @{
03dda8e3 647 return (which_alternative == 0
0f40f9f7
ZW
648 ? "clrreg %0" : "clrmem %0");
649 @})
03dda8e3
RK
650@end smallexample
651
652The example above, where the assembler code to generate was
653@emph{solely} determined by the alternative, could also have been specified
654as follows, having the output control string start with a @samp{@@}:
655
656@smallexample
657@group
658(define_insn ""
659 [(set (match_operand:SI 0 "general_operand" "=r,m")
660 (const_int 0))]
661 ""
662 "@@
663 clrreg %0
664 clrmem %0")
665@end group
666@end smallexample
e543e219 667
94c765ab
R
668If you just need a little bit of C code in one (or a few) alternatives,
669you can use @samp{*} inside of a @samp{@@} multi-alternative template:
670
671@smallexample
672@group
673(define_insn ""
674 [(set (match_operand:SI 0 "general_operand" "=r,<,m")
675 (const_int 0))]
676 ""
677 "@@
678 clrreg %0
679 * return stack_mem_p (operands[0]) ? \"push 0\" : \"clrmem %0\";
680 clrmem %0")
681@end group
682@end smallexample
683
e543e219
ZW
684@node Predicates
685@section Predicates
686@cindex predicates
687@cindex operand predicates
688@cindex operator predicates
689
690A predicate determines whether a @code{match_operand} or
691@code{match_operator} expression matches, and therefore whether the
692surrounding instruction pattern will be used for that combination of
693operands. GCC has a number of machine-independent predicates, and you
694can define machine-specific predicates as needed. By convention,
695predicates used with @code{match_operand} have names that end in
696@samp{_operand}, and those used with @code{match_operator} have names
697that end in @samp{_operator}.
698
699All predicates are Boolean functions (in the mathematical sense) of
700two arguments: the RTL expression that is being considered at that
701position in the instruction pattern, and the machine mode that the
702@code{match_operand} or @code{match_operator} specifies. In this
703section, the first argument is called @var{op} and the second argument
704@var{mode}. Predicates can be called from C as ordinary two-argument
705functions; this can be useful in output templates or other
706machine-specific code.
707
708Operand predicates can allow operands that are not actually acceptable
709to the hardware, as long as the constraints give reload the ability to
710fix them up (@pxref{Constraints}). However, GCC will usually generate
711better code if the predicates specify the requirements of the machine
712instructions as closely as possible. Reload cannot fix up operands
713that must be constants (``immediate operands''); you must use a
714predicate that allows only constants, or else enforce the requirement
715in the extra condition.
716
717@cindex predicates and machine modes
718@cindex normal predicates
719@cindex special predicates
720Most predicates handle their @var{mode} argument in a uniform manner.
721If @var{mode} is @code{VOIDmode} (unspecified), then @var{op} can have
722any mode. If @var{mode} is anything else, then @var{op} must have the
723same mode, unless @var{op} is a @code{CONST_INT} or integer
724@code{CONST_DOUBLE}. These RTL expressions always have
725@code{VOIDmode}, so it would be counterproductive to check that their
726mode matches. Instead, predicates that accept @code{CONST_INT} and/or
727integer @code{CONST_DOUBLE} check that the value stored in the
728constant will fit in the requested mode.
729
730Predicates with this behavior are called @dfn{normal}.
731@command{genrecog} can optimize the instruction recognizer based on
732knowledge of how normal predicates treat modes. It can also diagnose
733certain kinds of common errors in the use of normal predicates; for
734instance, it is almost always an error to use a normal predicate
735without specifying a mode.
736
737Predicates that do something different with their @var{mode} argument
738are called @dfn{special}. The generic predicates
739@code{address_operand} and @code{pmode_register_operand} are special
740predicates. @command{genrecog} does not do any optimizations or
741diagnosis when special predicates are used.
742
743@menu
744* Machine-Independent Predicates:: Predicates available to all back ends.
745* Defining Predicates:: How to write machine-specific predicate
746 functions.
747@end menu
748
749@node Machine-Independent Predicates
750@subsection Machine-Independent Predicates
751@cindex machine-independent predicates
752@cindex generic predicates
753
754These are the generic predicates available to all back ends. They are
755defined in @file{recog.c}. The first category of predicates allow
756only constant, or @dfn{immediate}, operands.
757
758@defun immediate_operand
759This predicate allows any sort of constant that fits in @var{mode}.
760It is an appropriate choice for instructions that take operands that
761must be constant.
762@end defun
763
764@defun const_int_operand
765This predicate allows any @code{CONST_INT} expression that fits in
766@var{mode}. It is an appropriate choice for an immediate operand that
767does not allow a symbol or label.
768@end defun
769
770@defun const_double_operand
771This predicate accepts any @code{CONST_DOUBLE} expression that has
772exactly @var{mode}. If @var{mode} is @code{VOIDmode}, it will also
773accept @code{CONST_INT}. It is intended for immediate floating point
774constants.
775@end defun
776
777@noindent
778The second category of predicates allow only some kind of machine
779register.
780
781@defun register_operand
782This predicate allows any @code{REG} or @code{SUBREG} expression that
783is valid for @var{mode}. It is often suitable for arithmetic
784instruction operands on a RISC machine.
785@end defun
786
787@defun pmode_register_operand
788This is a slight variant on @code{register_operand} which works around
789a limitation in the machine-description reader.
790
cd1a8088 791@smallexample
e543e219 792(match_operand @var{n} "pmode_register_operand" @var{constraint})
cd1a8088 793@end smallexample
e543e219
ZW
794
795@noindent
796means exactly what
797
cd1a8088 798@smallexample
e543e219 799(match_operand:P @var{n} "register_operand" @var{constraint})
cd1a8088 800@end smallexample
e543e219
ZW
801
802@noindent
803would mean, if the machine-description reader accepted @samp{:P}
804mode suffixes. Unfortunately, it cannot, because @code{Pmode} is an
805alias for some other mode, and might vary with machine-specific
8a36672b 806options. @xref{Misc}.
e543e219
ZW
807@end defun
808
809@defun scratch_operand
810This predicate allows hard registers and @code{SCRATCH} expressions,
811but not pseudo-registers. It is used internally by @code{match_scratch};
812it should not be used directly.
813@end defun
814
815@noindent
816The third category of predicates allow only some kind of memory reference.
817
818@defun memory_operand
819This predicate allows any valid reference to a quantity of mode
820@var{mode} in memory, as determined by the weak form of
821@code{GO_IF_LEGITIMATE_ADDRESS} (@pxref{Addressing Modes}).
822@end defun
823
824@defun address_operand
825This predicate is a little unusual; it allows any operand that is a
826valid expression for the @emph{address} of a quantity of mode
827@var{mode}, again determined by the weak form of
828@code{GO_IF_LEGITIMATE_ADDRESS}. To first order, if
829@samp{@w{(mem:@var{mode} (@var{exp}))}} is acceptable to
830@code{memory_operand}, then @var{exp} is acceptable to
831@code{address_operand}. Note that @var{exp} does not necessarily have
832the mode @var{mode}.
833@end defun
834
835@defun indirect_operand
836This is a stricter form of @code{memory_operand} which allows only
837memory references with a @code{general_operand} as the address
838expression. New uses of this predicate are discouraged, because
839@code{general_operand} is very permissive, so it's hard to tell what
840an @code{indirect_operand} does or does not allow. If a target has
841different requirements for memory operands for different instructions,
842it is better to define target-specific predicates which enforce the
843hardware's requirements explicitly.
844@end defun
845
846@defun push_operand
847This predicate allows a memory reference suitable for pushing a value
848onto the stack. This will be a @code{MEM} which refers to
849@code{stack_pointer_rtx}, with a side-effect in its address expression
850(@pxref{Incdec}); which one is determined by the
851@code{STACK_PUSH_CODE} macro (@pxref{Frame Layout}).
852@end defun
853
854@defun pop_operand
855This predicate allows a memory reference suitable for popping a value
856off the stack. Again, this will be a @code{MEM} referring to
857@code{stack_pointer_rtx}, with a side-effect in its address
858expression. However, this time @code{STACK_POP_CODE} is expected.
859@end defun
860
861@noindent
862The fourth category of predicates allow some combination of the above
863operands.
864
865@defun nonmemory_operand
866This predicate allows any immediate or register operand valid for @var{mode}.
867@end defun
868
869@defun nonimmediate_operand
870This predicate allows any register or memory operand valid for @var{mode}.
871@end defun
872
873@defun general_operand
874This predicate allows any immediate, register, or memory operand
875valid for @var{mode}.
876@end defun
877
878@noindent
c6963675 879Finally, there are two generic operator predicates.
e543e219
ZW
880
881@defun comparison_operator
882This predicate matches any expression which performs an arithmetic
883comparison in @var{mode}; that is, @code{COMPARISON_P} is true for the
884expression code.
885@end defun
886
c6963675
PB
887@defun ordered_comparison_operator
888This predicate matches any expression which performs an arithmetic
889comparison in @var{mode} and whose expression code is valid for integer
890modes; that is, the expression code will be one of @code{eq}, @code{ne},
891@code{lt}, @code{ltu}, @code{le}, @code{leu}, @code{gt}, @code{gtu},
892@code{ge}, @code{geu}.
893@end defun
894
e543e219
ZW
895@node Defining Predicates
896@subsection Defining Machine-Specific Predicates
897@cindex defining predicates
898@findex define_predicate
899@findex define_special_predicate
900
901Many machines have requirements for their operands that cannot be
902expressed precisely using the generic predicates. You can define
903additional predicates using @code{define_predicate} and
904@code{define_special_predicate} expressions. These expressions have
905three operands:
906
907@itemize @bullet
908@item
909The name of the predicate, as it will be referred to in
910@code{match_operand} or @code{match_operator} expressions.
911
912@item
913An RTL expression which evaluates to true if the predicate allows the
914operand @var{op}, false if it does not. This expression can only use
915the following RTL codes:
916
917@table @code
918@item MATCH_OPERAND
919When written inside a predicate expression, a @code{MATCH_OPERAND}
920expression evaluates to true if the predicate it names would allow
921@var{op}. The operand number and constraint are ignored. Due to
922limitations in @command{genrecog}, you can only refer to generic
923predicates and predicates that have already been defined.
924
925@item MATCH_CODE
6e7a4706
ZW
926This expression evaluates to true if @var{op} or a specified
927subexpression of @var{op} has one of a given list of RTX codes.
928
929The first operand of this expression is a string constant containing a
930comma-separated list of RTX code names (in lower case). These are the
931codes for which the @code{MATCH_CODE} will be true.
932
933The second operand is a string constant which indicates what
934subexpression of @var{op} to examine. If it is absent or the empty
935string, @var{op} itself is examined. Otherwise, the string constant
936must be a sequence of digits and/or lowercase letters. Each character
937indicates a subexpression to extract from the current expression; for
938the first character this is @var{op}, for the second and subsequent
939characters it is the result of the previous character. A digit
940@var{n} extracts @samp{@w{XEXP (@var{e}, @var{n})}}; a letter @var{l}
941extracts @samp{@w{XVECEXP (@var{e}, 0, @var{n})}} where @var{n} is the
942alphabetic ordinal of @var{l} (0 for `a', 1 for 'b', and so on). The
943@code{MATCH_CODE} then examines the RTX code of the subexpression
944extracted by the complete string. It is not possible to extract
945components of an @code{rtvec} that is not at position 0 within its RTX
946object.
e543e219
ZW
947
948@item MATCH_TEST
949This expression has one operand, a string constant containing a C
950expression. The predicate's arguments, @var{op} and @var{mode}, are
951available with those names in the C expression. The @code{MATCH_TEST}
952evaluates to true if the C expression evaluates to a nonzero value.
953@code{MATCH_TEST} expressions must not have side effects.
954
955@item AND
956@itemx IOR
957@itemx NOT
958@itemx IF_THEN_ELSE
959The basic @samp{MATCH_} expressions can be combined using these
960logical operators, which have the semantics of the C operators
6e7a4706
ZW
961@samp{&&}, @samp{||}, @samp{!}, and @samp{@w{? :}} respectively. As
962in Common Lisp, you may give an @code{AND} or @code{IOR} expression an
963arbitrary number of arguments; this has exactly the same effect as
964writing a chain of two-argument @code{AND} or @code{IOR} expressions.
e543e219
ZW
965@end table
966
967@item
f0eb93a8 968An optional block of C code, which should execute
e543e219
ZW
969@samp{@w{return true}} if the predicate is found to match and
970@samp{@w{return false}} if it does not. It must not have any side
971effects. The predicate arguments, @var{op} and @var{mode}, are
972available with those names.
973
974If a code block is present in a predicate definition, then the RTL
975expression must evaluate to true @emph{and} the code block must
976execute @samp{@w{return true}} for the predicate to allow the operand.
977The RTL expression is evaluated first; do not re-check anything in the
978code block that was checked in the RTL expression.
979@end itemize
980
981The program @command{genrecog} scans @code{define_predicate} and
982@code{define_special_predicate} expressions to determine which RTX
983codes are possibly allowed. You should always make this explicit in
984the RTL predicate expression, using @code{MATCH_OPERAND} and
985@code{MATCH_CODE}.
986
987Here is an example of a simple predicate definition, from the IA64
988machine description:
989
990@smallexample
991@group
992;; @r{True if @var{op} is a @code{SYMBOL_REF} which refers to the sdata section.}
993(define_predicate "small_addr_symbolic_operand"
994 (and (match_code "symbol_ref")
995 (match_test "SYMBOL_REF_SMALL_ADDR_P (op)")))
996@end group
997@end smallexample
998
999@noindent
1000And here is another, showing the use of the C block.
1001
1002@smallexample
1003@group
1004;; @r{True if @var{op} is a register operand that is (or could be) a GR reg.}
1005(define_predicate "gr_register_operand"
1006 (match_operand 0 "register_operand")
1007@{
1008 unsigned int regno;
1009 if (GET_CODE (op) == SUBREG)
1010 op = SUBREG_REG (op);
1011
1012 regno = REGNO (op);
1013 return (regno >= FIRST_PSEUDO_REGISTER || GENERAL_REGNO_P (regno));
1014@})
1015@end group
1016@end smallexample
1017
1018Predicates written with @code{define_predicate} automatically include
1019a test that @var{mode} is @code{VOIDmode}, or @var{op} has the same
1020mode as @var{mode}, or @var{op} is a @code{CONST_INT} or
1021@code{CONST_DOUBLE}. They do @emph{not} check specifically for
1022integer @code{CONST_DOUBLE}, nor do they test that the value of either
1023kind of constant fits in the requested mode. This is because
1024target-specific predicates that take constants usually have to do more
1025stringent value checks anyway. If you need the exact same treatment
1026of @code{CONST_INT} or @code{CONST_DOUBLE} that the generic predicates
1027provide, use a @code{MATCH_OPERAND} subexpression to call
1028@code{const_int_operand}, @code{const_double_operand}, or
1029@code{immediate_operand}.
1030
1031Predicates written with @code{define_special_predicate} do not get any
1032automatic mode checks, and are treated as having special mode handling
1033by @command{genrecog}.
1034
1035The program @command{genpreds} is responsible for generating code to
1036test predicates. It also writes a header file containing function
1037declarations for all machine-specific predicates. It is not necessary
1038to declare these predicates in @file{@var{cpu}-protos.h}.
03dda8e3
RK
1039@end ifset
1040
1041@c Most of this node appears by itself (in a different place) even
b11cc610
JM
1042@c when the INTERNALS flag is clear. Passages that require the internals
1043@c manual's context are conditionalized to appear only in the internals manual.
03dda8e3
RK
1044@ifset INTERNALS
1045@node Constraints
1046@section Operand Constraints
1047@cindex operand constraints
1048@cindex constraints
1049
e543e219
ZW
1050Each @code{match_operand} in an instruction pattern can specify
1051constraints for the operands allowed. The constraints allow you to
1052fine-tune matching within the set of operands allowed by the
1053predicate.
1054
03dda8e3
RK
1055@end ifset
1056@ifclear INTERNALS
1057@node Constraints
1058@section Constraints for @code{asm} Operands
1059@cindex operand constraints, @code{asm}
1060@cindex constraints, @code{asm}
1061@cindex @code{asm} constraints
1062
1063Here are specific details on what constraint letters you can use with
1064@code{asm} operands.
1065@end ifclear
1066Constraints can say whether
1067an operand may be in a register, and which kinds of register; whether the
1068operand can be a memory reference, and which kinds of address; whether the
1069operand may be an immediate constant, and which possible values it may
1070have. Constraints can also require two operands to match.
54f044eb
JJ
1071Side-effects aren't allowed in operands of inline @code{asm}, unless
1072@samp{<} or @samp{>} constraints are used, because there is no guarantee
1073that the side-effects will happen exactly once in an instruction that can update
1074the addressing register.
03dda8e3
RK
1075
1076@ifset INTERNALS
1077@menu
1078* Simple Constraints:: Basic use of constraints.
1079* Multi-Alternative:: When an insn has two alternative constraint-patterns.
1080* Class Preferences:: Constraints guide which hard register to put things in.
1081* Modifiers:: More precise control over effects of constraints.
7ac28727 1082* Disable Insn Alternatives:: Disable insn alternatives using the @code{enabled} attribute.
03dda8e3 1083* Machine Constraints:: Existing constraints for some particular machines.
f38840db
ZW
1084* Define Constraints:: How to define machine-specific constraints.
1085* C Constraint Interface:: How to test constraints from C code.
03dda8e3
RK
1086@end menu
1087@end ifset
1088
1089@ifclear INTERNALS
1090@menu
1091* Simple Constraints:: Basic use of constraints.
1092* Multi-Alternative:: When an insn has two alternative constraint-patterns.
1093* Modifiers:: More precise control over effects of constraints.
1094* Machine Constraints:: Special constraints for some particular machines.
1095@end menu
1096@end ifclear
1097
1098@node Simple Constraints
1099@subsection Simple Constraints
1100@cindex simple constraints
1101
1102The simplest kind of constraint is a string full of letters, each of
1103which describes one kind of operand that is permitted. Here are
1104the letters that are allowed:
1105
1106@table @asis
88a56c2e
HPN
1107@item whitespace
1108Whitespace characters are ignored and can be inserted at any position
1109except the first. This enables each alternative for different operands to
1110be visually aligned in the machine description even if they have different
1111number of constraints and modifiers.
1112
03dda8e3
RK
1113@cindex @samp{m} in constraint
1114@cindex memory references in constraints
1115@item @samp{m}
1116A memory operand is allowed, with any kind of address that the machine
1117supports in general.
a4edaf83
AK
1118Note that the letter used for the general memory constraint can be
1119re-defined by a back end using the @code{TARGET_MEM_CONSTRAINT} macro.
03dda8e3
RK
1120
1121@cindex offsettable address
1122@cindex @samp{o} in constraint
1123@item @samp{o}
1124A memory operand is allowed, but only if the address is
1125@dfn{offsettable}. This means that adding a small integer (actually,
1126the width in bytes of the operand, as determined by its machine mode)
1127may be added to the address and the result is also a valid memory
1128address.
1129
1130@cindex autoincrement/decrement addressing
1131For example, an address which is constant is offsettable; so is an
1132address that is the sum of a register and a constant (as long as a
1133slightly larger constant is also within the range of address-offsets
1134supported by the machine); but an autoincrement or autodecrement
1135address is not offsettable. More complicated indirect/indexed
1136addresses may or may not be offsettable depending on the other
1137addressing modes that the machine supports.
1138
1139Note that in an output operand which can be matched by another
1140operand, the constraint letter @samp{o} is valid only when accompanied
1141by both @samp{<} (if the target machine has predecrement addressing)
1142and @samp{>} (if the target machine has preincrement addressing).
1143
1144@cindex @samp{V} in constraint
1145@item @samp{V}
1146A memory operand that is not offsettable. In other words, anything that
1147would fit the @samp{m} constraint but not the @samp{o} constraint.
1148
1149@cindex @samp{<} in constraint
1150@item @samp{<}
1151A memory operand with autodecrement addressing (either predecrement or
54f044eb
JJ
1152postdecrement) is allowed. In inline @code{asm} this constraint is only
1153allowed if the operand is used exactly once in an instruction that can
1154handle the side-effects. Not using an operand with @samp{<} in constraint
1155string in the inline @code{asm} pattern at all or using it in multiple
1156instructions isn't valid, because the side-effects wouldn't be performed
1157or would be performed more than once. Furthermore, on some targets
1158the operand with @samp{<} in constraint string must be accompanied by
1159special instruction suffixes like @code{%U0} instruction suffix on PowerPC
1160or @code{%P0} on IA-64.
03dda8e3
RK
1161
1162@cindex @samp{>} in constraint
1163@item @samp{>}
1164A memory operand with autoincrement addressing (either preincrement or
54f044eb
JJ
1165postincrement) is allowed. In inline @code{asm} the same restrictions
1166as for @samp{<} apply.
03dda8e3
RK
1167
1168@cindex @samp{r} in constraint
1169@cindex registers in constraints
1170@item @samp{r}
1171A register operand is allowed provided that it is in a general
1172register.
1173
03dda8e3
RK
1174@cindex constants in constraints
1175@cindex @samp{i} in constraint
1176@item @samp{i}
1177An immediate integer operand (one with constant value) is allowed.
1178This includes symbolic constants whose values will be known only at
8ac658b6 1179assembly time or later.
03dda8e3
RK
1180
1181@cindex @samp{n} in constraint
1182@item @samp{n}
1183An immediate integer operand with a known numeric value is allowed.
1184Many systems cannot support assembly-time constants for operands less
1185than a word wide. Constraints for these operands should use @samp{n}
1186rather than @samp{i}.
1187
1188@cindex @samp{I} in constraint
1189@item @samp{I}, @samp{J}, @samp{K}, @dots{} @samp{P}
1190Other letters in the range @samp{I} through @samp{P} may be defined in
1191a machine-dependent fashion to permit immediate integer operands with
1192explicit integer values in specified ranges. For example, on the
119368000, @samp{I} is defined to stand for the range of values 1 to 8.
1194This is the range permitted as a shift count in the shift
1195instructions.
1196
1197@cindex @samp{E} in constraint
1198@item @samp{E}
1199An immediate floating operand (expression code @code{const_double}) is
1200allowed, but only if the target floating point format is the same as
1201that of the host machine (on which the compiler is running).
1202
1203@cindex @samp{F} in constraint
1204@item @samp{F}
bf7cd754
R
1205An immediate floating operand (expression code @code{const_double} or
1206@code{const_vector}) is allowed.
03dda8e3
RK
1207
1208@cindex @samp{G} in constraint
1209@cindex @samp{H} in constraint
1210@item @samp{G}, @samp{H}
1211@samp{G} and @samp{H} may be defined in a machine-dependent fashion to
1212permit immediate floating operands in particular ranges of values.
1213
1214@cindex @samp{s} in constraint
1215@item @samp{s}
1216An immediate integer operand whose value is not an explicit integer is
1217allowed.
1218
1219This might appear strange; if an insn allows a constant operand with a
1220value not known at compile time, it certainly must allow any known
1221value. So why use @samp{s} instead of @samp{i}? Sometimes it allows
1222better code to be generated.
1223
1224For example, on the 68000 in a fullword instruction it is possible to
630d3d5a 1225use an immediate operand; but if the immediate value is between @minus{}128
03dda8e3
RK
1226and 127, better code results from loading the value into a register and
1227using the register. This is because the load into the register can be
1228done with a @samp{moveq} instruction. We arrange for this to happen
1229by defining the letter @samp{K} to mean ``any integer outside the
630d3d5a 1230range @minus{}128 to 127'', and then specifying @samp{Ks} in the operand
03dda8e3
RK
1231constraints.
1232
1233@cindex @samp{g} in constraint
1234@item @samp{g}
1235Any register, memory or immediate integer operand is allowed, except for
1236registers that are not general registers.
1237
1238@cindex @samp{X} in constraint
1239@item @samp{X}
1240@ifset INTERNALS
1241Any operand whatsoever is allowed, even if it does not satisfy
1242@code{general_operand}. This is normally used in the constraint of
1243a @code{match_scratch} when certain alternatives will not actually
1244require a scratch register.
1245@end ifset
1246@ifclear INTERNALS
1247Any operand whatsoever is allowed.
1248@end ifclear
1249
1250@cindex @samp{0} in constraint
1251@cindex digits in constraint
1252@item @samp{0}, @samp{1}, @samp{2}, @dots{} @samp{9}
1253An operand that matches the specified operand number is allowed. If a
1254digit is used together with letters within the same alternative, the
1255digit should come last.
1256
84b72302 1257This number is allowed to be more than a single digit. If multiple
c0478a66 1258digits are encountered consecutively, they are interpreted as a single
84b72302
RH
1259decimal integer. There is scant chance for ambiguity, since to-date
1260it has never been desirable that @samp{10} be interpreted as matching
1261either operand 1 @emph{or} operand 0. Should this be desired, one
1262can use multiple alternatives instead.
1263
03dda8e3
RK
1264@cindex matching constraint
1265@cindex constraint, matching
1266This is called a @dfn{matching constraint} and what it really means is
1267that the assembler has only a single operand that fills two roles
1268@ifset INTERNALS
1269considered separate in the RTL insn. For example, an add insn has two
1270input operands and one output operand in the RTL, but on most CISC
1271@end ifset
1272@ifclear INTERNALS
1273which @code{asm} distinguishes. For example, an add instruction uses
1274two input operands and an output operand, but on most CISC
1275@end ifclear
1276machines an add instruction really has only two operands, one of them an
1277input-output operand:
1278
1279@smallexample
1280addl #35,r12
1281@end smallexample
1282
1283Matching constraints are used in these circumstances.
1284More precisely, the two operands that match must include one input-only
1285operand and one output-only operand. Moreover, the digit must be a
1286smaller number than the number of the operand that uses it in the
1287constraint.
1288
1289@ifset INTERNALS
1290For operands to match in a particular case usually means that they
1291are identical-looking RTL expressions. But in a few special cases
1292specific kinds of dissimilarity are allowed. For example, @code{*x}
1293as an input operand will match @code{*x++} as an output operand.
1294For proper results in such cases, the output template should always
1295use the output-operand's number when printing the operand.
1296@end ifset
1297
1298@cindex load address instruction
1299@cindex push address instruction
1300@cindex address constraints
1301@cindex @samp{p} in constraint
1302@item @samp{p}
1303An operand that is a valid memory address is allowed. This is
1304for ``load address'' and ``push address'' instructions.
1305
1306@findex address_operand
1307@samp{p} in the constraint must be accompanied by @code{address_operand}
1308as the predicate in the @code{match_operand}. This predicate interprets
1309the mode specified in the @code{match_operand} as the mode of the memory
1310reference for which the address would be valid.
1311
c2cba7a9 1312@cindex other register constraints
03dda8e3 1313@cindex extensible constraints
630d3d5a 1314@item @var{other-letters}
c2cba7a9
RH
1315Other letters can be defined in machine-dependent fashion to stand for
1316particular classes of registers or other arbitrary operand types.
1317@samp{d}, @samp{a} and @samp{f} are defined on the 68000/68020 to stand
1318for data, address and floating point registers.
03dda8e3
RK
1319@end table
1320
1321@ifset INTERNALS
1322In order to have valid assembler code, each operand must satisfy
1323its constraint. But a failure to do so does not prevent the pattern
1324from applying to an insn. Instead, it directs the compiler to modify
1325the code so that the constraint will be satisfied. Usually this is
1326done by copying an operand into a register.
1327
1328Contrast, therefore, the two instruction patterns that follow:
1329
1330@smallexample
1331(define_insn ""
1332 [(set (match_operand:SI 0 "general_operand" "=r")
1333 (plus:SI (match_dup 0)
1334 (match_operand:SI 1 "general_operand" "r")))]
1335 ""
1336 "@dots{}")
1337@end smallexample
1338
1339@noindent
1340which has two operands, one of which must appear in two places, and
1341
1342@smallexample
1343(define_insn ""
1344 [(set (match_operand:SI 0 "general_operand" "=r")
1345 (plus:SI (match_operand:SI 1 "general_operand" "0")
1346 (match_operand:SI 2 "general_operand" "r")))]
1347 ""
1348 "@dots{}")
1349@end smallexample
1350
1351@noindent
1352which has three operands, two of which are required by a constraint to be
1353identical. If we are considering an insn of the form
1354
1355@smallexample
1356(insn @var{n} @var{prev} @var{next}
1357 (set (reg:SI 3)
1358 (plus:SI (reg:SI 6) (reg:SI 109)))
1359 @dots{})
1360@end smallexample
1361
1362@noindent
1363the first pattern would not apply at all, because this insn does not
1364contain two identical subexpressions in the right place. The pattern would
d78aa55c 1365say, ``That does not look like an add instruction; try other patterns''.
03dda8e3 1366The second pattern would say, ``Yes, that's an add instruction, but there
d78aa55c 1367is something wrong with it''. It would direct the reload pass of the
03dda8e3
RK
1368compiler to generate additional insns to make the constraint true. The
1369results might look like this:
1370
1371@smallexample
1372(insn @var{n2} @var{prev} @var{n}
1373 (set (reg:SI 3) (reg:SI 6))
1374 @dots{})
1375
1376(insn @var{n} @var{n2} @var{next}
1377 (set (reg:SI 3)
1378 (plus:SI (reg:SI 3) (reg:SI 109)))
1379 @dots{})
1380@end smallexample
1381
1382It is up to you to make sure that each operand, in each pattern, has
1383constraints that can handle any RTL expression that could be present for
1384that operand. (When multiple alternatives are in use, each pattern must,
1385for each possible combination of operand expressions, have at least one
1386alternative which can handle that combination of operands.) The
1387constraints don't need to @emph{allow} any possible operand---when this is
1388the case, they do not constrain---but they must at least point the way to
1389reloading any possible operand so that it will fit.
1390
1391@itemize @bullet
1392@item
1393If the constraint accepts whatever operands the predicate permits,
1394there is no problem: reloading is never necessary for this operand.
1395
1396For example, an operand whose constraints permit everything except
1397registers is safe provided its predicate rejects registers.
1398
1399An operand whose predicate accepts only constant values is safe
1400provided its constraints include the letter @samp{i}. If any possible
1401constant value is accepted, then nothing less than @samp{i} will do;
1402if the predicate is more selective, then the constraints may also be
1403more selective.
1404
1405@item
1406Any operand expression can be reloaded by copying it into a register.
1407So if an operand's constraints allow some kind of register, it is
1408certain to be safe. It need not permit all classes of registers; the
1409compiler knows how to copy a register into another register of the
1410proper class in order to make an instruction valid.
1411
1412@cindex nonoffsettable memory reference
1413@cindex memory reference, nonoffsettable
1414@item
1415A nonoffsettable memory reference can be reloaded by copying the
1416address into a register. So if the constraint uses the letter
1417@samp{o}, all memory references are taken care of.
1418
1419@item
1420A constant operand can be reloaded by allocating space in memory to
1421hold it as preinitialized data. Then the memory reference can be used
1422in place of the constant. So if the constraint uses the letters
1423@samp{o} or @samp{m}, constant operands are not a problem.
1424
1425@item
1426If the constraint permits a constant and a pseudo register used in an insn
1427was not allocated to a hard register and is equivalent to a constant,
1428the register will be replaced with the constant. If the predicate does
1429not permit a constant and the insn is re-recognized for some reason, the
1430compiler will crash. Thus the predicate must always recognize any
1431objects allowed by the constraint.
1432@end itemize
1433
1434If the operand's predicate can recognize registers, but the constraint does
1435not permit them, it can make the compiler crash. When this operand happens
1436to be a register, the reload pass will be stymied, because it does not know
1437how to copy a register temporarily into memory.
1438
1439If the predicate accepts a unary operator, the constraint applies to the
1440operand. For example, the MIPS processor at ISA level 3 supports an
1441instruction which adds two registers in @code{SImode} to produce a
1442@code{DImode} result, but only if the registers are correctly sign
1443extended. This predicate for the input operands accepts a
1444@code{sign_extend} of an @code{SImode} register. Write the constraint
1445to indicate the type of register that is required for the operand of the
1446@code{sign_extend}.
1447@end ifset
1448
1449@node Multi-Alternative
1450@subsection Multiple Alternative Constraints
1451@cindex multiple alternative constraints
1452
1453Sometimes a single instruction has multiple alternative sets of possible
1454operands. For example, on the 68000, a logical-or instruction can combine
1455register or an immediate value into memory, or it can combine any kind of
1456operand into a register; but it cannot combine one memory location into
1457another.
1458
1459These constraints are represented as multiple alternatives. An alternative
1460can be described by a series of letters for each operand. The overall
1461constraint for an operand is made from the letters for this operand
1462from the first alternative, a comma, the letters for this operand from
1463the second alternative, a comma, and so on until the last alternative.
1464@ifset INTERNALS
1465Here is how it is done for fullword logical-or on the 68000:
1466
1467@smallexample
1468(define_insn "iorsi3"
1469 [(set (match_operand:SI 0 "general_operand" "=m,d")
1470 (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
1471 (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
1472 @dots{})
1473@end smallexample
1474
1475The first alternative has @samp{m} (memory) for operand 0, @samp{0} for
1476operand 1 (meaning it must match operand 0), and @samp{dKs} for operand
14772. The second alternative has @samp{d} (data register) for operand 0,
1478@samp{0} for operand 1, and @samp{dmKs} for operand 2. The @samp{=} and
1479@samp{%} in the constraints apply to all the alternatives; their
1480meaning is explained in the next section (@pxref{Class Preferences}).
1481@end ifset
1482
1483@c FIXME Is this ? and ! stuff of use in asm()? If not, hide unless INTERNAL
1484If all the operands fit any one alternative, the instruction is valid.
1485Otherwise, for each alternative, the compiler counts how many instructions
1486must be added to copy the operands so that that alternative applies.
1487The alternative requiring the least copying is chosen. If two alternatives
1488need the same amount of copying, the one that comes first is chosen.
1489These choices can be altered with the @samp{?} and @samp{!} characters:
1490
1491@table @code
1492@cindex @samp{?} in constraint
1493@cindex question mark
1494@item ?
1495Disparage slightly the alternative that the @samp{?} appears in,
1496as a choice when no alternative applies exactly. The compiler regards
1497this alternative as one unit more costly for each @samp{?} that appears
1498in it.
1499
1500@cindex @samp{!} in constraint
1501@cindex exclamation point
1502@item !
1503Disparage severely the alternative that the @samp{!} appears in.
1504This alternative can still be used if it fits without reloading,
1505but if reloading is needed, some other alternative will be used.
1506@end table
1507
1508@ifset INTERNALS
1509When an insn pattern has multiple alternatives in its constraints, often
1510the appearance of the assembler code is determined mostly by which
1511alternative was matched. When this is so, the C code for writing the
1512assembler code can use the variable @code{which_alternative}, which is
1513the ordinal number of the alternative that was actually satisfied (0 for
1514the first, 1 for the second alternative, etc.). @xref{Output Statement}.
1515@end ifset
1516
1517@ifset INTERNALS
1518@node Class Preferences
1519@subsection Register Class Preferences
1520@cindex class preference constraints
1521@cindex register class preference constraints
1522
1523@cindex voting between constraint alternatives
1524The operand constraints have another function: they enable the compiler
1525to decide which kind of hardware register a pseudo register is best
1526allocated to. The compiler examines the constraints that apply to the
1527insns that use the pseudo register, looking for the machine-dependent
1528letters such as @samp{d} and @samp{a} that specify classes of registers.
1529The pseudo register is put in whichever class gets the most ``votes''.
1530The constraint letters @samp{g} and @samp{r} also vote: they vote in
1531favor of a general register. The machine description says which registers
1532are considered general.
1533
1534Of course, on some machines all registers are equivalent, and no register
1535classes are defined. Then none of this complexity is relevant.
1536@end ifset
1537
1538@node Modifiers
1539@subsection Constraint Modifier Characters
1540@cindex modifiers in constraints
1541@cindex constraint modifier characters
1542
1543@c prevent bad page break with this line
1544Here are constraint modifier characters.
1545
1546@table @samp
1547@cindex @samp{=} in constraint
1548@item =
1549Means that this operand is write-only for this instruction: the previous
1550value is discarded and replaced by output data.
1551
1552@cindex @samp{+} in constraint
1553@item +
1554Means that this operand is both read and written by the instruction.
1555
1556When the compiler fixes up the operands to satisfy the constraints,
1557it needs to know which operands are inputs to the instruction and
1558which are outputs from it. @samp{=} identifies an output; @samp{+}
1559identifies an operand that is both input and output; all other operands
1560are assumed to be input only.
1561
c5c76735
JL
1562If you specify @samp{=} or @samp{+} in a constraint, you put it in the
1563first character of the constraint string.
1564
03dda8e3
RK
1565@cindex @samp{&} in constraint
1566@cindex earlyclobber operand
1567@item &
1568Means (in a particular alternative) that this operand is an
1569@dfn{earlyclobber} operand, which is modified before the instruction is
1570finished using the input operands. Therefore, this operand may not lie
1571in a register that is used as an input operand or as part of any memory
1572address.
1573
1574@samp{&} applies only to the alternative in which it is written. In
1575constraints with multiple alternatives, sometimes one alternative
1576requires @samp{&} while others do not. See, for example, the
1577@samp{movdf} insn of the 68000.
1578
ebb48a4d 1579An input operand can be tied to an earlyclobber operand if its only
03dda8e3
RK
1580use as an input occurs before the early result is written. Adding
1581alternatives of this form often allows GCC to produce better code
ebb48a4d 1582when only some of the inputs can be affected by the earlyclobber.
161d7b59 1583See, for example, the @samp{mulsi3} insn of the ARM@.
03dda8e3
RK
1584
1585@samp{&} does not obviate the need to write @samp{=}.
1586
1587@cindex @samp{%} in constraint
1588@item %
1589Declares the instruction to be commutative for this operand and the
1590following operand. This means that the compiler may interchange the
1591two operands if that is the cheapest way to make all operands fit the
1592constraints.
1593@ifset INTERNALS
1594This is often used in patterns for addition instructions
1595that really have only two operands: the result must go in one of the
1596arguments. Here for example, is how the 68000 halfword-add
1597instruction is defined:
1598
1599@smallexample
1600(define_insn "addhi3"
1601 [(set (match_operand:HI 0 "general_operand" "=m,r")
1602 (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
1603 (match_operand:HI 2 "general_operand" "di,g")))]
1604 @dots{})
1605@end smallexample
1606@end ifset
daf2f129 1607GCC can only handle one commutative pair in an asm; if you use more,
595163db
EB
1608the compiler may fail. Note that you need not use the modifier if
1609the two alternatives are strictly identical; this would only waste
be3914df
HPN
1610time in the reload pass. The modifier is not operational after
1611register allocation, so the result of @code{define_peephole2}
1612and @code{define_split}s performed after reload cannot rely on
1613@samp{%} to make the intended insn match.
03dda8e3
RK
1614
1615@cindex @samp{#} in constraint
1616@item #
1617Says that all following characters, up to the next comma, are to be
1618ignored as a constraint. They are significant only for choosing
1619register preferences.
1620
03dda8e3
RK
1621@cindex @samp{*} in constraint
1622@item *
1623Says that the following character should be ignored when choosing
1624register preferences. @samp{*} has no effect on the meaning of the
55a2c322
VM
1625constraint as a constraint, and no effect on reloading. For LRA
1626@samp{*} additionally disparages slightly the alternative if the
1627following character matches the operand.
03dda8e3 1628
9f339dde 1629@ifset INTERNALS
03dda8e3
RK
1630Here is an example: the 68000 has an instruction to sign-extend a
1631halfword in a data register, and can also sign-extend a value by
1632copying it into an address register. While either kind of register is
1633acceptable, the constraints on an address-register destination are
1634less strict, so it is best if register allocation makes an address
1635register its goal. Therefore, @samp{*} is used so that the @samp{d}
1636constraint letter (for data register) is ignored when computing
1637register preferences.
1638
1639@smallexample
1640(define_insn "extendhisi2"
1641 [(set (match_operand:SI 0 "general_operand" "=*d,a")
1642 (sign_extend:SI
1643 (match_operand:HI 1 "general_operand" "0,g")))]
1644 @dots{})
1645@end smallexample
1646@end ifset
1647@end table
1648
1649@node Machine Constraints
1650@subsection Constraints for Particular Machines
1651@cindex machine specific constraints
1652@cindex constraints, machine specific
1653
1654Whenever possible, you should use the general-purpose constraint letters
1655in @code{asm} arguments, since they will convey meaning more readily to
1656people reading your code. Failing that, use the constraint letters
1657that usually have very similar meanings across architectures. The most
1658commonly used constraints are @samp{m} and @samp{r} (for memory and
1659general-purpose registers respectively; @pxref{Simple Constraints}), and
1660@samp{I}, usually the letter indicating the most common
1661immediate-constant format.
1662
f38840db
ZW
1663Each architecture defines additional constraints. These constraints
1664are used by the compiler itself for instruction generation, as well as
1665for @code{asm} statements; therefore, some of the constraints are not
1666particularly useful for @code{asm}. Here is a summary of some of the
1667machine-dependent constraints available on some particular machines;
1668it includes both constraints that are useful for @code{asm} and
1669constraints that aren't. The compiler source file mentioned in the
1670table heading for each architecture is the definitive reference for
1671the meanings of that architecture's constraints.
6ccde948 1672
03dda8e3 1673@table @emph
dae840fc 1674@item ARM family---@file{config/arm/constraints.md}
03dda8e3 1675@table @code
9b66ebb1
PB
1676@item w
1677VFP floating-point register
1678
03dda8e3 1679@item G
dae840fc 1680The floating-point constant 0.0
03dda8e3
RK
1681
1682@item I
1683Integer that is valid as an immediate operand in a data processing
1684instruction. That is, an integer in the range 0 to 255 rotated by a
1685multiple of 2
1686
1687@item J
630d3d5a 1688Integer in the range @minus{}4095 to 4095
03dda8e3
RK
1689
1690@item K
1691Integer that satisfies constraint @samp{I} when inverted (ones complement)
1692
1693@item L
1694Integer that satisfies constraint @samp{I} when negated (twos complement)
1695
1696@item M
1697Integer in the range 0 to 32
1698
1699@item Q
1700A memory reference where the exact address is in a single register
1701(`@samp{m}' is preferable for @code{asm} statements)
1702
1703@item R
1704An item in the constant pool
1705
1706@item S
1707A symbol in the text segment of the current file
03dda8e3 1708
1e1ab407 1709@item Uv
9b66ebb1
PB
1710A memory reference suitable for VFP load/store insns (reg+constant offset)
1711
fdd695fd
PB
1712@item Uy
1713A memory reference suitable for iWMMXt load/store instructions.
1714
1e1ab407 1715@item Uq
0bdcd332 1716A memory reference suitable for the ARMv4 ldrsb instruction.
db875b15 1717@end table
1e1ab407 1718
fc262682 1719@item AVR family---@file{config/avr/constraints.md}
052a4b28
DC
1720@table @code
1721@item l
1722Registers from r0 to r15
1723
1724@item a
1725Registers from r16 to r23
1726
1727@item d
1728Registers from r16 to r31
1729
1730@item w
3a69a7d5 1731Registers from r24 to r31. These registers can be used in @samp{adiw} command
052a4b28
DC
1732
1733@item e
d7d9c429 1734Pointer register (r26--r31)
052a4b28
DC
1735
1736@item b
d7d9c429 1737Base pointer register (r28--r31)
052a4b28 1738
3a69a7d5
MM
1739@item q
1740Stack pointer register (SPH:SPL)
1741
052a4b28
DC
1742@item t
1743Temporary register r0
1744
1745@item x
1746Register pair X (r27:r26)
1747
1748@item y
1749Register pair Y (r29:r28)
1750
1751@item z
1752Register pair Z (r31:r30)
1753
1754@item I
630d3d5a 1755Constant greater than @minus{}1, less than 64
052a4b28
DC
1756
1757@item J
630d3d5a 1758Constant greater than @minus{}64, less than 1
052a4b28
DC
1759
1760@item K
1761Constant integer 2
1762
1763@item L
1764Constant integer 0
1765
1766@item M
1767Constant that fits in 8 bits
1768
1769@item N
630d3d5a 1770Constant integer @minus{}1
052a4b28
DC
1771
1772@item O
3a69a7d5 1773Constant integer 8, 16, or 24
052a4b28
DC
1774
1775@item P
1776Constant integer 1
1777
1778@item G
1779A floating point constant 0.0
0e8eb4d8 1780
0e8eb4d8
EW
1781@item Q
1782A memory address based on Y or Z pointer with displacement.
052a4b28 1783@end table
53054e77 1784
feeeff5c
JR
1785@item Epiphany---@file{config/epiphany/constraints.md}
1786@table @code
1787@item U16
1788An unsigned 16-bit constant.
1789
1790@item K
1791An unsigned 5-bit constant.
1792
1793@item L
1794A signed 11-bit constant.
1795
1796@item Cm1
1797A signed 11-bit constant added to @minus{}1.
1798Can only match when the @option{-m1reg-@var{reg}} option is active.
1799
1800@item Cl1
1801Left-shift of @minus{}1, i.e., a bit mask with a block of leading ones, the rest
1802being a block of trailing zeroes.
1803Can only match when the @option{-m1reg-@var{reg}} option is active.
1804
1805@item Cr1
1806Right-shift of @minus{}1, i.e., a bit mask with a trailing block of ones, the
1807rest being zeroes. Or to put it another way, one less than a power of two.
1808Can only match when the @option{-m1reg-@var{reg}} option is active.
1809
1810@item Cal
1811Constant for arithmetic/logical operations.
1812This is like @code{i}, except that for position independent code,
1813no symbols / expressions needing relocations are allowed.
1814
1815@item Csy
1816Symbolic constant for call/jump instruction.
1817
1818@item Rcs
1819The register class usable in short insns. This is a register class
1820constraint, and can thus drive register allocation.
1821This constraint won't match unless @option{-mprefer-short-insn-regs} is
1822in effect.
1823
1824@item Rsc
1825The the register class of registers that can be used to hold a
1826sibcall call address. I.e., a caller-saved register.
1827
1828@item Rct
1829Core control register class.
1830
1831@item Rgs
1832The register group usable in short insns.
1833This constraint does not use a register class, so that it only
1834passively matches suitable registers, and doesn't drive register allocation.
1835
1836@ifset INTERNALS
1837@item Car
1838Constant suitable for the addsi3_r pattern. This is a valid offset
1839For byte, halfword, or word addressing.
1840@end ifset
1841
1842@item Rra
1843Matches the return address if it can be replaced with the link register.
1844
1845@item Rcc
1846Matches the integer condition code register.
1847
1848@item Sra
1849Matches the return address if it is in a stack slot.
1850
1851@item Cfm
1852Matches control register values to switch fp mode, which are encapsulated in
1853@code{UNSPEC_FP_MODE}.
1854@end table
1855
b25364a0
S
1856@item CR16 Architecture---@file{config/cr16/cr16.h}
1857@table @code
1858
1859@item b
1860Registers from r0 to r14 (registers without stack pointer)
1861
1862@item t
1863Register from r0 to r11 (all 16-bit registers)
1864
1865@item p
1866Register from r12 to r15 (all 32-bit registers)
1867
1868@item I
1869Signed constant that fits in 4 bits
1870
1871@item J
1872Signed constant that fits in 5 bits
1873
1874@item K
1875Signed constant that fits in 6 bits
1876
1877@item L
1878Unsigned constant that fits in 4 bits
1879
1880@item M
1881Signed constant that fits in 32 bits
1882
1883@item N
1884Check for 64 bits wide constants for add/sub instructions
1885
1886@item G
1887Floating point constant that is legal for store immediate
1888@end table
1889
8119b4e4
JDA
1890@item Hewlett-Packard PA-RISC---@file{config/pa/pa.h}
1891@table @code
1892@item a
1893General register 1
1894
1895@item f
1896Floating point register
1897
1898@item q
1899Shift amount register
1900
1901@item x
1902Floating point register (deprecated)
1903
1904@item y
1905Upper floating point register (32-bit), floating point register (64-bit)
1906
1907@item Z
1908Any register
1909
1910@item I
1911Signed 11-bit integer constant
1912
1913@item J
1914Signed 14-bit integer constant
1915
1916@item K
1917Integer constant that can be deposited with a @code{zdepi} instruction
1918
1919@item L
1920Signed 5-bit integer constant
1921
1922@item M
1923Integer constant 0
1924
1925@item N
1926Integer constant that can be loaded with a @code{ldil} instruction
1927
1928@item O
1929Integer constant whose value plus one is a power of 2
1930
1931@item P
1932Integer constant that can be used for @code{and} operations in @code{depi}
1933and @code{extru} instructions
1934
1935@item S
1936Integer constant 31
1937
1938@item U
1939Integer constant 63
1940
1941@item G
1942Floating-point constant 0.0
1943
1944@item A
1945A @code{lo_sum} data-linkage-table memory operand
1946
1947@item Q
1948A memory operand that can be used as the destination operand of an
1949integer store instruction
1950
1951@item R
1952A scaled or unscaled indexed memory operand
1953
1954@item T
1955A memory operand for floating-point loads and stores
1956
1957@item W
1958A register indirect memory operand
1959@end table
1960
358da97e
HS
1961@item picoChip family---@file{picochip.h}
1962@table @code
1963@item k
1964Stack register.
1965
1966@item f
1967Pointer register. A register which can be used to access memory without
1968supplying an offset. Any other register can be used to access memory,
1969but will need a constant offset. In the case of the offset being zero,
1970it is more efficient to use a pointer register, since this reduces code
1971size.
1972
1973@item t
1974A twin register. A register which may be paired with an adjacent
1975register to create a 32-bit register.
1976
1977@item a
1978Any absolute memory address (e.g., symbolic constant, symbolic
1979constant + offset).
1980
1981@item I
19824-bit signed integer.
1983
1984@item J
19854-bit unsigned integer.
1986
1987@item K
19888-bit signed integer.
1989
1990@item M
1991Any constant whose absolute value is no greater than 4-bits.
1992
1993@item N
199410-bit signed integer
1995
1996@item O
199716-bit signed integer.
1998
1999@end table
2000
74fe790b 2001@item PowerPC and IBM RS6000---@file{config/rs6000/rs6000.h}
03dda8e3
RK
2002@table @code
2003@item b
2004Address base register
2005
799dbb0f
ME
2006@item d
2007Floating point register (containing 64-bit value)
2008
03dda8e3 2009@item f
799dbb0f 2010Floating point register (containing 32-bit value)
03dda8e3 2011
2dcfc29d 2012@item v
29e6733c
MM
2013Altivec vector register
2014
2015@item wd
2016VSX vector register to hold vector double data
2017
2018@item wf
2019VSX vector register to hold vector float data
2020
2021@item ws
2022VSX vector register to hold scalar float data
2023
2024@item wa
2025Any VSX register
2dcfc29d 2026
03dda8e3
RK
2027@item h
2028@samp{MQ}, @samp{CTR}, or @samp{LINK} register
2029
2030@item q
2031@samp{MQ} register
2032
2033@item c
2034@samp{CTR} register
2035
2036@item l
2037@samp{LINK} register
2038
2039@item x
2040@samp{CR} register (condition register) number 0
2041
2042@item y
2043@samp{CR} register (condition register)
2044
8f685459 2045@item z
f6b5d695 2046@samp{XER[CA]} carry bit (part of the XER register)
8f685459 2047
03dda8e3 2048@item I
1e5f973d 2049Signed 16-bit constant
03dda8e3
RK
2050
2051@item J
ebb48a4d 2052Unsigned 16-bit constant shifted left 16 bits (use @samp{L} instead for
5f59ecb7 2053@code{SImode} constants)
03dda8e3
RK
2054
2055@item K
1e5f973d 2056Unsigned 16-bit constant
03dda8e3
RK
2057
2058@item L
1e5f973d 2059Signed 16-bit constant shifted left 16 bits
03dda8e3
RK
2060
2061@item M
2062Constant larger than 31
2063
2064@item N
2065Exact power of 2
2066
2067@item O
2068Zero
2069
2070@item P
1e5f973d 2071Constant whose negation is a signed 16-bit constant
03dda8e3
RK
2072
2073@item G
2074Floating point constant that can be loaded into a register with one
2075instruction per word
2076
a8a51a97
AP
2077@item H
2078Integer/Floating point constant that can be loaded into a register using
2079three instructions
2080
1d447995 2081@item m
ff2ce160 2082Memory operand.
fea31288
JJ
2083Normally, @code{m} does not allow addresses that update the base register.
2084If @samp{<} or @samp{>} constraint is also used, they are allowed and
2085therefore on PowerPC targets in that case it is only safe
2086to use @samp{m<>} in an @code{asm} statement if that @code{asm} statement
1d447995
RS
2087accesses the operand exactly once. The @code{asm} statement must also
2088use @samp{%U@var{<opno>}} as a placeholder for the ``update'' flag in the
2089corresponding load or store instruction. For example:
2090
2091@smallexample
fea31288 2092asm ("st%U0 %1,%0" : "=m<>" (mem) : "r" (val));
1d447995
RS
2093@end smallexample
2094
2095is correct but:
2096
2097@smallexample
fea31288 2098asm ("st %1,%0" : "=m<>" (mem) : "r" (val));
1d447995
RS
2099@end smallexample
2100
fea31288 2101is not.
1d447995
RS
2102
2103@item es
2104A ``stable'' memory operand; that is, one which does not include any
fea31288
JJ
2105automodification of the base register. This used to be useful when
2106@samp{m} allowed automodification of the base register, but as those are now only
2107allowed when @samp{<} or @samp{>} is used, @samp{es} is basically the same
2108as @samp{m} without @samp{<} and @samp{>}.
1d447995 2109
03dda8e3 2110@item Q
1d447995
RS
2111Memory operand that is an offset from a register (it is usually better
2112to use @samp{m} or @samp{es} in @code{asm} statements)
03dda8e3 2113
a8a51a97 2114@item Z
1d447995
RS
2115Memory operand that is an indexed or indirect from a register (it is
2116usually better to use @samp{m} or @samp{es} in @code{asm} statements)
a8a51a97 2117
03dda8e3
RK
2118@item R
2119AIX TOC entry
2120
a8a51a97
AP
2121@item a
2122Address operand that is an indexed or indirect from a register (@samp{p} is
2123preferable for @code{asm} statements)
2124
03dda8e3 2125@item S
8f685459 2126Constant suitable as a 64-bit mask operand
03dda8e3 2127
5f59ecb7
DE
2128@item T
2129Constant suitable as a 32-bit mask operand
2130
03dda8e3
RK
2131@item U
2132System V Release 4 small data area reference
a8a51a97
AP
2133
2134@item t
2135AND masks that can be performed by two rldic@{l, r@} instructions
2136
2137@item W
2138Vector constant that does not require memory
2139
29e6733c
MM
2140@item j
2141Vector constant that is all zeros.
2142
03dda8e3
RK
2143@end table
2144
08b1e29a 2145@item Intel 386---@file{config/i386/constraints.md}
03dda8e3 2146@table @code
0c56474e 2147@item R
f38840db
ZW
2148Legacy register---the eight integer registers available on all
2149i386 processors (@code{a}, @code{b}, @code{c}, @code{d},
2150@code{si}, @code{di}, @code{bp}, @code{sp}).
03dda8e3 2151
f38840db
ZW
2152@item q
2153Any register accessible as @code{@var{r}l}. In 32-bit mode, @code{a},
2154@code{b}, @code{c}, and @code{d}; in 64-bit mode, any integer register.
03dda8e3 2155
f38840db
ZW
2156@item Q
2157Any register accessible as @code{@var{r}h}: @code{a}, @code{b},
2158@code{c}, and @code{d}.
03dda8e3 2159
f38840db
ZW
2160@ifset INTERNALS
2161@item l
2162Any register that can be used as the index in a base+index memory
2163access: that is, any general register except the stack pointer.
2164@end ifset
03dda8e3
RK
2165
2166@item a
f38840db 2167The @code{a} register.
03dda8e3
RK
2168
2169@item b
f38840db 2170The @code{b} register.
03dda8e3
RK
2171
2172@item c
f38840db 2173The @code{c} register.
f8ca7923 2174
03dda8e3 2175@item d
f38840db
ZW
2176The @code{d} register.
2177
2178@item S
2179The @code{si} register.
03dda8e3
RK
2180
2181@item D
f38840db 2182The @code{di} register.
03dda8e3 2183
f38840db 2184@item A
ae8358d6
RG
2185The @code{a} and @code{d} registers. This class is used for instructions
2186that return double word results in the @code{ax:dx} register pair. Single
2187word values will be allocated either in @code{ax} or @code{dx}.
2188For example on i386 the following implements @code{rdtsc}:
2189
2190@smallexample
2191unsigned long long rdtsc (void)
2192@{
2193 unsigned long long tick;
2194 __asm__ __volatile__("rdtsc":"=A"(tick));
2195 return tick;
2196@}
2197@end smallexample
2198
2199This is not correct on x86_64 as it would allocate tick in either @code{ax}
2200or @code{dx}. You have to use the following variant instead:
2201
2202@smallexample
2203unsigned long long rdtsc (void)
2204@{
2205 unsigned int tickl, tickh;
2206 __asm__ __volatile__("rdtsc":"=a"(tickl),"=d"(tickh));
2207 return ((unsigned long long)tickh << 32)|tickl;
2208@}
2209@end smallexample
2210
03dda8e3 2211
f38840db
ZW
2212@item f
2213Any 80387 floating-point (stack) register.
2214
2215@item t
2216Top of 80387 floating-point stack (@code{%st(0)}).
2217
2218@item u
2219Second from top of 80387 floating-point stack (@code{%st(1)}).
994682b9
AJ
2220
2221@item y
f38840db
ZW
2222Any MMX register.
2223
2224@item x
2225Any SSE register.
2226
c5245af5
L
2227@item Yz
2228First SSE register (@code{%xmm0}).
2229
f38840db 2230@ifset INTERNALS
c5245af5
L
2231@item Y2
2232Any SSE register, when SSE2 is enabled.
2233
2234@item Yi
2235Any SSE register, when SSE2 and inter-unit moves are enabled.
2236
2237@item Ym
2238Any MMX register, when inter-unit moves are enabled.
f38840db 2239@end ifset
994682b9 2240
03dda8e3 2241@item I
f38840db 2242Integer constant in the range 0 @dots{} 31, for 32-bit shifts.
03dda8e3
RK
2243
2244@item J
f38840db 2245Integer constant in the range 0 @dots{} 63, for 64-bit shifts.
03dda8e3
RK
2246
2247@item K
f38840db 2248Signed 8-bit integer constant.
03dda8e3
RK
2249
2250@item L
f38840db 2251@code{0xFF} or @code{0xFFFF}, for andsi as a zero-extending move.
03dda8e3
RK
2252
2253@item M
f38840db 22540, 1, 2, or 3 (shifts for the @code{lea} instruction).
03dda8e3
RK
2255
2256@item N
ff2ce160 2257Unsigned 8-bit integer constant (for @code{in} and @code{out}
f38840db 2258instructions).
03dda8e3 2259
f38840db
ZW
2260@ifset INTERNALS
2261@item O
2262Integer constant in the range 0 @dots{} 127, for 128-bit shifts.
2263@end ifset
2264
2265@item G
2266Standard 80387 floating point constant.
2267
2268@item C
2269Standard SSE floating point constant.
0c56474e
JH
2270
2271@item e
f38840db
ZW
227232-bit signed integer constant, or a symbolic reference known
2273to fit that range (for immediate operands in sign-extending x86-64
2274instructions).
2275
2276@item Z
227732-bit unsigned integer constant, or a symbolic reference known
2278to fit that range (for immediate operands in zero-extending x86-64
2279instructions).
0c56474e 2280
03dda8e3
RK
2281@end table
2282
74fe790b 2283@item Intel IA-64---@file{config/ia64/ia64.h}
7a430e3b
SC
2284@table @code
2285@item a
2286General register @code{r0} to @code{r3} for @code{addl} instruction
2287
2288@item b
2289Branch register
2290
2291@item c
2292Predicate register (@samp{c} as in ``conditional'')
2293
2294@item d
2295Application register residing in M-unit
2296
2297@item e
2298Application register residing in I-unit
2299
2300@item f
2301Floating-point register
2302
2303@item m
fea31288
JJ
2304Memory operand. If used together with @samp{<} or @samp{>},
2305the operand can have postincrement and postdecrement which
7a430e3b 2306require printing with @samp{%Pn} on IA-64.
7a430e3b
SC
2307
2308@item G
2309Floating-point constant 0.0 or 1.0
2310
2311@item I
231214-bit signed integer constant
2313
2314@item J
231522-bit signed integer constant
2316
2317@item K
23188-bit signed integer constant for logical instructions
2319
2320@item L
23218-bit adjusted signed integer constant for compare pseudo-ops
2322
2323@item M
23246-bit unsigned integer constant for shift counts
2325
2326@item N
23279-bit signed integer constant for load and store postincrements
2328
2329@item O
2330The constant zero
2331
2332@item P
78466c0e 23330 or @minus{}1 for @code{dep} instruction
7a430e3b
SC
2334
2335@item Q
2336Non-volatile memory for floating-point loads and stores
2337
2338@item R
2339Integer constant in the range 1 to 4 for @code{shladd} instruction
2340
2341@item S
fea31288
JJ
2342Memory operand except postincrement and postdecrement. This is
2343now roughly the same as @samp{m} when not used together with @samp{<}
2344or @samp{>}.
7a430e3b 2345@end table
03dda8e3 2346
74fe790b 2347@item FRV---@file{config/frv/frv.h}
70899148
BS
2348@table @code
2349@item a
840758d3 2350Register in the class @code{ACC_REGS} (@code{acc0} to @code{acc7}).
70899148
BS
2351
2352@item b
840758d3 2353Register in the class @code{EVEN_ACC_REGS} (@code{acc0} to @code{acc7}).
70899148
BS
2354
2355@item c
840758d3
BS
2356Register in the class @code{CC_REGS} (@code{fcc0} to @code{fcc3} and
2357@code{icc0} to @code{icc3}).
70899148
BS
2358
2359@item d
840758d3 2360Register in the class @code{GPR_REGS} (@code{gr0} to @code{gr63}).
70899148
BS
2361
2362@item e
840758d3 2363Register in the class @code{EVEN_REGS} (@code{gr0} to @code{gr63}).
70899148
BS
2364Odd registers are excluded not in the class but through the use of a machine
2365mode larger than 4 bytes.
2366
2367@item f
840758d3 2368Register in the class @code{FPR_REGS} (@code{fr0} to @code{fr63}).
70899148
BS
2369
2370@item h
840758d3 2371Register in the class @code{FEVEN_REGS} (@code{fr0} to @code{fr63}).
70899148
BS
2372Odd registers are excluded not in the class but through the use of a machine
2373mode larger than 4 bytes.
2374
2375@item l
840758d3 2376Register in the class @code{LR_REG} (the @code{lr} register).
70899148
BS
2377
2378@item q
840758d3 2379Register in the class @code{QUAD_REGS} (@code{gr2} to @code{gr63}).
70899148
BS
2380Register numbers not divisible by 4 are excluded not in the class but through
2381the use of a machine mode larger than 8 bytes.
2382
2383@item t
840758d3 2384Register in the class @code{ICC_REGS} (@code{icc0} to @code{icc3}).
70899148
BS
2385
2386@item u
840758d3 2387Register in the class @code{FCC_REGS} (@code{fcc0} to @code{fcc3}).
70899148
BS
2388
2389@item v
840758d3 2390Register in the class @code{ICR_REGS} (@code{cc4} to @code{cc7}).
70899148
BS
2391
2392@item w
840758d3 2393Register in the class @code{FCR_REGS} (@code{cc0} to @code{cc3}).
70899148
BS
2394
2395@item x
840758d3 2396Register in the class @code{QUAD_FPR_REGS} (@code{fr0} to @code{fr63}).
70899148
BS
2397Register numbers not divisible by 4 are excluded not in the class but through
2398the use of a machine mode larger than 8 bytes.
2399
2400@item z
840758d3 2401Register in the class @code{SPR_REGS} (@code{lcr} and @code{lr}).
70899148
BS
2402
2403@item A
840758d3 2404Register in the class @code{QUAD_ACC_REGS} (@code{acc0} to @code{acc7}).
70899148
BS
2405
2406@item B
840758d3 2407Register in the class @code{ACCG_REGS} (@code{accg0} to @code{accg7}).
70899148
BS
2408
2409@item C
840758d3 2410Register in the class @code{CR_REGS} (@code{cc0} to @code{cc7}).
70899148
BS
2411
2412@item G
2413Floating point constant zero
2414
2415@item I
24166-bit signed integer constant
2417
2418@item J
241910-bit signed integer constant
2420
2421@item L
242216-bit signed integer constant
2423
2424@item M
242516-bit unsigned integer constant
2426
2427@item N
840758d3
BS
242812-bit signed integer constant that is negative---i.e.@: in the
2429range of @minus{}2048 to @minus{}1
70899148
BS
2430
2431@item O
2432Constant zero
2433
2434@item P
840758d3 243512-bit signed integer constant that is greater than zero---i.e.@: in the
70899148
BS
2436range of 1 to 2047.
2437
2438@end table
2439
9fdd7520 2440@item Blackfin family---@file{config/bfin/constraints.md}
0d4a78eb
BS
2441@table @code
2442@item a
2443P register
2444
2445@item d
2446D register
2447
2448@item z
2449A call clobbered P register.
2450
03848bd0
BS
2451@item q@var{n}
2452A single register. If @var{n} is in the range 0 to 7, the corresponding D
2453register. If it is @code{A}, then the register P0.
2454
0d4a78eb
BS
2455@item D
2456Even-numbered D register
2457
2458@item W
2459Odd-numbered D register
2460
2461@item e
2462Accumulator register.
2463
2464@item A
2465Even-numbered accumulator register.
2466
2467@item B
2468Odd-numbered accumulator register.
2469
2470@item b
2471I register
2472
a9c46998 2473@item v
0d4a78eb
BS
2474B register
2475
2476@item f
2477M register
2478
2479@item c
2480Registers used for circular buffering, i.e. I, B, or L registers.
2481
2482@item C
2483The CC register.
2484
a9c46998
JZ
2485@item t
2486LT0 or LT1.
2487
2488@item k
2489LC0 or LC1.
2490
2491@item u
2492LB0 or LB1.
2493
0d4a78eb
BS
2494@item x
2495Any D, P, B, M, I or L register.
2496
2497@item y
2498Additional registers typically used only in prologues and epilogues: RETS,
2499RETN, RETI, RETX, RETE, ASTAT, SEQSTAT and USP.
2500
2501@item w
2502Any register except accumulators or CC.
2503
2504@item Ksh
8ad1dde7 2505Signed 16 bit integer (in the range @minus{}32768 to 32767)
0d4a78eb
BS
2506
2507@item Kuh
2508Unsigned 16 bit integer (in the range 0 to 65535)
2509
2510@item Ks7
8ad1dde7 2511Signed 7 bit integer (in the range @minus{}64 to 63)
0d4a78eb
BS
2512
2513@item Ku7
2514Unsigned 7 bit integer (in the range 0 to 127)
2515
2516@item Ku5
2517Unsigned 5 bit integer (in the range 0 to 31)
2518
2519@item Ks4
8ad1dde7 2520Signed 4 bit integer (in the range @minus{}8 to 7)
0d4a78eb
BS
2521
2522@item Ks3
8ad1dde7 2523Signed 3 bit integer (in the range @minus{}3 to 4)
0d4a78eb
BS
2524
2525@item Ku3
2526Unsigned 3 bit integer (in the range 0 to 7)
2527
2528@item P@var{n}
2529Constant @var{n}, where @var{n} is a single-digit constant in the range 0 to 4.
2530
3efd5670
BS
2531@item PA
2532An integer equal to one of the MACFLAG_XXX constants that is suitable for
2533use with either accumulator.
2534
2535@item PB
2536An integer equal to one of the MACFLAG_XXX constants that is suitable for
2537use only with accumulator A1.
2538
0d4a78eb
BS
2539@item M1
2540Constant 255.
2541
2542@item M2
2543Constant 65535.
2544
2545@item J
2546An integer constant with exactly a single bit set.
2547
2548@item L
2549An integer constant with all bits set except exactly one.
2550
2551@item H
2552
2553@item Q
2554Any SYMBOL_REF.
2555@end table
2556
74fe790b
ZW
2557@item M32C---@file{config/m32c/m32c.c}
2558@table @code
38b2d076
DD
2559@item Rsp
2560@itemx Rfb
2561@itemx Rsb
2562@samp{$sp}, @samp{$fb}, @samp{$sb}.
2563
2564@item Rcr
2565Any control register, when they're 16 bits wide (nothing if control
2566registers are 24 bits wide)
2567
2568@item Rcl
2569Any control register, when they're 24 bits wide.
2570
2571@item R0w
2572@itemx R1w
2573@itemx R2w
2574@itemx R3w
2575$r0, $r1, $r2, $r3.
2576
2577@item R02
2578$r0 or $r2, or $r2r0 for 32 bit values.
2579
2580@item R13
2581$r1 or $r3, or $r3r1 for 32 bit values.
2582
2583@item Rdi
2584A register that can hold a 64 bit value.
2585
2586@item Rhl
2587$r0 or $r1 (registers with addressable high/low bytes)
2588
2589@item R23
2590$r2 or $r3
2591
2592@item Raa
2593Address registers
2594
2595@item Raw
2596Address registers when they're 16 bits wide.
2597
2598@item Ral
2599Address registers when they're 24 bits wide.
2600
2601@item Rqi
2602Registers that can hold QI values.
2603
2604@item Rad
2605Registers that can be used with displacements ($a0, $a1, $sb).
2606
2607@item Rsi
2608Registers that can hold 32 bit values.
2609
2610@item Rhi
2611Registers that can hold 16 bit values.
2612
2613@item Rhc
2614Registers chat can hold 16 bit values, including all control
2615registers.
2616
2617@item Rra
2618$r0 through R1, plus $a0 and $a1.
2619
2620@item Rfl
2621The flags register.
2622
2623@item Rmm
2624The memory-based pseudo-registers $mem0 through $mem15.
2625
2626@item Rpi
2627Registers that can hold pointers (16 bit registers for r8c, m16c; 24
2628bit registers for m32cm, m32c).
2629
2630@item Rpa
2631Matches multiple registers in a PARALLEL to form a larger register.
2632Used to match function return values.
2633
2634@item Is3
8ad1dde7 2635@minus{}8 @dots{} 7
38b2d076
DD
2636
2637@item IS1
8ad1dde7 2638@minus{}128 @dots{} 127
38b2d076
DD
2639
2640@item IS2
8ad1dde7 2641@minus{}32768 @dots{} 32767
38b2d076
DD
2642
2643@item IU2
26440 @dots{} 65535
2645
2646@item In4
8ad1dde7 2647@minus{}8 @dots{} @minus{}1 or 1 @dots{} 8
38b2d076
DD
2648
2649@item In5
8ad1dde7 2650@minus{}16 @dots{} @minus{}1 or 1 @dots{} 16
38b2d076 2651
23fed240 2652@item In6
8ad1dde7 2653@minus{}32 @dots{} @minus{}1 or 1 @dots{} 32
38b2d076
DD
2654
2655@item IM2
8ad1dde7 2656@minus{}65536 @dots{} @minus{}1
38b2d076
DD
2657
2658@item Ilb
2659An 8 bit value with exactly one bit set.
2660
2661@item Ilw
2662A 16 bit value with exactly one bit set.
2663
2664@item Sd
2665The common src/dest memory addressing modes.
2666
2667@item Sa
2668Memory addressed using $a0 or $a1.
2669
2670@item Si
2671Memory addressed with immediate addresses.
2672
2673@item Ss
2674Memory addressed using the stack pointer ($sp).
2675
2676@item Sf
2677Memory addressed using the frame base register ($fb).
2678
2679@item Ss
2680Memory addressed using the small base register ($sb).
2681
2682@item S1
2683$r1h
e2491744
DD
2684@end table
2685
2686@item MeP---@file{config/mep/constraints.md}
2687@table @code
2688
2689@item a
2690The $sp register.
2691
2692@item b
2693The $tp register.
2694
2695@item c
2696Any control register.
2697
2698@item d
2699Either the $hi or the $lo register.
2700
2701@item em
2702Coprocessor registers that can be directly loaded ($c0-$c15).
2703
2704@item ex
2705Coprocessor registers that can be moved to each other.
2706
2707@item er
2708Coprocessor registers that can be moved to core registers.
2709
2710@item h
2711The $hi register.
2712
2713@item j
2714The $rpc register.
2715
2716@item l
2717The $lo register.
2718
2719@item t
2720Registers which can be used in $tp-relative addressing.
2721
2722@item v
2723The $gp register.
2724
2725@item x
2726The coprocessor registers.
2727
2728@item y
2729The coprocessor control registers.
2730
2731@item z
2732The $0 register.
2733
2734@item A
2735User-defined register set A.
2736
2737@item B
2738User-defined register set B.
2739
2740@item C
2741User-defined register set C.
2742
2743@item D
2744User-defined register set D.
2745
2746@item I
2747Offsets for $gp-rel addressing.
2748
2749@item J
2750Constants that can be used directly with boolean insns.
2751
2752@item K
2753Constants that can be moved directly to registers.
2754
2755@item L
2756Small constants that can be added to registers.
2757
2758@item M
2759Long shift counts.
2760
2761@item N
2762Small constants that can be compared to registers.
2763
2764@item O
2765Constants that can be loaded into the top half of registers.
2766
2767@item S
2768Signed 8-bit immediates.
2769
2770@item T
2771Symbols encoded for $tp-rel or $gp-rel addressing.
2772
2773@item U
2774Non-constant addresses for loading/saving coprocessor registers.
2775
2776@item W
2777The top half of a symbol's value.
2778
2779@item Y
2780A register indirect address without offset.
2781
2782@item Z
2783Symbolic references to the control bus.
2784
80920132 2785@end table
e2491744 2786
80920132
ME
2787@item MicroBlaze---@file{config/microblaze/constraints.md}
2788@table @code
2789@item d
2790A general register (@code{r0} to @code{r31}).
2791
2792@item z
2793A status register (@code{rmsr}, @code{$fcc1} to @code{$fcc7}).
e2491744 2794
74fe790b 2795@end table
38b2d076 2796
cbbb5b6d 2797@item MIPS---@file{config/mips/constraints.md}
4226378a
PK
2798@table @code
2799@item d
cbbb5b6d
RS
2800An address register. This is equivalent to @code{r} unless
2801generating MIPS16 code.
4226378a
PK
2802
2803@item f
cbbb5b6d 2804A floating-point register (if available).
4226378a
PK
2805
2806@item h
21dfc6dc 2807Formerly the @code{hi} register. This constraint is no longer supported.
4226378a
PK
2808
2809@item l
21dfc6dc
RS
2810The @code{lo} register. Use this register to store values that are
2811no bigger than a word.
4226378a
PK
2812
2813@item x
21dfc6dc
RS
2814The concatenated @code{hi} and @code{lo} registers. Use this register
2815to store doubleword values.
cbbb5b6d
RS
2816
2817@item c
2818A register suitable for use in an indirect jump. This will always be
2819@code{$25} for @option{-mabicalls}.
4226378a 2820
2feaae20
RS
2821@item v
2822Register @code{$3}. Do not use this constraint in new code;
2823it is retained only for compatibility with glibc.
2824
4226378a 2825@item y
cbbb5b6d 2826Equivalent to @code{r}; retained for backwards compatibility.
4226378a
PK
2827
2828@item z
cbbb5b6d 2829A floating-point condition code register.
4226378a
PK
2830
2831@item I
cbbb5b6d 2832A signed 16-bit constant (for arithmetic instructions).
4226378a
PK
2833
2834@item J
cbbb5b6d 2835Integer zero.
4226378a
PK
2836
2837@item K
cbbb5b6d 2838An unsigned 16-bit constant (for logic instructions).
4226378a
PK
2839
2840@item L
cbbb5b6d
RS
2841A signed 32-bit constant in which the lower 16 bits are zero.
2842Such constants can be loaded using @code{lui}.
4226378a
PK
2843
2844@item M
cbbb5b6d
RS
2845A constant that cannot be loaded using @code{lui}, @code{addiu}
2846or @code{ori}.
4226378a
PK
2847
2848@item N
8ad1dde7 2849A constant in the range @minus{}65535 to @minus{}1 (inclusive).
4226378a
PK
2850
2851@item O
cbbb5b6d 2852A signed 15-bit constant.
4226378a
PK
2853
2854@item P
cbbb5b6d 2855A constant in the range 1 to 65535 (inclusive).
4226378a
PK
2856
2857@item G
cbbb5b6d 2858Floating-point zero.
4226378a
PK
2859
2860@item R
cbbb5b6d 2861An address that can be used in a non-macro load or store.
4226378a
PK
2862@end table
2863
c47b0cb4 2864@item Motorola 680x0---@file{config/m68k/constraints.md}
03dda8e3
RK
2865@table @code
2866@item a
2867Address register
2868
2869@item d
2870Data register
2871
2872@item f
287368881 floating-point register, if available
2874
03dda8e3
RK
2875@item I
2876Integer in the range 1 to 8
2877
2878@item J
1e5f973d 287916-bit signed number
03dda8e3
RK
2880
2881@item K
2882Signed number whose magnitude is greater than 0x80
2883
2884@item L
630d3d5a 2885Integer in the range @minus{}8 to @minus{}1
03dda8e3
RK
2886
2887@item M
2888Signed number whose magnitude is greater than 0x100
2889
c47b0cb4
MK
2890@item N
2891Range 24 to 31, rotatert:SI 8 to 1 expressed as rotate
2892
2893@item O
289416 (for rotate using swap)
2895
2896@item P
2897Range 8 to 15, rotatert:HI 8 to 1 expressed as rotate
2898
2899@item R
2900Numbers that mov3q can handle
2901
03dda8e3
RK
2902@item G
2903Floating point constant that is not a 68881 constant
c47b0cb4
MK
2904
2905@item S
2906Operands that satisfy 'm' when -mpcrel is in effect
2907
2908@item T
2909Operands that satisfy 's' when -mpcrel is not in effect
2910
2911@item Q
2912Address register indirect addressing mode
2913
2914@item U
2915Register offset addressing
2916
2917@item W
2918const_call_operand
2919
2920@item Cs
2921symbol_ref or const
2922
2923@item Ci
2924const_int
2925
2926@item C0
2927const_int 0
2928
2929@item Cj
2930Range of signed numbers that don't fit in 16 bits
2931
2932@item Cmvq
2933Integers valid for mvq
2934
2935@item Capsw
2936Integers valid for a moveq followed by a swap
2937
2938@item Cmvz
2939Integers valid for mvz
2940
2941@item Cmvs
2942Integers valid for mvs
2943
2944@item Ap
2945push_operand
2946
2947@item Ac
2948Non-register operands allowed in clr
2949
03dda8e3
RK
2950@end table
2951
cceb575c
AG
2952@item Moxie---@file{config/moxie/constraints.md}
2953@table @code
2954@item A
2955An absolute address
2956
2957@item B
2958An offset address
2959
2960@item W
2961A register indirect memory operand
2962
2963@item I
2964A constant in the range of 0 to 255.
2965
2966@item N
8ad1dde7 2967A constant in the range of 0 to @minus{}255.
cceb575c
AG
2968
2969@end table
2970
5e426dd4
PK
2971@item PDP-11---@file{config/pdp11/constraints.md}
2972@table @code
2973@item a
2974Floating point registers AC0 through AC3. These can be loaded from/to
2975memory with a single instruction.
2976
2977@item d
868e54d1
PK
2978Odd numbered general registers (R1, R3, R5). These are used for
297916-bit multiply operations.
5e426dd4
PK
2980
2981@item f
2982Any of the floating point registers (AC0 through AC5).
2983
2984@item G
2985Floating point constant 0.
2986
2987@item I
2988An integer constant that fits in 16 bits.
2989
2990@item J
2991An integer constant whose low order 16 bits are zero.
2992
2993@item K
2994An integer constant that does not meet the constraints for codes
2995@samp{I} or @samp{J}.
2996
2997@item L
2998The integer constant 1.
2999
3000@item M
868e54d1 3001The integer constant @minus{}1.
5e426dd4
PK
3002
3003@item N
3004The integer constant 0.
3005
3006@item O
868e54d1 3007Integer constants @minus{}4 through @minus{}1 and 1 through 4; shifts by these
5e426dd4
PK
3008amounts are handled as multiple single-bit shifts rather than a single
3009variable-length shift.
3010
3011@item Q
3012A memory reference which requires an additional word (address or
3013offset) after the opcode.
3014
3015@item R
3016A memory reference that is encoded within the opcode.
3017
3018@end table
3019
85b8555e
DD
3020@item RL78---@file{config/rl78/constraints.md}
3021@table @code
3022
3023@item Int3
3024An integer constant in the range 1 @dots{} 7.
3025@item Int8
3026An integer constant in the range 0 @dots{} 255.
3027@item J
3028An integer constant in the range @minus{}255 @dots{} 0
3029@item K
3030The integer constant 1.
3031@item L
3032The integer constant -1.
3033@item M
3034The integer constant 0.
3035@item N
3036The integer constant 2.
3037@item O
3038The integer constant -2.
3039@item P
3040An integer constant in the range 1 @dots{} 15.
3041@item Qbi
3042The built-in compare types--eq, ne, gtu, ltu, geu, and leu.
3043@item Qsc
3044The synthetic compare types--gt, lt, ge, and le.
3045@item Wab
3046A memory reference with an absolute address.
3047@item Wbc
3048A memory reference using @code{BC} as a base register, with an optional offset.
3049@item Wca
3050A memory reference using @code{AX}, @code{BC}, @code{DE}, or @code{HL} for the address, for calls.
3051@item Wcv
3052A memory reference using any 16-bit register pair for the address, for calls.
3053@item Wd2
3054A memory reference using @code{DE} as a base register, with an optional offset.
3055@item Wde
3056A memory reference using @code{DE} as a base register, without any offset.
3057@item Wfr
3058Any memory reference to an address in the far address space.
3059@item Wh1
3060A memory reference using @code{HL} as a base register, with an optional one-byte offset.
3061@item Whb
3062A memory reference using @code{HL} as a base register, with @code{B} or @code{C} as the index register.
3063@item Whl
3064A memory reference using @code{HL} as a base register, without any offset.
3065@item Ws1
3066A memory reference using @code{SP} as a base register, with an optional one-byte offset.
3067@item Y
3068Any memory reference to an address in the near address space.
3069@item A
3070The @code{AX} register.
3071@item B
3072The @code{BC} register.
3073@item D
3074The @code{DE} register.
3075@item R
3076@code{A} through @code{L} registers.
3077@item S
3078The @code{SP} register.
3079@item T
3080The @code{HL} register.
3081@item Z08W
3082The 16-bit @code{R8} register.
3083@item Z10W
3084The 16-bit @code{R10} register.
3085@item Zint
3086The registers reserved for interrupts (@code{R24} to @code{R31}).
3087@item a
3088The @code{A} register.
3089@item b
3090The @code{B} register.
3091@item c
3092The @code{C} register.
3093@item d
3094The @code{D} register.
3095@item e
3096The @code{E} register.
3097@item h
3098The @code{H} register.
3099@item l
3100The @code{L} register.
3101@item v
3102The virtual registers.
3103@item w
3104The @code{PSW} register.
3105@item x
3106The @code{X} register.
3107
3108@end table
3109
65a324b4
NC
3110@item RX---@file{config/rx/constraints.md}
3111@table @code
3112@item Q
3113An address which does not involve register indirect addressing or
3114pre/post increment/decrement addressing.
3115
3116@item Symbol
3117A symbol reference.
3118
3119@item Int08
3120A constant in the range @minus{}256 to 255, inclusive.
3121
3122@item Sint08
3123A constant in the range @minus{}128 to 127, inclusive.
3124
3125@item Sint16
3126A constant in the range @minus{}32768 to 32767, inclusive.
3127
3128@item Sint24
3129A constant in the range @minus{}8388608 to 8388607, inclusive.
3130
3131@item Uint04
3132A constant in the range 0 to 15, inclusive.
3133
3134@end table
3135
03dda8e3 3136@need 1000
74fe790b 3137@item SPARC---@file{config/sparc/sparc.h}
03dda8e3
RK
3138@table @code
3139@item f
53e5f173
EB
3140Floating-point register on the SPARC-V8 architecture and
3141lower floating-point register on the SPARC-V9 architecture.
03dda8e3
RK
3142
3143@item e
8a36672b 3144Floating-point register. It is equivalent to @samp{f} on the
53e5f173
EB
3145SPARC-V8 architecture and contains both lower and upper
3146floating-point registers on the SPARC-V9 architecture.
03dda8e3 3147
8a69f99f
EB
3148@item c
3149Floating-point condition code register.
3150
3151@item d
8a36672b 3152Lower floating-point register. It is only valid on the SPARC-V9
53e5f173 3153architecture when the Visual Instruction Set is available.
8a69f99f
EB
3154
3155@item b
8a36672b 3156Floating-point register. It is only valid on the SPARC-V9 architecture
53e5f173 3157when the Visual Instruction Set is available.
8a69f99f
EB
3158
3159@item h
316064-bit global or out register for the SPARC-V8+ architecture.
3161
66e62b49
KH
3162@item D
3163A vector constant
3164
03dda8e3 3165@item I
1e5f973d 3166Signed 13-bit constant
03dda8e3
RK
3167
3168@item J
3169Zero
3170
3171@item K
1e5f973d 317232-bit constant with the low 12 bits clear (a constant that can be
03dda8e3
RK
3173loaded with the @code{sethi} instruction)
3174
7d6040e8
AO
3175@item L
3176A constant in the range supported by @code{movcc} instructions
3177
3178@item M
3179A constant in the range supported by @code{movrcc} instructions
3180
3181@item N
3182Same as @samp{K}, except that it verifies that bits that are not in the
57694e40 3183lower 32-bit range are all zero. Must be used instead of @samp{K} for
7d6040e8
AO
3184modes wider than @code{SImode}
3185
ef0139b1
EB
3186@item O
3187The constant 4096
3188
03dda8e3
RK
3189@item G
3190Floating-point zero
3191
3192@item H
1e5f973d 3193Signed 13-bit constant, sign-extended to 32 or 64 bits
03dda8e3
RK
3194
3195@item Q
62190128
DM
3196Floating-point constant whose integral representation can
3197be moved into an integer register using a single sethi
3198instruction
3199
3200@item R
3201Floating-point constant whose integral representation can
3202be moved into an integer register using a single mov
3203instruction
03dda8e3
RK
3204
3205@item S
62190128
DM
3206Floating-point constant whose integral representation can
3207be moved into an integer register using a high/lo_sum
3208instruction sequence
03dda8e3
RK
3209
3210@item T
3211Memory address aligned to an 8-byte boundary
3212
3213@item U
3214Even register
6ca30df6 3215
7a31a340 3216@item W
c75d6010
JM
3217Memory address for @samp{e} constraint registers
3218
3219@item Y
3220Vector zero
7a31a340 3221
6ca30df6
MH
3222@end table
3223
85d9c13c
TS
3224@item SPU---@file{config/spu/spu.h}
3225@table @code
3226@item a
ff2ce160 3227An immediate which can be loaded with the il/ila/ilh/ilhu instructions. const_int is treated as a 64 bit value.
85d9c13c
TS
3228
3229@item c
ff2ce160 3230An immediate for and/xor/or instructions. const_int is treated as a 64 bit value.
85d9c13c
TS
3231
3232@item d
ff2ce160 3233An immediate for the @code{iohl} instruction. const_int is treated as a 64 bit value.
85d9c13c
TS
3234
3235@item f
ff2ce160 3236An immediate which can be loaded with @code{fsmbi}.
85d9c13c
TS
3237
3238@item A
ff2ce160 3239An immediate which can be loaded with the il/ila/ilh/ilhu instructions. const_int is treated as a 32 bit value.
85d9c13c
TS
3240
3241@item B
ff2ce160 3242An immediate for most arithmetic instructions. const_int is treated as a 32 bit value.
85d9c13c
TS
3243
3244@item C
ff2ce160 3245An immediate for and/xor/or instructions. const_int is treated as a 32 bit value.
85d9c13c
TS
3246
3247@item D
ff2ce160 3248An immediate for the @code{iohl} instruction. const_int is treated as a 32 bit value.
85d9c13c
TS
3249
3250@item I
ff2ce160 3251A constant in the range [@minus{}64, 63] for shift/rotate instructions.
85d9c13c
TS
3252
3253@item J
ff2ce160 3254An unsigned 7-bit constant for conversion/nop/channel instructions.
85d9c13c
TS
3255
3256@item K
ff2ce160 3257A signed 10-bit constant for most arithmetic instructions.
85d9c13c
TS
3258
3259@item M
ff2ce160 3260A signed 16 bit immediate for @code{stop}.
85d9c13c
TS
3261
3262@item N
ff2ce160 3263An unsigned 16-bit constant for @code{iohl} and @code{fsmbi}.
85d9c13c
TS
3264
3265@item O
ff2ce160 3266An unsigned 7-bit constant whose 3 least significant bits are 0.
85d9c13c
TS
3267
3268@item P
ff2ce160 3269An unsigned 3-bit constant for 16-byte rotates and shifts
85d9c13c
TS
3270
3271@item R
ff2ce160 3272Call operand, reg, for indirect calls
85d9c13c
TS
3273
3274@item S
ff2ce160 3275Call operand, symbol, for relative calls.
85d9c13c
TS
3276
3277@item T
ff2ce160 3278Call operand, const_int, for absolute calls.
85d9c13c
TS
3279
3280@item U
ff2ce160 3281An immediate which can be loaded with the il/ila/ilh/ilhu instructions. const_int is sign extended to 128 bit.
85d9c13c
TS
3282
3283@item W
ff2ce160 3284An immediate for shift and rotate instructions. const_int is treated as a 32 bit value.
85d9c13c
TS
3285
3286@item Y
ff2ce160 3287An immediate for and/xor/or instructions. const_int is sign extended as a 128 bit.
85d9c13c
TS
3288
3289@item Z
ff2ce160 3290An immediate for the @code{iohl} instruction. const_int is sign extended to 128 bit.
85d9c13c
TS
3291
3292@end table
3293
74fe790b 3294@item S/390 and zSeries---@file{config/s390/s390.h}
91abf72d
HP
3295@table @code
3296@item a
3297Address register (general purpose register except r0)
3298
9dc62c00
AK
3299@item c
3300Condition code register
3301
91abf72d
HP
3302@item d
3303Data register (arbitrary general purpose register)
3304
3305@item f
3306Floating-point register
3307
3308@item I
3309Unsigned 8-bit constant (0--255)
3310
3311@item J
3312Unsigned 12-bit constant (0--4095)
3313
3314@item K
3315Signed 16-bit constant (@minus{}32768--32767)
3316
3317@item L
f19a9af7
AK
3318Value appropriate as displacement.
3319@table @code
6ccde948
RW
3320@item (0..4095)
3321for short displacement
8ad1dde7 3322@item (@minus{}524288..524287)
6ccde948 3323for long displacement
f19a9af7
AK
3324@end table
3325
3326@item M
3327Constant integer with a value of 0x7fffffff.
3328
3329@item N
3330Multiple letter constraint followed by 4 parameter letters.
3331@table @code
6ccde948
RW
3332@item 0..9:
3333number of the part counting from most to least significant
3334@item H,Q:
3335mode of the part
3336@item D,S,H:
3337mode of the containing operand
3338@item 0,F:
3339value of the other parts (F---all bits set)
f19a9af7
AK
3340@end table
3341The constraint matches if the specified part of a constant
dc9a511d 3342has a value different from its other parts.
91abf72d
HP
3343
3344@item Q
f19a9af7
AK
3345Memory reference without index register and with short displacement.
3346
3347@item R
3348Memory reference with index register and short displacement.
91abf72d
HP
3349
3350@item S
f19a9af7
AK
3351Memory reference without index register but with long displacement.
3352
3353@item T
3354Memory reference with index register and long displacement.
3355
3356@item U
3357Pointer with short displacement.
3358
3359@item W
3360Pointer with long displacement.
3361
3362@item Y
3363Shift count operand.
91abf72d
HP
3364
3365@end table
3366
93ef7c1f
CL
3367@item Score family---@file{config/score/score.h}
3368@table @code
3369@item d
3370Registers from r0 to r32.
3371
3372@item e
3373Registers from r0 to r16.
3374
3375@item t
3376r8---r11 or r22---r27 registers.
3377
3378@item h
3379hi register.
3380
3381@item l
3382lo register.
3383
3384@item x
3385hi + lo register.
3386
3387@item q
3388cnt register.
3389
3390@item y
3391lcb register.
3392
3393@item z
3394scb register.
3395
3396@item a
3397cnt + lcb + scb register.
3398
3399@item c
3400cr0---cr15 register.
3401
3402@item b
3403cp1 registers.
3404
3405@item f
3406cp2 registers.
3407
3408@item i
3409cp3 registers.
3410
3411@item j
3412cp1 + cp2 + cp3 registers.
3413
3414@item I
c6681463 3415High 16-bit constant (32-bit constant with 16 LSBs zero).
93ef7c1f
CL
3416
3417@item J
3418Unsigned 5 bit integer (in the range 0 to 31).
3419
3420@item K
3421Unsigned 16 bit integer (in the range 0 to 65535).
3422
3423@item L
3424Signed 16 bit integer (in the range @minus{}32768 to 32767).
3425
3426@item M
3427Unsigned 14 bit integer (in the range 0 to 16383).
3428
3429@item N
3430Signed 14 bit integer (in the range @minus{}8192 to 8191).
3431
93ef7c1f
CL
3432@item Z
3433Any SYMBOL_REF.
3434@end table
3435
74fe790b 3436@item Xstormy16---@file{config/stormy16/stormy16.h}
9f339dde
GK
3437@table @code
3438@item a
3439Register r0.
3440
3441@item b
3442Register r1.
3443
3444@item c
3445Register r2.
3446
3447@item d
3448Register r8.
3449
3450@item e
3451Registers r0 through r7.
3452
3453@item t
3454Registers r0 and r1.
3455
3456@item y
3457The carry register.
3458
3459@item z
3460Registers r8 and r9.
3461
3462@item I
3463A constant between 0 and 3 inclusive.
3464
3465@item J
3466A constant that has exactly one bit set.
3467
3468@item K
3469A constant that has exactly one bit clear.
3470
3471@item L
3472A constant between 0 and 255 inclusive.
3473
3474@item M
69a0611f 3475A constant between @minus{}255 and 0 inclusive.
9f339dde
GK
3476
3477@item N
69a0611f 3478A constant between @minus{}3 and 0 inclusive.
9f339dde
GK
3479
3480@item O
3481A constant between 1 and 4 inclusive.
3482
3483@item P
69a0611f 3484A constant between @minus{}4 and @minus{}1 inclusive.
9f339dde
GK
3485
3486@item Q
3487A memory reference that is a stack push.
3488
3489@item R
3490A memory reference that is a stack pop.
3491
3492@item S
63519d23 3493A memory reference that refers to a constant address of known value.
9f339dde
GK
3494
3495@item T
3496The register indicated by Rx (not implemented yet).
3497
3498@item U
3499A constant that is not between 2 and 15 inclusive.
3500
e2ce66a9
DD
3501@item Z
3502The constant 0.
3503
9f339dde
GK
3504@end table
3505
bcead286
BS
3506@item TI C6X family---@file{config/c6x/constraints.md}
3507@table @code
3508@item a
3509Register file A (A0--A31).
3510
3511@item b
3512Register file B (B0--B31).
3513
3514@item A
3515Predicate registers in register file A (A0--A2 on C64X and
3516higher, A1 and A2 otherwise).
3517
3518@item B
3519Predicate registers in register file B (B0--B2).
3520
3521@item C
3522A call-used register in register file B (B0--B9, B16--B31).
3523
3524@item Da
3525Register file A, excluding predicate registers (A3--A31,
3526plus A0 if not C64X or higher).
3527
3528@item Db
3529Register file B, excluding predicate registers (B3--B31).
3530
3531@item Iu4
3532Integer constant in the range 0 @dots{} 15.
3533
3534@item Iu5
3535Integer constant in the range 0 @dots{} 31.
3536
3537@item In5
3538Integer constant in the range @minus{}31 @dots{} 0.
3539
3540@item Is5
3541Integer constant in the range @minus{}16 @dots{} 15.
3542
3543@item I5x
3544Integer constant that can be the operand of an ADDA or a SUBA insn.
3545
3546@item IuB
3547Integer constant in the range 0 @dots{} 65535.
3548
3549@item IsB
3550Integer constant in the range @minus{}32768 @dots{} 32767.
3551
3552@item IsC
3553Integer constant in the range @math{-2^{20}} @dots{} @math{2^{20} - 1}.
3554
3555@item Jc
3556Integer constant that is a valid mask for the clr instruction.
3557
3558@item Js
3559Integer constant that is a valid mask for the set instruction.
3560
3561@item Q
3562Memory location with A base register.
3563
3564@item R
3565Memory location with B base register.
3566
3567@ifset INTERNALS
3568@item S0
3569On C64x+ targets, a GP-relative small data reference.
3570
3571@item S1
3572Any kind of @code{SYMBOL_REF}, for use in a call address.
3573
3574@item Si
3575Any kind of immediate operand, unless it matches the S0 constraint.
3576
3577@item T
3578Memory location with B base register, but not using a long offset.
3579
3580@item W
3581A memory operand with an address that can't be used in an unaligned access.
3582
3583@end ifset
3584@item Z
3585Register B14 (aka DP).
3586
3587@end table
3588
dd552284
WL
3589@item TILE-Gx---@file{config/tilegx/constraints.md}
3590@table @code
3591@item R00
3592@itemx R01
3593@itemx R02
3594@itemx R03
3595@itemx R04
3596@itemx R05
3597@itemx R06
3598@itemx R07
3599@itemx R08
3600@itemx R09
655c5444 3601@itemx R10
dd552284
WL
3602Each of these represents a register constraint for an individual
3603register, from r0 to r10.
3604
3605@item I
3606Signed 8-bit integer constant.
3607
3608@item J
3609Signed 16-bit integer constant.
3610
3611@item K
3612Unsigned 16-bit integer constant.
3613
3614@item L
3615Integer constant that fits in one signed byte when incremented by one
3616(@minus{}129 @dots{} 126).
3617
3618@item m
3619Memory operand. If used together with @samp{<} or @samp{>}, the
3620operand can have postincrement which requires printing with @samp{%In}
3621and @samp{%in} on TILE-Gx. For example:
3622
3623@smallexample
3624asm ("st_add %I0,%1,%i0" : "=m<>" (*mem) : "r" (val));
3625@end smallexample
3626
3627@item M
3628A bit mask suitable for the BFINS instruction.
3629
3630@item N
3631Integer constant that is a byte tiled out eight times.
3632
3633@item O
3634The integer zero constant.
3635
3636@item P
3637Integer constant that is a sign-extended byte tiled out as four shorts.
3638
3639@item Q
3640Integer constant that fits in one signed byte when incremented
3641(@minus{}129 @dots{} 126), but excluding -1.
3642
3643@item S
3644Integer constant that has all 1 bits consecutive and starting at bit 0.
3645
3646@item T
3647A 16-bit fragment of a got, tls, or pc-relative reference.
3648
3649@item U
3650Memory operand except postincrement. This is roughly the same as
3651@samp{m} when not used together with @samp{<} or @samp{>}.
3652
3653@item W
3654An 8-element vector constant with identical elements.
3655
3656@item Y
3657A 4-element vector constant with identical elements.
3658
3659@item Z0
3660The integer constant 0xffffffff.
3661
3662@item Z1
3663The integer constant 0xffffffff00000000.
3664
3665@end table
3666
3667@item TILEPro---@file{config/tilepro/constraints.md}
3668@table @code
3669@item R00
3670@itemx R01
3671@itemx R02
3672@itemx R03
3673@itemx R04
3674@itemx R05
3675@itemx R06
3676@itemx R07
3677@itemx R08
3678@itemx R09
655c5444 3679@itemx R10
dd552284
WL
3680Each of these represents a register constraint for an individual
3681register, from r0 to r10.
3682
3683@item I
3684Signed 8-bit integer constant.
3685
3686@item J
3687Signed 16-bit integer constant.
3688
3689@item K
3690Nonzero integer constant with low 16 bits zero.
3691
3692@item L
3693Integer constant that fits in one signed byte when incremented by one
3694(@minus{}129 @dots{} 126).
3695
3696@item m
3697Memory operand. If used together with @samp{<} or @samp{>}, the
3698operand can have postincrement which requires printing with @samp{%In}
3699and @samp{%in} on TILEPro. For example:
3700
3701@smallexample
3702asm ("swadd %I0,%1,%i0" : "=m<>" (mem) : "r" (val));
3703@end smallexample
3704
3705@item M
3706A bit mask suitable for the MM instruction.
3707
3708@item N
3709Integer constant that is a byte tiled out four times.
3710
3711@item O
3712The integer zero constant.
3713
3714@item P
3715Integer constant that is a sign-extended byte tiled out as two shorts.
3716
3717@item Q
3718Integer constant that fits in one signed byte when incremented
3719(@minus{}129 @dots{} 126), but excluding -1.
3720
3721@item T
3722A symbolic operand, or a 16-bit fragment of a got, tls, or pc-relative
3723reference.
3724
3725@item U
3726Memory operand except postincrement. This is roughly the same as
3727@samp{m} when not used together with @samp{<} or @samp{>}.
3728
3729@item W
3730A 4-element vector constant with identical elements.
3731
3732@item Y
3733A 2-element vector constant with identical elements.
3734
3735@end table
3736
887af464 3737@item Xtensa---@file{config/xtensa/constraints.md}
03984308
BW
3738@table @code
3739@item a
3740General-purpose 32-bit register
3741
3742@item b
3743One-bit boolean register
3744
3745@item A
3746MAC16 40-bit accumulator register
3747
3748@item I
3749Signed 12-bit integer constant, for use in MOVI instructions
3750
3751@item J
3752Signed 8-bit integer constant, for use in ADDI instructions
3753
3754@item K
3755Integer constant valid for BccI instructions
3756
3757@item L
3758Unsigned constant valid for BccUI instructions
3759
3760@end table
3761
03dda8e3
RK
3762@end table
3763
7ac28727
AK
3764@ifset INTERNALS
3765@node Disable Insn Alternatives
3766@subsection Disable insn alternatives using the @code{enabled} attribute
3767@cindex enabled
3768
3769The @code{enabled} insn attribute may be used to disable certain insn
3770alternatives for machine-specific reasons. This is useful when adding
3771new instructions to an existing pattern which are only available for
3772certain cpu architecture levels as specified with the @code{-march=}
3773option.
3774
3775If an insn alternative is disabled, then it will never be used. The
3776compiler treats the constraints for the disabled alternative as
3777unsatisfiable.
3778
3779In order to make use of the @code{enabled} attribute a back end has to add
3780in the machine description files:
3781
3782@enumerate
3783@item
3784A definition of the @code{enabled} insn attribute. The attribute is
3785defined as usual using the @code{define_attr} command. This
3786definition should be based on other insn attributes and/or target flags.
3787The @code{enabled} attribute is a numeric attribute and should evaluate to
3788@code{(const_int 1)} for an enabled alternative and to
3789@code{(const_int 0)} otherwise.
3790@item
3791A definition of another insn attribute used to describe for what
3792reason an insn alternative might be available or
3793not. E.g. @code{cpu_facility} as in the example below.
3794@item
a640c13b 3795An assignment for the second attribute to each insn definition
7ac28727
AK
3796combining instructions which are not all available under the same
3797circumstances. (Note: It obviously only makes sense for definitions
3798with more than one alternative. Otherwise the insn pattern should be
3799disabled or enabled using the insn condition.)
3800@end enumerate
3801
3802E.g. the following two patterns could easily be merged using the @code{enabled}
3803attribute:
3804
3805@smallexample
3806
3807(define_insn "*movdi_old"
3808 [(set (match_operand:DI 0 "register_operand" "=d")
3809 (match_operand:DI 1 "register_operand" " d"))]
3810 "!TARGET_NEW"
3811 "lgr %0,%1")
3812
3813(define_insn "*movdi_new"
3814 [(set (match_operand:DI 0 "register_operand" "=d,f,d")
3815 (match_operand:DI 1 "register_operand" " d,d,f"))]
3816 "TARGET_NEW"
3817 "@@
3818 lgr %0,%1
3819 ldgr %0,%1
3820 lgdr %0,%1")
3821
3822@end smallexample
3823
3824to:
3825
3826@smallexample
3827
3828(define_insn "*movdi_combined"
3829 [(set (match_operand:DI 0 "register_operand" "=d,f,d")
3830 (match_operand:DI 1 "register_operand" " d,d,f"))]
3831 ""
3832 "@@
3833 lgr %0,%1
3834 ldgr %0,%1
3835 lgdr %0,%1"
3836 [(set_attr "cpu_facility" "*,new,new")])
3837
3838@end smallexample
3839
3840with the @code{enabled} attribute defined like this:
3841
3842@smallexample
3843
3844(define_attr "cpu_facility" "standard,new" (const_string "standard"))
3845
3846(define_attr "enabled" ""
3847 (cond [(eq_attr "cpu_facility" "standard") (const_int 1)
3848 (and (eq_attr "cpu_facility" "new")
3849 (ne (symbol_ref "TARGET_NEW") (const_int 0)))
3850 (const_int 1)]
3851 (const_int 0)))
3852
3853@end smallexample
3854
3855@end ifset
3856
03dda8e3 3857@ifset INTERNALS
f38840db
ZW
3858@node Define Constraints
3859@subsection Defining Machine-Specific Constraints
3860@cindex defining constraints
3861@cindex constraints, defining
3862
3863Machine-specific constraints fall into two categories: register and
3864non-register constraints. Within the latter category, constraints
3865which allow subsets of all possible memory or address operands should
3866be specially marked, to give @code{reload} more information.
3867
3868Machine-specific constraints can be given names of arbitrary length,
3869but they must be entirely composed of letters, digits, underscores
3870(@samp{_}), and angle brackets (@samp{< >}). Like C identifiers, they
ff2ce160 3871must begin with a letter or underscore.
f38840db
ZW
3872
3873In order to avoid ambiguity in operand constraint strings, no
3874constraint can have a name that begins with any other constraint's
3875name. For example, if @code{x} is defined as a constraint name,
3876@code{xy} may not be, and vice versa. As a consequence of this rule,
3877no constraint may begin with one of the generic constraint letters:
3878@samp{E F V X g i m n o p r s}.
3879
3880Register constraints correspond directly to register classes.
3881@xref{Register Classes}. There is thus not much flexibility in their
3882definitions.
3883
3884@deffn {MD Expression} define_register_constraint name regclass docstring
3885All three arguments are string constants.
3886@var{name} is the name of the constraint, as it will appear in
5be527d0
RG
3887@code{match_operand} expressions. If @var{name} is a multi-letter
3888constraint its length shall be the same for all constraints starting
3889with the same letter. @var{regclass} can be either the
f38840db
ZW
3890name of the corresponding register class (@pxref{Register Classes}),
3891or a C expression which evaluates to the appropriate register class.
3892If it is an expression, it must have no side effects, and it cannot
3893look at the operand. The usual use of expressions is to map some
3894register constraints to @code{NO_REGS} when the register class
3895is not available on a given subarchitecture.
3896
3897@var{docstring} is a sentence documenting the meaning of the
3898constraint. Docstrings are explained further below.
3899@end deffn
3900
3901Non-register constraints are more like predicates: the constraint
3902definition gives a Boolean expression which indicates whether the
3903constraint matches.
3904
3905@deffn {MD Expression} define_constraint name docstring exp
3906The @var{name} and @var{docstring} arguments are the same as for
3907@code{define_register_constraint}, but note that the docstring comes
3908immediately after the name for these expressions. @var{exp} is an RTL
3909expression, obeying the same rules as the RTL expressions in predicate
3910definitions. @xref{Defining Predicates}, for details. If it
3911evaluates true, the constraint matches; if it evaluates false, it
3912doesn't. Constraint expressions should indicate which RTL codes they
3913might match, just like predicate expressions.
3914
3915@code{match_test} C expressions have access to the
3916following variables:
3917
3918@table @var
3919@item op
3920The RTL object defining the operand.
3921@item mode
3922The machine mode of @var{op}.
3923@item ival
3924@samp{INTVAL (@var{op})}, if @var{op} is a @code{const_int}.
3925@item hval
3926@samp{CONST_DOUBLE_HIGH (@var{op})}, if @var{op} is an integer
3927@code{const_double}.
3928@item lval
3929@samp{CONST_DOUBLE_LOW (@var{op})}, if @var{op} is an integer
3930@code{const_double}.
3931@item rval
3932@samp{CONST_DOUBLE_REAL_VALUE (@var{op})}, if @var{op} is a floating-point
3fa1b0e5 3933@code{const_double}.
f38840db
ZW
3934@end table
3935
3936The @var{*val} variables should only be used once another piece of the
3937expression has verified that @var{op} is the appropriate kind of RTL
3938object.
3939@end deffn
3940
3941Most non-register constraints should be defined with
3942@code{define_constraint}. The remaining two definition expressions
3943are only appropriate for constraints that should be handled specially
3944by @code{reload} if they fail to match.
3945
3946@deffn {MD Expression} define_memory_constraint name docstring exp
3947Use this expression for constraints that match a subset of all memory
3948operands: that is, @code{reload} can make them match by converting the
3949operand to the form @samp{@w{(mem (reg @var{X}))}}, where @var{X} is a
3950base register (from the register class specified by
3951@code{BASE_REG_CLASS}, @pxref{Register Classes}).
3952
3953For example, on the S/390, some instructions do not accept arbitrary
3954memory references, but only those that do not make use of an index
3955register. The constraint letter @samp{Q} is defined to represent a
3956memory address of this type. If @samp{Q} is defined with
3957@code{define_memory_constraint}, a @samp{Q} constraint can handle any
3958memory operand, because @code{reload} knows it can simply copy the
3959memory address into a base register if required. This is analogous to
e4ae5e77 3960the way an @samp{o} constraint can handle any memory operand.
f38840db
ZW
3961
3962The syntax and semantics are otherwise identical to
3963@code{define_constraint}.
3964@end deffn
3965
3966@deffn {MD Expression} define_address_constraint name docstring exp
3967Use this expression for constraints that match a subset of all address
3968operands: that is, @code{reload} can make the constraint match by
3969converting the operand to the form @samp{@w{(reg @var{X})}}, again
3970with @var{X} a base register.
3971
3972Constraints defined with @code{define_address_constraint} can only be
3973used with the @code{address_operand} predicate, or machine-specific
3974predicates that work the same way. They are treated analogously to
3975the generic @samp{p} constraint.
3976
3977The syntax and semantics are otherwise identical to
3978@code{define_constraint}.
3979@end deffn
3980
3981For historical reasons, names beginning with the letters @samp{G H}
3982are reserved for constraints that match only @code{const_double}s, and
3983names beginning with the letters @samp{I J K L M N O P} are reserved
3984for constraints that match only @code{const_int}s. This may change in
3985the future. For the time being, constraints with these names must be
3986written in a stylized form, so that @code{genpreds} can tell you did
3987it correctly:
3988
3989@smallexample
3990@group
3991(define_constraint "[@var{GHIJKLMNOP}]@dots{}"
3992 "@var{doc}@dots{}"
3993 (and (match_code "const_int") ; @r{@code{const_double} for G/H}
3994 @var{condition}@dots{})) ; @r{usually a @code{match_test}}
3995@end group
3996@end smallexample
3997@c the semicolons line up in the formatted manual
3998
3999It is fine to use names beginning with other letters for constraints
4000that match @code{const_double}s or @code{const_int}s.
4001
4002Each docstring in a constraint definition should be one or more complete
4003sentences, marked up in Texinfo format. @emph{They are currently unused.}
4004In the future they will be copied into the GCC manual, in @ref{Machine
4005Constraints}, replacing the hand-maintained tables currently found in
4006that section. Also, in the future the compiler may use this to give
4007more helpful diagnostics when poor choice of @code{asm} constraints
4008causes a reload failure.
4009
4010If you put the pseudo-Texinfo directive @samp{@@internal} at the
4011beginning of a docstring, then (in the future) it will appear only in
4012the internals manual's version of the machine-specific constraint tables.
4013Use this for constraints that should not appear in @code{asm} statements.
4014
4015@node C Constraint Interface
4016@subsection Testing constraints from C
4017@cindex testing constraints
4018@cindex constraints, testing
4019
4020It is occasionally useful to test a constraint from C code rather than
4021implicitly via the constraint string in a @code{match_operand}. The
4022generated file @file{tm_p.h} declares a few interfaces for working
4023with machine-specific constraints. None of these interfaces work with
4024the generic constraints described in @ref{Simple Constraints}. This
4025may change in the future.
4026
4027@strong{Warning:} @file{tm_p.h} may declare other functions that
4028operate on constraints, besides the ones documented here. Do not use
4029those functions from machine-dependent code. They exist to implement
4030the old constraint interface that machine-independent components of
4031the compiler still expect. They will change or disappear in the
4032future.
4033
4034Some valid constraint names are not valid C identifiers, so there is a
4035mangling scheme for referring to them from C@. Constraint names that
4036do not contain angle brackets or underscores are left unchanged.
4037Underscores are doubled, each @samp{<} is replaced with @samp{_l}, and
4038each @samp{>} with @samp{_g}. Here are some examples:
4039
4040@c the @c's prevent double blank lines in the printed manual.
4041@example
4042@multitable {Original} {Mangled}
cccb0908 4043@item @strong{Original} @tab @strong{Mangled} @c
f38840db
ZW
4044@item @code{x} @tab @code{x} @c
4045@item @code{P42x} @tab @code{P42x} @c
4046@item @code{P4_x} @tab @code{P4__x} @c
4047@item @code{P4>x} @tab @code{P4_gx} @c
4048@item @code{P4>>} @tab @code{P4_g_g} @c
4049@item @code{P4_g>} @tab @code{P4__g_g} @c
4050@end multitable
4051@end example
4052
4053Throughout this section, the variable @var{c} is either a constraint
4054in the abstract sense, or a constant from @code{enum constraint_num};
4055the variable @var{m} is a mangled constraint name (usually as part of
4056a larger identifier).
4057
4058@deftp Enum constraint_num
4059For each machine-specific constraint, there is a corresponding
4060enumeration constant: @samp{CONSTRAINT_} plus the mangled name of the
4061constraint. Functions that take an @code{enum constraint_num} as an
4062argument expect one of these constants.
4063
4064Machine-independent constraints do not have associated constants.
4065This may change in the future.
4066@end deftp
4067
4068@deftypefun {inline bool} satisfies_constraint_@var{m} (rtx @var{exp})
4069For each machine-specific, non-register constraint @var{m}, there is
4070one of these functions; it returns @code{true} if @var{exp} satisfies the
4071constraint. These functions are only visible if @file{rtl.h} was included
4072before @file{tm_p.h}.
4073@end deftypefun
4074
4075@deftypefun bool constraint_satisfied_p (rtx @var{exp}, enum constraint_num @var{c})
4076Like the @code{satisfies_constraint_@var{m}} functions, but the
4077constraint to test is given as an argument, @var{c}. If @var{c}
4078specifies a register constraint, this function will always return
4079@code{false}.
4080@end deftypefun
4081
4082@deftypefun {enum reg_class} regclass_for_constraint (enum constraint_num @var{c})
4083Returns the register class associated with @var{c}. If @var{c} is not
4084a register constraint, or those registers are not available for the
4085currently selected subtarget, returns @code{NO_REGS}.
4086@end deftypefun
4087
4088Here is an example use of @code{satisfies_constraint_@var{m}}. In
4089peephole optimizations (@pxref{Peephole Definitions}), operand
4090constraint strings are ignored, so if there are relevant constraints,
4091they must be tested in the C condition. In the example, the
4092optimization is applied if operand 2 does @emph{not} satisfy the
4093@samp{K} constraint. (This is a simplified version of a peephole
4094definition from the i386 machine description.)
4095
4096@smallexample
4097(define_peephole2
4098 [(match_scratch:SI 3 "r")
4099 (set (match_operand:SI 0 "register_operand" "")
6ccde948
RW
4100 (mult:SI (match_operand:SI 1 "memory_operand" "")
4101 (match_operand:SI 2 "immediate_operand" "")))]
f38840db
ZW
4102
4103 "!satisfies_constraint_K (operands[2])"
4104
4105 [(set (match_dup 3) (match_dup 1))
4106 (set (match_dup 0) (mult:SI (match_dup 3) (match_dup 2)))]
4107
4108 "")
4109@end smallexample
4110
03dda8e3
RK
4111@node Standard Names
4112@section Standard Pattern Names For Generation
4113@cindex standard pattern names
4114@cindex pattern names
4115@cindex names, pattern
4116
4117Here is a table of the instruction names that are meaningful in the RTL
4118generation pass of the compiler. Giving one of these names to an
4119instruction pattern tells the RTL generation pass that it can use the
556e0f21 4120pattern to accomplish a certain task.
03dda8e3
RK
4121
4122@table @asis
4123@cindex @code{mov@var{m}} instruction pattern
4124@item @samp{mov@var{m}}
4bd0bee9 4125Here @var{m} stands for a two-letter machine mode name, in lowercase.
03dda8e3
RK
4126This instruction pattern moves data with that machine mode from operand
41271 to operand 0. For example, @samp{movsi} moves full-word data.
4128
4129If operand 0 is a @code{subreg} with mode @var{m} of a register whose
4130own mode is wider than @var{m}, the effect of this instruction is
4131to store the specified value in the part of the register that corresponds
8feb4e28
JL
4132to mode @var{m}. Bits outside of @var{m}, but which are within the
4133same target word as the @code{subreg} are undefined. Bits which are
4134outside the target word are left unchanged.
03dda8e3
RK
4135
4136This class of patterns is special in several ways. First of all, each
65945ec1
HPN
4137of these names up to and including full word size @emph{must} be defined,
4138because there is no other way to copy a datum from one place to another.
4139If there are patterns accepting operands in larger modes,
4140@samp{mov@var{m}} must be defined for integer modes of those sizes.
03dda8e3
RK
4141
4142Second, these patterns are not used solely in the RTL generation pass.
4143Even the reload pass can generate move insns to copy values from stack
4144slots into temporary registers. When it does so, one of the operands is
4145a hard register and the other is an operand that can need to be reloaded
4146into a register.
4147
4148@findex force_reg
4149Therefore, when given such a pair of operands, the pattern must generate
4150RTL which needs no reloading and needs no temporary registers---no
4151registers other than the operands. For example, if you support the
4152pattern with a @code{define_expand}, then in such a case the
4153@code{define_expand} mustn't call @code{force_reg} or any other such
4154function which might generate new pseudo registers.
4155
4156This requirement exists even for subword modes on a RISC machine where
4157fetching those modes from memory normally requires several insns and
39ed8974 4158some temporary registers.
03dda8e3
RK
4159
4160@findex change_address
4161During reload a memory reference with an invalid address may be passed
4162as an operand. Such an address will be replaced with a valid address
4163later in the reload pass. In this case, nothing may be done with the
4164address except to use it as it stands. If it is copied, it will not be
4165replaced with a valid address. No attempt should be made to make such
4166an address into a valid address and no routine (such as
4167@code{change_address}) that will do so may be called. Note that
4168@code{general_operand} will fail when applied to such an address.
4169
4170@findex reload_in_progress
4171The global variable @code{reload_in_progress} (which must be explicitly
4172declared if required) can be used to determine whether such special
4173handling is required.
4174
4175The variety of operands that have reloads depends on the rest of the
4176machine description, but typically on a RISC machine these can only be
4177pseudo registers that did not get hard registers, while on other
4178machines explicit memory references will get optional reloads.
4179
4180If a scratch register is required to move an object to or from memory,
f1db3576
JL
4181it can be allocated using @code{gen_reg_rtx} prior to life analysis.
4182
9c34dbbf 4183If there are cases which need scratch registers during or after reload,
8a99f6f9 4184you must provide an appropriate secondary_reload target hook.
03dda8e3 4185
ef4375b2
KZ
4186@findex can_create_pseudo_p
4187The macro @code{can_create_pseudo_p} can be used to determine if it
f1db3576
JL
4188is unsafe to create new pseudo registers. If this variable is nonzero, then
4189it is unsafe to call @code{gen_reg_rtx} to allocate a new pseudo.
4190
956d6950 4191The constraints on a @samp{mov@var{m}} must permit moving any hard
03dda8e3
RK
4192register to any other hard register provided that
4193@code{HARD_REGNO_MODE_OK} permits mode @var{m} in both registers and
de8f4b07
AS
4194@code{TARGET_REGISTER_MOVE_COST} applied to their classes returns a value
4195of 2.
03dda8e3 4196
956d6950 4197It is obligatory to support floating point @samp{mov@var{m}}
03dda8e3
RK
4198instructions into and out of any registers that can hold fixed point
4199values, because unions and structures (which have modes @code{SImode} or
4200@code{DImode}) can be in those registers and they may have floating
4201point members.
4202
956d6950 4203There may also be a need to support fixed point @samp{mov@var{m}}
03dda8e3
RK
4204instructions in and out of floating point registers. Unfortunately, I
4205have forgotten why this was so, and I don't know whether it is still
4206true. If @code{HARD_REGNO_MODE_OK} rejects fixed point values in
4207floating point registers, then the constraints of the fixed point
956d6950 4208@samp{mov@var{m}} instructions must be designed to avoid ever trying to
03dda8e3
RK
4209reload into a floating point register.
4210
4211@cindex @code{reload_in} instruction pattern
4212@cindex @code{reload_out} instruction pattern
4213@item @samp{reload_in@var{m}}
4214@itemx @samp{reload_out@var{m}}
8a99f6f9
R
4215These named patterns have been obsoleted by the target hook
4216@code{secondary_reload}.
4217
03dda8e3
RK
4218Like @samp{mov@var{m}}, but used when a scratch register is required to
4219move between operand 0 and operand 1. Operand 2 describes the scratch
4220register. See the discussion of the @code{SECONDARY_RELOAD_CLASS}
4221macro in @pxref{Register Classes}.
4222
d989f648 4223There are special restrictions on the form of the @code{match_operand}s
f282ffb3 4224used in these patterns. First, only the predicate for the reload
560dbedd
RH
4225operand is examined, i.e., @code{reload_in} examines operand 1, but not
4226the predicates for operand 0 or 2. Second, there may be only one
d989f648
RH
4227alternative in the constraints. Third, only a single register class
4228letter may be used for the constraint; subsequent constraint letters
4229are ignored. As a special exception, an empty constraint string
4230matches the @code{ALL_REGS} register class. This may relieve ports
4231of the burden of defining an @code{ALL_REGS} constraint letter just
4232for these patterns.
4233
03dda8e3
RK
4234@cindex @code{movstrict@var{m}} instruction pattern
4235@item @samp{movstrict@var{m}}
4236Like @samp{mov@var{m}} except that if operand 0 is a @code{subreg}
4237with mode @var{m} of a register whose natural mode is wider,
4238the @samp{movstrict@var{m}} instruction is guaranteed not to alter
4239any of the register except the part which belongs to mode @var{m}.
4240
1e0598e2
RH
4241@cindex @code{movmisalign@var{m}} instruction pattern
4242@item @samp{movmisalign@var{m}}
4243This variant of a move pattern is designed to load or store a value
4244from a memory address that is not naturally aligned for its mode.
4245For a store, the memory will be in operand 0; for a load, the memory
4246will be in operand 1. The other operand is guaranteed not to be a
4247memory, so that it's easy to tell whether this is a load or store.
4248
4249This pattern is used by the autovectorizer, and when expanding a
4250@code{MISALIGNED_INDIRECT_REF} expression.
4251
03dda8e3
RK
4252@cindex @code{load_multiple} instruction pattern
4253@item @samp{load_multiple}
4254Load several consecutive memory locations into consecutive registers.
4255Operand 0 is the first of the consecutive registers, operand 1
4256is the first memory location, and operand 2 is a constant: the
4257number of consecutive registers.
4258
4259Define this only if the target machine really has such an instruction;
4260do not define this if the most efficient way of loading consecutive
4261registers from memory is to do them one at a time.
4262
4263On some machines, there are restrictions as to which consecutive
4264registers can be stored into memory, such as particular starting or
4265ending register numbers or only a range of valid counts. For those
4266machines, use a @code{define_expand} (@pxref{Expander Definitions})
4267and make the pattern fail if the restrictions are not met.
4268
4269Write the generated insn as a @code{parallel} with elements being a
4270@code{set} of one register from the appropriate memory location (you may
4271also need @code{use} or @code{clobber} elements). Use a
4272@code{match_parallel} (@pxref{RTL Template}) to recognize the insn. See
c9693e96 4273@file{rs6000.md} for examples of the use of this insn pattern.
03dda8e3
RK
4274
4275@cindex @samp{store_multiple} instruction pattern
4276@item @samp{store_multiple}
4277Similar to @samp{load_multiple}, but store several consecutive registers
4278into consecutive memory locations. Operand 0 is the first of the
4279consecutive memory locations, operand 1 is the first register, and
4280operand 2 is a constant: the number of consecutive registers.
4281
272c6793
RS
4282@cindex @code{vec_load_lanes@var{m}@var{n}} instruction pattern
4283@item @samp{vec_load_lanes@var{m}@var{n}}
4284Perform an interleaved load of several vectors from memory operand 1
4285into register operand 0. Both operands have mode @var{m}. The register
4286operand is viewed as holding consecutive vectors of mode @var{n},
4287while the memory operand is a flat array that contains the same number
4288of elements. The operation is equivalent to:
4289
4290@smallexample
4291int c = GET_MODE_SIZE (@var{m}) / GET_MODE_SIZE (@var{n});
4292for (j = 0; j < GET_MODE_NUNITS (@var{n}); j++)
4293 for (i = 0; i < c; i++)
4294 operand0[i][j] = operand1[j * c + i];
4295@end smallexample
4296
4297For example, @samp{vec_load_lanestiv4hi} loads 8 16-bit values
4298from memory into a register of mode @samp{TI}@. The register
4299contains two consecutive vectors of mode @samp{V4HI}@.
4300
4301This pattern can only be used if:
4302@smallexample
4303TARGET_ARRAY_MODE_SUPPORTED_P (@var{n}, @var{c})
4304@end smallexample
4305is true. GCC assumes that, if a target supports this kind of
4306instruction for some mode @var{n}, it also supports unaligned
4307loads for vectors of mode @var{n}.
4308
4309@cindex @code{vec_store_lanes@var{m}@var{n}} instruction pattern
4310@item @samp{vec_store_lanes@var{m}@var{n}}
4311Equivalent to @samp{vec_load_lanes@var{m}@var{n}}, with the memory
4312and register operands reversed. That is, the instruction is
4313equivalent to:
4314
4315@smallexample
4316int c = GET_MODE_SIZE (@var{m}) / GET_MODE_SIZE (@var{n});
4317for (j = 0; j < GET_MODE_NUNITS (@var{n}); j++)
4318 for (i = 0; i < c; i++)
4319 operand0[j * c + i] = operand1[i][j];
4320@end smallexample
4321
4322for a memory operand 0 and register operand 1.
4323
ef1140a9
JH
4324@cindex @code{vec_set@var{m}} instruction pattern
4325@item @samp{vec_set@var{m}}
4326Set given field in the vector value. Operand 0 is the vector to modify,
4327operand 1 is new value of field and operand 2 specify the field index.
4328
4329@cindex @code{vec_extract@var{m}} instruction pattern
4330@item @samp{vec_extract@var{m}}
4331Extract given field from the vector value. Operand 1 is the vector, operand 2
4332specify field index and operand 0 place to store value into.
4333
4334@cindex @code{vec_init@var{m}} instruction pattern
4335@item @samp{vec_init@var{m}}
425a2bde 4336Initialize the vector to given values. Operand 0 is the vector to initialize
ef1140a9
JH
4337and operand 1 is parallel containing values for individual fields.
4338
e9e1d143
RG
4339@cindex @code{vcond@var{m}@var{n}} instruction pattern
4340@item @samp{vcond@var{m}@var{n}}
4341Output a conditional vector move. Operand 0 is the destination to
4342receive a combination of operand 1 and operand 2, which are of mode @var{m},
4343dependent on the outcome of the predicate in operand 3 which is a
4344vector comparison with operands of mode @var{n} in operands 4 and 5. The
4345modes @var{m} and @var{n} should have the same size. Operand 0
4346will be set to the value @var{op1} & @var{msk} | @var{op2} & ~@var{msk}
4347where @var{msk} is computed by element-wise evaluation of the vector
4348comparison with a truth value of all-ones and a false value of all-zeros.
4349
2205ed25
RH
4350@cindex @code{vec_perm@var{m}} instruction pattern
4351@item @samp{vec_perm@var{m}}
4352Output a (variable) vector permutation. Operand 0 is the destination
4353to receive elements from operand 1 and operand 2, which are of mode
4354@var{m}. Operand 3 is the @dfn{selector}. It is an integral mode
4355vector of the same width and number of elements as mode @var{m}.
4356
4357The input elements are numbered from 0 in operand 1 through
4358@math{2*@var{N}-1} in operand 2. The elements of the selector must
4359be computed modulo @math{2*@var{N}}. Note that if
4360@code{rtx_equal_p(operand1, operand2)}, this can be implemented
4361with just operand 1 and selector elements modulo @var{N}.
4362
d7943c8b
RH
4363In order to make things easy for a number of targets, if there is no
4364@samp{vec_perm} pattern for mode @var{m}, but there is for mode @var{q}
4365where @var{q} is a vector of @code{QImode} of the same width as @var{m},
4366the middle-end will lower the mode @var{m} @code{VEC_PERM_EXPR} to
4367mode @var{q}.
4368
82675d94 4369@cindex @code{vec_perm_const@var{m}} instruction pattern
2205ed25
RH
4370@item @samp{vec_perm_const@var{m}}
4371Like @samp{vec_perm} except that the permutation is a compile-time
4372constant. That is, operand 3, the @dfn{selector}, is a @code{CONST_VECTOR}.
4373
4374Some targets cannot perform a permutation with a variable selector,
4375but can efficiently perform a constant permutation. Further, the
4376target hook @code{vec_perm_ok} is queried to determine if the
4377specific constant permutation is available efficiently; the named
4378pattern is never expanded without @code{vec_perm_ok} returning true.
4379
4380There is no need for a target to supply both @samp{vec_perm@var{m}}
4381and @samp{vec_perm_const@var{m}} if the former can trivially implement
4382the operation with, say, the vector constant loaded into a register.
4383
759915ca
EC
4384@cindex @code{push@var{m}1} instruction pattern
4385@item @samp{push@var{m}1}
299c5111 4386Output a push instruction. Operand 0 is value to push. Used only when
38f4324c
JH
4387@code{PUSH_ROUNDING} is defined. For historical reason, this pattern may be
4388missing and in such case an @code{mov} expander is used instead, with a
6e9aac46 4389@code{MEM} expression forming the push operation. The @code{mov} expander
38f4324c
JH
4390method is deprecated.
4391
03dda8e3
RK
4392@cindex @code{add@var{m}3} instruction pattern
4393@item @samp{add@var{m}3}
4394Add operand 2 and operand 1, storing the result in operand 0. All operands
4395must have mode @var{m}. This can be used even on two-address machines, by
4396means of constraints requiring operands 1 and 0 to be the same location.
4397
0f996086
CF
4398@cindex @code{ssadd@var{m}3} instruction pattern
4399@cindex @code{usadd@var{m}3} instruction pattern
03dda8e3 4400@cindex @code{sub@var{m}3} instruction pattern
0f996086
CF
4401@cindex @code{sssub@var{m}3} instruction pattern
4402@cindex @code{ussub@var{m}3} instruction pattern
03dda8e3 4403@cindex @code{mul@var{m}3} instruction pattern
0f996086
CF
4404@cindex @code{ssmul@var{m}3} instruction pattern
4405@cindex @code{usmul@var{m}3} instruction pattern
03dda8e3 4406@cindex @code{div@var{m}3} instruction pattern
0f996086 4407@cindex @code{ssdiv@var{m}3} instruction pattern
03dda8e3 4408@cindex @code{udiv@var{m}3} instruction pattern
0f996086 4409@cindex @code{usdiv@var{m}3} instruction pattern
03dda8e3
RK
4410@cindex @code{mod@var{m}3} instruction pattern
4411@cindex @code{umod@var{m}3} instruction pattern
03dda8e3
RK
4412@cindex @code{umin@var{m}3} instruction pattern
4413@cindex @code{umax@var{m}3} instruction pattern
4414@cindex @code{and@var{m}3} instruction pattern
4415@cindex @code{ior@var{m}3} instruction pattern
4416@cindex @code{xor@var{m}3} instruction pattern
0f996086
CF
4417@item @samp{ssadd@var{m}3}, @samp{usadd@var{m}3}
4418@item @samp{sub@var{m}3}, @samp{sssub@var{m}3}, @samp{ussub@var{m}3}
4419@item @samp{mul@var{m}3}, @samp{ssmul@var{m}3}, @samp{usmul@var{m}3}
4420@itemx @samp{div@var{m}3}, @samp{ssdiv@var{m}3}
4421@itemx @samp{udiv@var{m}3}, @samp{usdiv@var{m}3}
7ae4d8d4
RH
4422@itemx @samp{mod@var{m}3}, @samp{umod@var{m}3}
4423@itemx @samp{umin@var{m}3}, @samp{umax@var{m}3}
03dda8e3
RK
4424@itemx @samp{and@var{m}3}, @samp{ior@var{m}3}, @samp{xor@var{m}3}
4425Similar, for other arithmetic operations.
7ae4d8d4 4426
1b1562a5
MM
4427@cindex @code{fma@var{m}4} instruction pattern
4428@item @samp{fma@var{m}4}
4429Multiply operand 2 and operand 1, then add operand 3, storing the
d6373302
KZ
4430result in operand 0 without doing an intermediate rounding step. All
4431operands must have mode @var{m}. This pattern is used to implement
4432the @code{fma}, @code{fmaf}, and @code{fmal} builtin functions from
4433the ISO C99 standard.
1b1562a5 4434
16949072
RG
4435@cindex @code{fms@var{m}4} instruction pattern
4436@item @samp{fms@var{m}4}
4437Like @code{fma@var{m}4}, except operand 3 subtracted from the
4438product instead of added to the product. This is represented
4439in the rtl as
4440
4441@smallexample
4442(fma:@var{m} @var{op1} @var{op2} (neg:@var{m} @var{op3}))
4443@end smallexample
4444
4445@cindex @code{fnma@var{m}4} instruction pattern
4446@item @samp{fnma@var{m}4}
4447Like @code{fma@var{m}4} except that the intermediate product
4448is negated before being added to operand 3. This is represented
4449in the rtl as
4450
4451@smallexample
4452(fma:@var{m} (neg:@var{m} @var{op1}) @var{op2} @var{op3})
4453@end smallexample
4454
4455@cindex @code{fnms@var{m}4} instruction pattern
4456@item @samp{fnms@var{m}4}
4457Like @code{fms@var{m}4} except that the intermediate product
4458is negated before subtracting operand 3. This is represented
4459in the rtl as
4460
4461@smallexample
4462(fma:@var{m} (neg:@var{m} @var{op1}) @var{op2} (neg:@var{m} @var{op3}))
4463@end smallexample
4464
b71b019a
JH
4465@cindex @code{min@var{m}3} instruction pattern
4466@cindex @code{max@var{m}3} instruction pattern
7ae4d8d4
RH
4467@item @samp{smin@var{m}3}, @samp{smax@var{m}3}
4468Signed minimum and maximum operations. When used with floating point,
4469if both operands are zeros, or if either operand is @code{NaN}, then
4470it is unspecified which of the two operands is returned as the result.
03dda8e3 4471
61abee65
DN
4472@cindex @code{reduc_smin_@var{m}} instruction pattern
4473@cindex @code{reduc_smax_@var{m}} instruction pattern
4474@item @samp{reduc_smin_@var{m}}, @samp{reduc_smax_@var{m}}
4475Find the signed minimum/maximum of the elements of a vector. The vector is
759915ca
EC
4476operand 1, and the scalar result is stored in the least significant bits of
4477operand 0 (also a vector). The output and input vector should have the same
61abee65
DN
4478modes.
4479
4480@cindex @code{reduc_umin_@var{m}} instruction pattern
4481@cindex @code{reduc_umax_@var{m}} instruction pattern
4482@item @samp{reduc_umin_@var{m}}, @samp{reduc_umax_@var{m}}
4483Find the unsigned minimum/maximum of the elements of a vector. The vector is
759915ca
EC
4484operand 1, and the scalar result is stored in the least significant bits of
4485operand 0 (also a vector). The output and input vector should have the same
61abee65
DN
4486modes.
4487
4488@cindex @code{reduc_splus_@var{m}} instruction pattern
4489@item @samp{reduc_splus_@var{m}}
759915ca
EC
4490Compute the sum of the signed elements of a vector. The vector is operand 1,
4491and the scalar result is stored in the least significant bits of operand 0
61abee65
DN
4492(also a vector). The output and input vector should have the same modes.
4493
4494@cindex @code{reduc_uplus_@var{m}} instruction pattern
4495@item @samp{reduc_uplus_@var{m}}
759915ca
EC
4496Compute the sum of the unsigned elements of a vector. The vector is operand 1,
4497and the scalar result is stored in the least significant bits of operand 0
61abee65
DN
4498(also a vector). The output and input vector should have the same modes.
4499
20f06221
DN
4500@cindex @code{sdot_prod@var{m}} instruction pattern
4501@item @samp{sdot_prod@var{m}}
4502@cindex @code{udot_prod@var{m}} instruction pattern
4503@item @samp{udot_prod@var{m}}
ff2ce160
MS
4504Compute the sum of the products of two signed/unsigned elements.
4505Operand 1 and operand 2 are of the same mode. Their product, which is of a
4506wider mode, is computed and added to operand 3. Operand 3 is of a mode equal or
20f06221 4507wider than the mode of the product. The result is placed in operand 0, which
ff2ce160 4508is of the same mode as operand 3.
20f06221
DN
4509
4510@cindex @code{ssum_widen@var{m3}} instruction pattern
4511@item @samp{ssum_widen@var{m3}}
4512@cindex @code{usum_widen@var{m3}} instruction pattern
4513@item @samp{usum_widen@var{m3}}
ff2ce160 4514Operands 0 and 2 are of the same mode, which is wider than the mode of
20f06221
DN
4515operand 1. Add operand 1 to operand 2 and place the widened result in
4516operand 0. (This is used express accumulation of elements into an accumulator
4517of a wider mode.)
4518
61abee65
DN
4519@cindex @code{vec_shl_@var{m}} instruction pattern
4520@cindex @code{vec_shr_@var{m}} instruction pattern
4521@item @samp{vec_shl_@var{m}}, @samp{vec_shr_@var{m}}
4522Whole vector left/right shift in bits.
4523Operand 1 is a vector to be shifted.
759915ca 4524Operand 2 is an integer shift amount in bits.
61abee65
DN
4525Operand 0 is where the resulting shifted vector is stored.
4526The output and input vectors should have the same modes.
4527
8115817b
UB
4528@cindex @code{vec_pack_trunc_@var{m}} instruction pattern
4529@item @samp{vec_pack_trunc_@var{m}}
4530Narrow (demote) and merge the elements of two vectors. Operands 1 and 2
4531are vectors of the same mode having N integral or floating point elements
0ee2ea09 4532of size S@. Operand 0 is the resulting vector in which 2*N elements of
8115817b
UB
4533size N/2 are concatenated after narrowing them down using truncation.
4534
89d67cca
DN
4535@cindex @code{vec_pack_ssat_@var{m}} instruction pattern
4536@cindex @code{vec_pack_usat_@var{m}} instruction pattern
8115817b
UB
4537@item @samp{vec_pack_ssat_@var{m}}, @samp{vec_pack_usat_@var{m}}
4538Narrow (demote) and merge the elements of two vectors. Operands 1 and 2
4539are vectors of the same mode having N integral elements of size S.
89d67cca 4540Operand 0 is the resulting vector in which the elements of the two input
8115817b
UB
4541vectors are concatenated after narrowing them down using signed/unsigned
4542saturating arithmetic.
89d67cca 4543
d9987fb4
UB
4544@cindex @code{vec_pack_sfix_trunc_@var{m}} instruction pattern
4545@cindex @code{vec_pack_ufix_trunc_@var{m}} instruction pattern
4546@item @samp{vec_pack_sfix_trunc_@var{m}}, @samp{vec_pack_ufix_trunc_@var{m}}
4547Narrow, convert to signed/unsigned integral type and merge the elements
4548of two vectors. Operands 1 and 2 are vectors of the same mode having N
0ee2ea09 4549floating point elements of size S@. Operand 0 is the resulting vector
d9987fb4
UB
4550in which 2*N elements of size N/2 are concatenated.
4551
89d67cca
DN
4552@cindex @code{vec_unpacks_hi_@var{m}} instruction pattern
4553@cindex @code{vec_unpacks_lo_@var{m}} instruction pattern
8115817b
UB
4554@item @samp{vec_unpacks_hi_@var{m}}, @samp{vec_unpacks_lo_@var{m}}
4555Extract and widen (promote) the high/low part of a vector of signed
4556integral or floating point elements. The input vector (operand 1) has N
0ee2ea09 4557elements of size S@. Widen (promote) the high/low elements of the vector
8115817b
UB
4558using signed or floating point extension and place the resulting N/2
4559values of size 2*S in the output vector (operand 0).
4560
89d67cca
DN
4561@cindex @code{vec_unpacku_hi_@var{m}} instruction pattern
4562@cindex @code{vec_unpacku_lo_@var{m}} instruction pattern
8115817b
UB
4563@item @samp{vec_unpacku_hi_@var{m}}, @samp{vec_unpacku_lo_@var{m}}
4564Extract and widen (promote) the high/low part of a vector of unsigned
4565integral elements. The input vector (operand 1) has N elements of size S.
4566Widen (promote) the high/low elements of the vector using zero extension and
4567place the resulting N/2 values of size 2*S in the output vector (operand 0).
89d67cca 4568
d9987fb4
UB
4569@cindex @code{vec_unpacks_float_hi_@var{m}} instruction pattern
4570@cindex @code{vec_unpacks_float_lo_@var{m}} instruction pattern
4571@cindex @code{vec_unpacku_float_hi_@var{m}} instruction pattern
4572@cindex @code{vec_unpacku_float_lo_@var{m}} instruction pattern
4573@item @samp{vec_unpacks_float_hi_@var{m}}, @samp{vec_unpacks_float_lo_@var{m}}
4574@itemx @samp{vec_unpacku_float_hi_@var{m}}, @samp{vec_unpacku_float_lo_@var{m}}
4575Extract, convert to floating point type and widen the high/low part of a
4576vector of signed/unsigned integral elements. The input vector (operand 1)
0ee2ea09 4577has N elements of size S@. Convert the high/low elements of the vector using
d9987fb4
UB
4578floating point conversion and place the resulting N/2 values of size 2*S in
4579the output vector (operand 0).
4580
89d67cca 4581@cindex @code{vec_widen_umult_hi_@var{m}} instruction pattern
3f30a9a6 4582@cindex @code{vec_widen_umult_lo_@var{m}} instruction pattern
89d67cca
DN
4583@cindex @code{vec_widen_smult_hi_@var{m}} instruction pattern
4584@cindex @code{vec_widen_smult_lo_@var{m}} instruction pattern
3f30a9a6
RH
4585@cindex @code{vec_widen_umult_even_@var{m}} instruction pattern
4586@cindex @code{vec_widen_umult_odd_@var{m}} instruction pattern
4587@cindex @code{vec_widen_smult_even_@var{m}} instruction pattern
4588@cindex @code{vec_widen_smult_odd_@var{m}} instruction pattern
d9987fb4
UB
4589@item @samp{vec_widen_umult_hi_@var{m}}, @samp{vec_widen_umult_lo_@var{m}}
4590@itemx @samp{vec_widen_smult_hi_@var{m}}, @samp{vec_widen_smult_lo_@var{m}}
3f30a9a6
RH
4591@itemx @samp{vec_widen_umult_even_@var{m}}, @samp{vec_widen_umult_odd_@var{m}}
4592@itemx @samp{vec_widen_smult_even_@var{m}}, @samp{vec_widen_smult_odd_@var{m}}
8115817b 4593Signed/Unsigned widening multiplication. The two inputs (operands 1 and 2)
0ee2ea09 4594are vectors with N signed/unsigned elements of size S@. Multiply the high/low
3f30a9a6
RH
4595or even/odd elements of the two vectors, and put the N/2 products of size 2*S
4596in the output vector (operand 0).
89d67cca 4597
36ba4aae
IR
4598@cindex @code{vec_widen_ushiftl_hi_@var{m}} instruction pattern
4599@cindex @code{vec_widen_ushiftl_lo_@var{m}} instruction pattern
4600@cindex @code{vec_widen_sshiftl_hi_@var{m}} instruction pattern
4601@cindex @code{vec_widen_sshiftl_lo_@var{m}} instruction pattern
4602@item @samp{vec_widen_ushiftl_hi_@var{m}}, @samp{vec_widen_ushiftl_lo_@var{m}}
4603@itemx @samp{vec_widen_sshiftl_hi_@var{m}}, @samp{vec_widen_sshiftl_lo_@var{m}}
4604Signed/Unsigned widening shift left. The first input (operand 1) is a vector
4605with N signed/unsigned elements of size S@. Operand 2 is a constant. Shift
4606the high/low elements of operand 1, and put the N/2 results of size 2*S in the
4607output vector (operand 0).
4608
03dda8e3
RK
4609@cindex @code{mulhisi3} instruction pattern
4610@item @samp{mulhisi3}
4611Multiply operands 1 and 2, which have mode @code{HImode}, and store
4612a @code{SImode} product in operand 0.
4613
4614@cindex @code{mulqihi3} instruction pattern
4615@cindex @code{mulsidi3} instruction pattern
4616@item @samp{mulqihi3}, @samp{mulsidi3}
4617Similar widening-multiplication instructions of other widths.
4618
4619@cindex @code{umulqihi3} instruction pattern
4620@cindex @code{umulhisi3} instruction pattern
4621@cindex @code{umulsidi3} instruction pattern
4622@item @samp{umulqihi3}, @samp{umulhisi3}, @samp{umulsidi3}
4623Similar widening-multiplication instructions that do unsigned
4624multiplication.
4625
8b44057d
BS
4626@cindex @code{usmulqihi3} instruction pattern
4627@cindex @code{usmulhisi3} instruction pattern
4628@cindex @code{usmulsidi3} instruction pattern
4629@item @samp{usmulqihi3}, @samp{usmulhisi3}, @samp{usmulsidi3}
4630Similar widening-multiplication instructions that interpret the first
4631operand as unsigned and the second operand as signed, then do a signed
4632multiplication.
4633
03dda8e3 4634@cindex @code{smul@var{m}3_highpart} instruction pattern
759c58af 4635@item @samp{smul@var{m}3_highpart}
03dda8e3
RK
4636Perform a signed multiplication of operands 1 and 2, which have mode
4637@var{m}, and store the most significant half of the product in operand 0.
4638The least significant half of the product is discarded.
4639
4640@cindex @code{umul@var{m}3_highpart} instruction pattern
4641@item @samp{umul@var{m}3_highpart}
4642Similar, but the multiplication is unsigned.
4643
7f9844ca
RS
4644@cindex @code{madd@var{m}@var{n}4} instruction pattern
4645@item @samp{madd@var{m}@var{n}4}
4646Multiply operands 1 and 2, sign-extend them to mode @var{n}, add
4647operand 3, and store the result in operand 0. Operands 1 and 2
4648have mode @var{m} and operands 0 and 3 have mode @var{n}.
0f996086 4649Both modes must be integer or fixed-point modes and @var{n} must be twice
7f9844ca
RS
4650the size of @var{m}.
4651
4652In other words, @code{madd@var{m}@var{n}4} is like
4653@code{mul@var{m}@var{n}3} except that it also adds operand 3.
4654
4655These instructions are not allowed to @code{FAIL}.
4656
4657@cindex @code{umadd@var{m}@var{n}4} instruction pattern
4658@item @samp{umadd@var{m}@var{n}4}
4659Like @code{madd@var{m}@var{n}4}, but zero-extend the multiplication
4660operands instead of sign-extending them.
4661
0f996086
CF
4662@cindex @code{ssmadd@var{m}@var{n}4} instruction pattern
4663@item @samp{ssmadd@var{m}@var{n}4}
4664Like @code{madd@var{m}@var{n}4}, but all involved operations must be
4665signed-saturating.
4666
4667@cindex @code{usmadd@var{m}@var{n}4} instruction pattern
4668@item @samp{usmadd@var{m}@var{n}4}
4669Like @code{umadd@var{m}@var{n}4}, but all involved operations must be
4670unsigned-saturating.
4671
14661f36
CF
4672@cindex @code{msub@var{m}@var{n}4} instruction pattern
4673@item @samp{msub@var{m}@var{n}4}
4674Multiply operands 1 and 2, sign-extend them to mode @var{n}, subtract the
4675result from operand 3, and store the result in operand 0. Operands 1 and 2
4676have mode @var{m} and operands 0 and 3 have mode @var{n}.
0f996086 4677Both modes must be integer or fixed-point modes and @var{n} must be twice
14661f36
CF
4678the size of @var{m}.
4679
4680In other words, @code{msub@var{m}@var{n}4} is like
4681@code{mul@var{m}@var{n}3} except that it also subtracts the result
4682from operand 3.
4683
4684These instructions are not allowed to @code{FAIL}.
4685
4686@cindex @code{umsub@var{m}@var{n}4} instruction pattern
4687@item @samp{umsub@var{m}@var{n}4}
4688Like @code{msub@var{m}@var{n}4}, but zero-extend the multiplication
4689operands instead of sign-extending them.
4690
0f996086
CF
4691@cindex @code{ssmsub@var{m}@var{n}4} instruction pattern
4692@item @samp{ssmsub@var{m}@var{n}4}
4693Like @code{msub@var{m}@var{n}4}, but all involved operations must be
4694signed-saturating.
4695
4696@cindex @code{usmsub@var{m}@var{n}4} instruction pattern
4697@item @samp{usmsub@var{m}@var{n}4}
4698Like @code{umsub@var{m}@var{n}4}, but all involved operations must be
4699unsigned-saturating.
4700
03dda8e3
RK
4701@cindex @code{divmod@var{m}4} instruction pattern
4702@item @samp{divmod@var{m}4}
4703Signed division that produces both a quotient and a remainder.
4704Operand 1 is divided by operand 2 to produce a quotient stored
4705in operand 0 and a remainder stored in operand 3.
4706
4707For machines with an instruction that produces both a quotient and a
4708remainder, provide a pattern for @samp{divmod@var{m}4} but do not
4709provide patterns for @samp{div@var{m}3} and @samp{mod@var{m}3}. This
4710allows optimization in the relatively common case when both the quotient
4711and remainder are computed.
4712
4713If an instruction that just produces a quotient or just a remainder
4714exists and is more efficient than the instruction that produces both,
4715write the output routine of @samp{divmod@var{m}4} to call
4716@code{find_reg_note} and look for a @code{REG_UNUSED} note on the
4717quotient or remainder and generate the appropriate instruction.
4718
4719@cindex @code{udivmod@var{m}4} instruction pattern
4720@item @samp{udivmod@var{m}4}
4721Similar, but does unsigned division.
4722
273a2526 4723@anchor{shift patterns}
03dda8e3 4724@cindex @code{ashl@var{m}3} instruction pattern
0f996086
CF
4725@cindex @code{ssashl@var{m}3} instruction pattern
4726@cindex @code{usashl@var{m}3} instruction pattern
4727@item @samp{ashl@var{m}3}, @samp{ssashl@var{m}3}, @samp{usashl@var{m}3}
03dda8e3
RK
4728Arithmetic-shift operand 1 left by a number of bits specified by operand
47292, and store the result in operand 0. Here @var{m} is the mode of
4730operand 0 and operand 1; operand 2's mode is specified by the
4731instruction pattern, and the compiler will convert the operand to that
273a2526
RS
4732mode before generating the instruction. The meaning of out-of-range shift
4733counts can optionally be specified by @code{TARGET_SHIFT_TRUNCATION_MASK}.
71d46ca5 4734@xref{TARGET_SHIFT_TRUNCATION_MASK}. Operand 2 is always a scalar type.
03dda8e3
RK
4735
4736@cindex @code{ashr@var{m}3} instruction pattern
4737@cindex @code{lshr@var{m}3} instruction pattern
4738@cindex @code{rotl@var{m}3} instruction pattern
4739@cindex @code{rotr@var{m}3} instruction pattern
4740@item @samp{ashr@var{m}3}, @samp{lshr@var{m}3}, @samp{rotl@var{m}3}, @samp{rotr@var{m}3}
4741Other shift and rotate instructions, analogous to the
71d46ca5
MM
4742@code{ashl@var{m}3} instructions. Operand 2 is always a scalar type.
4743
4744@cindex @code{vashl@var{m}3} instruction pattern
4745@cindex @code{vashr@var{m}3} instruction pattern
4746@cindex @code{vlshr@var{m}3} instruction pattern
4747@cindex @code{vrotl@var{m}3} instruction pattern
4748@cindex @code{vrotr@var{m}3} instruction pattern
4749@item @samp{vashl@var{m}3}, @samp{vashr@var{m}3}, @samp{vlshr@var{m}3}, @samp{vrotl@var{m}3}, @samp{vrotr@var{m}3}
4750Vector shift and rotate instructions that take vectors as operand 2
4751instead of a scalar type.
03dda8e3 4752
ac868f29
EB
4753@cindex @code{bswap@var{m}2} instruction pattern
4754@item @samp{bswap@var{m}2}
4755Reverse the order of bytes of operand 1 and store the result in operand 0.
4756
03dda8e3 4757@cindex @code{neg@var{m}2} instruction pattern
0f996086
CF
4758@cindex @code{ssneg@var{m}2} instruction pattern
4759@cindex @code{usneg@var{m}2} instruction pattern
4760@item @samp{neg@var{m}2}, @samp{ssneg@var{m}2}, @samp{usneg@var{m}2}
03dda8e3
RK
4761Negate operand 1 and store the result in operand 0.
4762
4763@cindex @code{abs@var{m}2} instruction pattern
4764@item @samp{abs@var{m}2}
4765Store the absolute value of operand 1 into operand 0.
4766
4767@cindex @code{sqrt@var{m}2} instruction pattern
4768@item @samp{sqrt@var{m}2}
4769Store the square root of operand 1 into operand 0.
4770
4771The @code{sqrt} built-in function of C always uses the mode which
e7b489c8
RS
4772corresponds to the C data type @code{double} and the @code{sqrtf}
4773built-in function uses the mode which corresponds to the C data
4774type @code{float}.
4775
17b98269
UB
4776@cindex @code{fmod@var{m}3} instruction pattern
4777@item @samp{fmod@var{m}3}
4778Store the remainder of dividing operand 1 by operand 2 into
4779operand 0, rounded towards zero to an integer.
4780
4781The @code{fmod} built-in function of C always uses the mode which
4782corresponds to the C data type @code{double} and the @code{fmodf}
4783built-in function uses the mode which corresponds to the C data
4784type @code{float}.
4785
4786@cindex @code{remainder@var{m}3} instruction pattern
4787@item @samp{remainder@var{m}3}
4788Store the remainder of dividing operand 1 by operand 2 into
4789operand 0, rounded to the nearest integer.
4790
4791The @code{remainder} built-in function of C always uses the mode
4792which corresponds to the C data type @code{double} and the
4793@code{remainderf} built-in function uses the mode which corresponds
4794to the C data type @code{float}.
4795
e7b489c8
RS
4796@cindex @code{cos@var{m}2} instruction pattern
4797@item @samp{cos@var{m}2}
4798Store the cosine of operand 1 into operand 0.
4799
4800The @code{cos} built-in function of C always uses the mode which
4801corresponds to the C data type @code{double} and the @code{cosf}
4802built-in function uses the mode which corresponds to the C data
4803type @code{float}.
4804
4805@cindex @code{sin@var{m}2} instruction pattern
4806@item @samp{sin@var{m}2}
4807Store the sine of operand 1 into operand 0.
4808
4809The @code{sin} built-in function of C always uses the mode which
4810corresponds to the C data type @code{double} and the @code{sinf}
4811built-in function uses the mode which corresponds to the C data
4812type @code{float}.
4813
6d1f6aff
OE
4814@cindex @code{sincos@var{m}3} instruction pattern
4815@item @samp{sincos@var{m}3}
4816Store the sine of operand 2 into operand 0 and the cosine of
4817operand 2 into operand 1.
4818
4819The @code{sin} and @code{cos} built-in functions of C always use the
4820mode which corresponds to the C data type @code{double} and the
4821@code{sinf} and @code{cosf} built-in function use the mode which
4822corresponds to the C data type @code{float}.
4823Targets that can calculate the sine and cosine simultaneously can
4824implement this pattern as opposed to implementing individual
4825@code{sin@var{m}2} and @code{cos@var{m}2} patterns. The @code{sin}
4826and @code{cos} built-in functions will then be expanded to the
4827@code{sincos@var{m}3} pattern, with one of the output values
4828left unused.
4829
e7b489c8
RS
4830@cindex @code{exp@var{m}2} instruction pattern
4831@item @samp{exp@var{m}2}
4832Store the exponential of operand 1 into operand 0.
4833
4834The @code{exp} built-in function of C always uses the mode which
4835corresponds to the C data type @code{double} and the @code{expf}
4836built-in function uses the mode which corresponds to the C data
4837type @code{float}.
4838
4839@cindex @code{log@var{m}2} instruction pattern
4840@item @samp{log@var{m}2}
4841Store the natural logarithm of operand 1 into operand 0.
4842
4843The @code{log} built-in function of C always uses the mode which
4844corresponds to the C data type @code{double} and the @code{logf}
4845built-in function uses the mode which corresponds to the C data
4846type @code{float}.
03dda8e3 4847
b5e01d4b
RS
4848@cindex @code{pow@var{m}3} instruction pattern
4849@item @samp{pow@var{m}3}
4850Store the value of operand 1 raised to the exponent operand 2
4851into operand 0.
4852
4853The @code{pow} built-in function of C always uses the mode which
4854corresponds to the C data type @code{double} and the @code{powf}
4855built-in function uses the mode which corresponds to the C data
4856type @code{float}.
4857
4858@cindex @code{atan2@var{m}3} instruction pattern
4859@item @samp{atan2@var{m}3}
4860Store the arc tangent (inverse tangent) of operand 1 divided by
4861operand 2 into operand 0, using the signs of both arguments to
4862determine the quadrant of the result.
4863
4864The @code{atan2} built-in function of C always uses the mode which
4865corresponds to the C data type @code{double} and the @code{atan2f}
4866built-in function uses the mode which corresponds to the C data
4867type @code{float}.
4868
4977bab6
ZW
4869@cindex @code{floor@var{m}2} instruction pattern
4870@item @samp{floor@var{m}2}
4871Store the largest integral value not greater than argument.
4872
4873The @code{floor} built-in function of C always uses the mode which
4874corresponds to the C data type @code{double} and the @code{floorf}
4875built-in function uses the mode which corresponds to the C data
4876type @code{float}.
4877
10553f10
UB
4878@cindex @code{btrunc@var{m}2} instruction pattern
4879@item @samp{btrunc@var{m}2}
4977bab6
ZW
4880Store the argument rounded to integer towards zero.
4881
4882The @code{trunc} built-in function of C always uses the mode which
4883corresponds to the C data type @code{double} and the @code{truncf}
4884built-in function uses the mode which corresponds to the C data
4885type @code{float}.
4886
4887@cindex @code{round@var{m}2} instruction pattern
4888@item @samp{round@var{m}2}
4889Store the argument rounded to integer away from zero.
4890
4891The @code{round} built-in function of C always uses the mode which
4892corresponds to the C data type @code{double} and the @code{roundf}
4893built-in function uses the mode which corresponds to the C data
4894type @code{float}.
4895
4896@cindex @code{ceil@var{m}2} instruction pattern
4897@item @samp{ceil@var{m}2}
4898Store the argument rounded to integer away from zero.
4899
4900The @code{ceil} built-in function of C always uses the mode which
4901corresponds to the C data type @code{double} and the @code{ceilf}
4902built-in function uses the mode which corresponds to the C data
4903type @code{float}.
4904
4905@cindex @code{nearbyint@var{m}2} instruction pattern
4906@item @samp{nearbyint@var{m}2}
4907Store the argument rounded according to the default rounding mode
4908
4909The @code{nearbyint} built-in function of C always uses the mode which
4910corresponds to the C data type @code{double} and the @code{nearbyintf}
4911built-in function uses the mode which corresponds to the C data
4912type @code{float}.
4913
10553f10
UB
4914@cindex @code{rint@var{m}2} instruction pattern
4915@item @samp{rint@var{m}2}
4916Store the argument rounded according to the default rounding mode and
4917raise the inexact exception when the result differs in value from
4918the argument
4919
4920The @code{rint} built-in function of C always uses the mode which
4921corresponds to the C data type @code{double} and the @code{rintf}
4922built-in function uses the mode which corresponds to the C data
4923type @code{float}.
4924
bb7f0423
RG
4925@cindex @code{lrint@var{m}@var{n}2}
4926@item @samp{lrint@var{m}@var{n}2}
4927Convert operand 1 (valid for floating point mode @var{m}) to fixed
4928point mode @var{n} as a signed number according to the current
4929rounding mode and store in operand 0 (which has mode @var{n}).
4930
4d81bf84 4931@cindex @code{lround@var{m}@var{n}2}
e0d4c0b3 4932@item @samp{lround@var{m}@var{n}2}
4d81bf84
RG
4933Convert operand 1 (valid for floating point mode @var{m}) to fixed
4934point mode @var{n} as a signed number rounding to nearest and away
4935from zero and store in operand 0 (which has mode @var{n}).
4936
c3a4177f 4937@cindex @code{lfloor@var{m}@var{n}2}
e0d4c0b3 4938@item @samp{lfloor@var{m}@var{n}2}
c3a4177f
RG
4939Convert operand 1 (valid for floating point mode @var{m}) to fixed
4940point mode @var{n} as a signed number rounding down and store in
4941operand 0 (which has mode @var{n}).
4942
4943@cindex @code{lceil@var{m}@var{n}2}
e0d4c0b3 4944@item @samp{lceil@var{m}@var{n}2}
c3a4177f
RG
4945Convert operand 1 (valid for floating point mode @var{m}) to fixed
4946point mode @var{n} as a signed number rounding up and store in
4947operand 0 (which has mode @var{n}).
4948
d35a40fc
DE
4949@cindex @code{copysign@var{m}3} instruction pattern
4950@item @samp{copysign@var{m}3}
4951Store a value with the magnitude of operand 1 and the sign of operand
49522 into operand 0.
4953
4954The @code{copysign} built-in function of C always uses the mode which
4955corresponds to the C data type @code{double} and the @code{copysignf}
4956built-in function uses the mode which corresponds to the C data
4957type @code{float}.
4958
03dda8e3
RK
4959@cindex @code{ffs@var{m}2} instruction pattern
4960@item @samp{ffs@var{m}2}
4961Store into operand 0 one plus the index of the least significant 1-bit
4962of operand 1. If operand 1 is zero, store zero. @var{m} is the mode
4963of operand 0; operand 1's mode is specified by the instruction
4964pattern, and the compiler will convert the operand to that mode before
4965generating the instruction.
4966
4967The @code{ffs} built-in function of C always uses the mode which
4968corresponds to the C data type @code{int}.
4969
2928cd7a
RH
4970@cindex @code{clz@var{m}2} instruction pattern
4971@item @samp{clz@var{m}2}
4972Store into operand 0 the number of leading 0-bits in @var{x}, starting
2a6627c2
JN
4973at the most significant bit position. If @var{x} is 0, the
4974@code{CLZ_DEFINED_VALUE_AT_ZERO} (@pxref{Misc}) macro defines if
4975the result is undefined or has a useful value.
4976@var{m} is the mode of operand 0; operand 1's mode is
2928cd7a
RH
4977specified by the instruction pattern, and the compiler will convert the
4978operand to that mode before generating the instruction.
4979
4980@cindex @code{ctz@var{m}2} instruction pattern
4981@item @samp{ctz@var{m}2}
4982Store into operand 0 the number of trailing 0-bits in @var{x}, starting
2a6627c2
JN
4983at the least significant bit position. If @var{x} is 0, the
4984@code{CTZ_DEFINED_VALUE_AT_ZERO} (@pxref{Misc}) macro defines if
4985the result is undefined or has a useful value.
4986@var{m} is the mode of operand 0; operand 1's mode is
2928cd7a
RH
4987specified by the instruction pattern, and the compiler will convert the
4988operand to that mode before generating the instruction.
4989
4990@cindex @code{popcount@var{m}2} instruction pattern
4991@item @samp{popcount@var{m}2}
4992Store into operand 0 the number of 1-bits in @var{x}. @var{m} is the
4993mode of operand 0; operand 1's mode is specified by the instruction
4994pattern, and the compiler will convert the operand to that mode before
4995generating the instruction.
4996
4997@cindex @code{parity@var{m}2} instruction pattern
4998@item @samp{parity@var{m}2}
8a36672b 4999Store into operand 0 the parity of @var{x}, i.e.@: the number of 1-bits
2928cd7a
RH
5000in @var{x} modulo 2. @var{m} is the mode of operand 0; operand 1's mode
5001is specified by the instruction pattern, and the compiler will convert
5002the operand to that mode before generating the instruction.
5003
03dda8e3
RK
5004@cindex @code{one_cmpl@var{m}2} instruction pattern
5005@item @samp{one_cmpl@var{m}2}
5006Store the bitwise-complement of operand 1 into operand 0.
5007
70128ad9
AO
5008@cindex @code{movmem@var{m}} instruction pattern
5009@item @samp{movmem@var{m}}
beed8fc0
AO
5010Block move instruction. The destination and source blocks of memory
5011are the first two operands, and both are @code{mem:BLK}s with an
5012address in mode @code{Pmode}.
e5e809f4 5013
03dda8e3 5014The number of bytes to move is the third operand, in mode @var{m}.
e5e809f4
JL
5015Usually, you specify @code{word_mode} for @var{m}. However, if you can
5016generate better code knowing the range of valid lengths is smaller than
5017those representable in a full word, you should provide a pattern with a
5018mode corresponding to the range of values you can handle efficiently
5019(e.g., @code{QImode} for values in the range 0--127; note we avoid numbers
5020that appear negative) and also a pattern with @code{word_mode}.
03dda8e3
RK
5021
5022The fourth operand is the known shared alignment of the source and
5023destination, in the form of a @code{const_int} rtx. Thus, if the
5024compiler knows that both source and destination are word-aligned,
5025it may provide the value 4 for this operand.
5026
079a182e
JH
5027Optional operands 5 and 6 specify expected alignment and size of block
5028respectively. The expected alignment differs from alignment in operand 4
5029in a way that the blocks are not required to be aligned according to it in
9946ca2d
RA
5030all cases. This expected alignment is also in bytes, just like operand 4.
5031Expected size, when unknown, is set to @code{(const_int -1)}.
079a182e 5032
70128ad9 5033Descriptions of multiple @code{movmem@var{m}} patterns can only be
4693911f 5034beneficial if the patterns for smaller modes have fewer restrictions
8c01d9b6 5035on their first, second and fourth operands. Note that the mode @var{m}
70128ad9 5036in @code{movmem@var{m}} does not impose any restriction on the mode of
8c01d9b6
JL
5037individually moved data units in the block.
5038
03dda8e3
RK
5039These patterns need not give special consideration to the possibility
5040that the source and destination strings might overlap.
5041
beed8fc0
AO
5042@cindex @code{movstr} instruction pattern
5043@item @samp{movstr}
5044String copy instruction, with @code{stpcpy} semantics. Operand 0 is
5045an output operand in mode @code{Pmode}. The addresses of the
5046destination and source strings are operands 1 and 2, and both are
5047@code{mem:BLK}s with addresses in mode @code{Pmode}. The execution of
5048the expansion of this pattern should store in operand 0 the address in
5049which the @code{NUL} terminator was stored in the destination string.
5050
57e84f18
AS
5051@cindex @code{setmem@var{m}} instruction pattern
5052@item @samp{setmem@var{m}}
5053Block set instruction. The destination string is the first operand,
beed8fc0 5054given as a @code{mem:BLK} whose address is in mode @code{Pmode}. The
57e84f18
AS
5055number of bytes to set is the second operand, in mode @var{m}. The value to
5056initialize the memory with is the third operand. Targets that only support the
5057clearing of memory should reject any value that is not the constant 0. See
beed8fc0 5058@samp{movmem@var{m}} for a discussion of the choice of mode.
03dda8e3 5059
57e84f18 5060The fourth operand is the known alignment of the destination, in the form
03dda8e3
RK
5061of a @code{const_int} rtx. Thus, if the compiler knows that the
5062destination is word-aligned, it may provide the value 4 for this
5063operand.
5064
079a182e
JH
5065Optional operands 5 and 6 specify expected alignment and size of block
5066respectively. The expected alignment differs from alignment in operand 4
5067in a way that the blocks are not required to be aligned according to it in
9946ca2d
RA
5068all cases. This expected alignment is also in bytes, just like operand 4.
5069Expected size, when unknown, is set to @code{(const_int -1)}.
079a182e 5070
57e84f18 5071The use for multiple @code{setmem@var{m}} is as for @code{movmem@var{m}}.
8c01d9b6 5072
40c1d5f8
AS
5073@cindex @code{cmpstrn@var{m}} instruction pattern
5074@item @samp{cmpstrn@var{m}}
358b8f01 5075String compare instruction, with five operands. Operand 0 is the output;
03dda8e3 5076it has mode @var{m}. The remaining four operands are like the operands
70128ad9 5077of @samp{movmem@var{m}}. The two memory blocks specified are compared
5cc2f4f3
KG
5078byte by byte in lexicographic order starting at the beginning of each
5079string. The instruction is not allowed to prefetch more than one byte
5080at a time since either string may end in the first byte and reading past
5081that may access an invalid page or segment and cause a fault. The
9b0f6f5e
NC
5082comparison terminates early if the fetched bytes are different or if
5083they are equal to zero. The effect of the instruction is to store a
5084value in operand 0 whose sign indicates the result of the comparison.
03dda8e3 5085
40c1d5f8
AS
5086@cindex @code{cmpstr@var{m}} instruction pattern
5087@item @samp{cmpstr@var{m}}
5088String compare instruction, without known maximum length. Operand 0 is the
5089output; it has mode @var{m}. The second and third operand are the blocks of
5090memory to be compared; both are @code{mem:BLK} with an address in mode
5091@code{Pmode}.
5092
5093The fourth operand is the known shared alignment of the source and
5094destination, in the form of a @code{const_int} rtx. Thus, if the
5095compiler knows that both source and destination are word-aligned,
5096it may provide the value 4 for this operand.
5097
5098The two memory blocks specified are compared byte by byte in lexicographic
5099order starting at the beginning of each string. The instruction is not allowed
5100to prefetch more than one byte at a time since either string may end in the
5101first byte and reading past that may access an invalid page or segment and
9b0f6f5e
NC
5102cause a fault. The comparison will terminate when the fetched bytes
5103are different or if they are equal to zero. The effect of the
5104instruction is to store a value in operand 0 whose sign indicates the
5105result of the comparison.
40c1d5f8 5106
358b8f01
JJ
5107@cindex @code{cmpmem@var{m}} instruction pattern
5108@item @samp{cmpmem@var{m}}
5109Block compare instruction, with five operands like the operands
5110of @samp{cmpstr@var{m}}. The two memory blocks specified are compared
5111byte by byte in lexicographic order starting at the beginning of each
5112block. Unlike @samp{cmpstr@var{m}} the instruction can prefetch
9b0f6f5e
NC
5113any bytes in the two memory blocks. Also unlike @samp{cmpstr@var{m}}
5114the comparison will not stop if both bytes are zero. The effect of
5115the instruction is to store a value in operand 0 whose sign indicates
5116the result of the comparison.
358b8f01 5117
03dda8e3
RK
5118@cindex @code{strlen@var{m}} instruction pattern
5119@item @samp{strlen@var{m}}
5120Compute the length of a string, with three operands.
5121Operand 0 is the result (of mode @var{m}), operand 1 is
5122a @code{mem} referring to the first character of the string,
5123operand 2 is the character to search for (normally zero),
5124and operand 3 is a constant describing the known alignment
5125of the beginning of the string.
5126
e0d4c0b3 5127@cindex @code{float@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5128@item @samp{float@var{m}@var{n}2}
5129Convert signed integer operand 1 (valid for fixed point mode @var{m}) to
5130floating point mode @var{n} and store in operand 0 (which has mode
5131@var{n}).
5132
e0d4c0b3 5133@cindex @code{floatuns@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5134@item @samp{floatuns@var{m}@var{n}2}
5135Convert unsigned integer operand 1 (valid for fixed point mode @var{m})
5136to floating point mode @var{n} and store in operand 0 (which has mode
5137@var{n}).
5138
e0d4c0b3 5139@cindex @code{fix@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5140@item @samp{fix@var{m}@var{n}2}
5141Convert operand 1 (valid for floating point mode @var{m}) to fixed
5142point mode @var{n} as a signed number and store in operand 0 (which
5143has mode @var{n}). This instruction's result is defined only when
5144the value of operand 1 is an integer.
5145
0e1d7f32
AH
5146If the machine description defines this pattern, it also needs to
5147define the @code{ftrunc} pattern.
5148
e0d4c0b3 5149@cindex @code{fixuns@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5150@item @samp{fixuns@var{m}@var{n}2}
5151Convert operand 1 (valid for floating point mode @var{m}) to fixed
5152point mode @var{n} as an unsigned number and store in operand 0 (which
5153has mode @var{n}). This instruction's result is defined only when the
5154value of operand 1 is an integer.
5155
5156@cindex @code{ftrunc@var{m}2} instruction pattern
5157@item @samp{ftrunc@var{m}2}
5158Convert operand 1 (valid for floating point mode @var{m}) to an
5159integer value, still represented in floating point mode @var{m}, and
5160store it in operand 0 (valid for floating point mode @var{m}).
5161
e0d4c0b3 5162@cindex @code{fix_trunc@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5163@item @samp{fix_trunc@var{m}@var{n}2}
5164Like @samp{fix@var{m}@var{n}2} but works for any floating point value
5165of mode @var{m} by converting the value to an integer.
5166
e0d4c0b3 5167@cindex @code{fixuns_trunc@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5168@item @samp{fixuns_trunc@var{m}@var{n}2}
5169Like @samp{fixuns@var{m}@var{n}2} but works for any floating point
5170value of mode @var{m} by converting the value to an integer.
5171
e0d4c0b3 5172@cindex @code{trunc@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5173@item @samp{trunc@var{m}@var{n}2}
5174Truncate operand 1 (valid for mode @var{m}) to mode @var{n} and
5175store in operand 0 (which has mode @var{n}). Both modes must be fixed
5176point or both floating point.
5177
e0d4c0b3 5178@cindex @code{extend@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5179@item @samp{extend@var{m}@var{n}2}
5180Sign-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
5181store in operand 0 (which has mode @var{n}). Both modes must be fixed
5182point or both floating point.
5183
e0d4c0b3 5184@cindex @code{zero_extend@var{m}@var{n}2} instruction pattern
03dda8e3
RK
5185@item @samp{zero_extend@var{m}@var{n}2}
5186Zero-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
5187store in operand 0 (which has mode @var{n}). Both modes must be fixed
5188point.
5189
e0d4c0b3 5190@cindex @code{fract@var{m}@var{n}2} instruction pattern
0f996086
CF
5191@item @samp{fract@var{m}@var{n}2}
5192Convert operand 1 of mode @var{m} to mode @var{n} and store in
5193operand 0 (which has mode @var{n}). Mode @var{m} and mode @var{n}
5194could be fixed-point to fixed-point, signed integer to fixed-point,
5195fixed-point to signed integer, floating-point to fixed-point,
5196or fixed-point to floating-point.
5197When overflows or underflows happen, the results are undefined.
5198
e0d4c0b3 5199@cindex @code{satfract@var{m}@var{n}2} instruction pattern
0f996086
CF
5200@item @samp{satfract@var{m}@var{n}2}
5201Convert operand 1 of mode @var{m} to mode @var{n} and store in
5202operand 0 (which has mode @var{n}). Mode @var{m} and mode @var{n}
5203could be fixed-point to fixed-point, signed integer to fixed-point,
5204or floating-point to fixed-point.
5205When overflows or underflows happen, the instruction saturates the
5206results to the maximum or the minimum.
5207
e0d4c0b3 5208@cindex @code{fractuns@var{m}@var{n}2} instruction pattern
0f996086
CF
5209@item @samp{fractuns@var{m}@var{n}2}
5210Convert operand 1 of mode @var{m} to mode @var{n} and store in
5211operand 0 (which has mode @var{n}). Mode @var{m} and mode @var{n}
5212could be unsigned integer to fixed-point, or
5213fixed-point to unsigned integer.
5214When overflows or underflows happen, the results are undefined.
5215
e0d4c0b3 5216@cindex @code{satfractuns@var{m}@var{n}2} instruction pattern
0f996086
CF
5217@item @samp{satfractuns@var{m}@var{n}2}
5218Convert unsigned integer operand 1 of mode @var{m} to fixed-point mode
5219@var{n} and store in operand 0 (which has mode @var{n}).
5220When overflows or underflows happen, the instruction saturates the
5221results to the maximum or the minimum.
5222
03dda8e3
RK
5223@cindex @code{extv} instruction pattern
5224@item @samp{extv}
c771326b 5225Extract a bit-field from operand 1 (a register or memory operand), where
03dda8e3
RK
5226operand 2 specifies the width in bits and operand 3 the starting bit,
5227and store it in operand 0. Operand 0 must have mode @code{word_mode}.
5228Operand 1 may have mode @code{byte_mode} or @code{word_mode}; often
5229@code{word_mode} is allowed only for registers. Operands 2 and 3 must
5230be valid for @code{word_mode}.
5231
5232The RTL generation pass generates this instruction only with constants
3ab997e8 5233for operands 2 and 3 and the constant is never zero for operand 2.
03dda8e3
RK
5234
5235The bit-field value is sign-extended to a full word integer
5236before it is stored in operand 0.
5237
5238@cindex @code{extzv} instruction pattern
5239@item @samp{extzv}
5240Like @samp{extv} except that the bit-field value is zero-extended.
5241
5242@cindex @code{insv} instruction pattern
5243@item @samp{insv}
c771326b
JM
5244Store operand 3 (which must be valid for @code{word_mode}) into a
5245bit-field in operand 0, where operand 1 specifies the width in bits and
03dda8e3
RK
5246operand 2 the starting bit. Operand 0 may have mode @code{byte_mode} or
5247@code{word_mode}; often @code{word_mode} is allowed only for registers.
5248Operands 1 and 2 must be valid for @code{word_mode}.
5249
5250The RTL generation pass generates this instruction only with constants
3ab997e8 5251for operands 1 and 2 and the constant is never zero for operand 1.
03dda8e3
RK
5252
5253@cindex @code{mov@var{mode}cc} instruction pattern
5254@item @samp{mov@var{mode}cc}
5255Conditionally move operand 2 or operand 3 into operand 0 according to the
5256comparison in operand 1. If the comparison is true, operand 2 is moved
5257into operand 0, otherwise operand 3 is moved.
5258
5259The mode of the operands being compared need not be the same as the operands
5260being moved. Some machines, sparc64 for example, have instructions that
5261conditionally move an integer value based on the floating point condition
5262codes and vice versa.
5263
5264If the machine does not have conditional move instructions, do not
5265define these patterns.
5266
068f5dea 5267@cindex @code{add@var{mode}cc} instruction pattern
4b5cc2b3 5268@item @samp{add@var{mode}cc}
068f5dea
JH
5269Similar to @samp{mov@var{mode}cc} but for conditional addition. Conditionally
5270move operand 2 or (operands 2 + operand 3) into operand 0 according to the
5285c21c 5271comparison in operand 1. If the comparison is false, operand 2 is moved into
4b5cc2b3 5272operand 0, otherwise (operand 2 + operand 3) is moved.
068f5dea 5273
f90b7a5a
PB
5274@cindex @code{cstore@var{mode}4} instruction pattern
5275@item @samp{cstore@var{mode}4}
5276Store zero or nonzero in operand 0 according to whether a comparison
5277is true. Operand 1 is a comparison operator. Operand 2 and operand 3
5278are the first and second operand of the comparison, respectively.
5279You specify the mode that operand 0 must have when you write the
5280@code{match_operand} expression. The compiler automatically sees which
5281mode you have used and supplies an operand of that mode.
03dda8e3
RK
5282
5283The value stored for a true condition must have 1 as its low bit, or
5284else must be negative. Otherwise the instruction is not suitable and
5285you should omit it from the machine description. You describe to the
5286compiler exactly which value is stored by defining the macro
5287@code{STORE_FLAG_VALUE} (@pxref{Misc}). If a description cannot be
ac5eda13
PB
5288found that can be used for all the possible comparison operators, you
5289should pick one and use a @code{define_expand} to map all results
5290onto the one you chose.
5291
5292These operations may @code{FAIL}, but should do so only in relatively
5293uncommon cases; if they would @code{FAIL} for common cases involving
5294integer comparisons, it is best to restrict the predicates to not
5295allow these operands. Likewise if a given comparison operator will
5296always fail, independent of the operands (for floating-point modes, the
5297@code{ordered_comparison_operator} predicate is often useful in this case).
5298
5299If this pattern is omitted, the compiler will generate a conditional
5300branch---for example, it may copy a constant one to the target and branching
5301around an assignment of zero to the target---or a libcall. If the predicate
5302for operand 1 only rejects some operators, it will also try reordering the
5303operands and/or inverting the result value (e.g.@: by an exclusive OR).
5304These possibilities could be cheaper or equivalent to the instructions
5305used for the @samp{cstore@var{mode}4} pattern followed by those required
5306to convert a positive result from @code{STORE_FLAG_VALUE} to 1; in this
5307case, you can and should make operand 1's predicate reject some operators
5308in the @samp{cstore@var{mode}4} pattern, or remove the pattern altogether
5309from the machine description.
03dda8e3 5310
66c87bae
KH
5311@cindex @code{cbranch@var{mode}4} instruction pattern
5312@item @samp{cbranch@var{mode}4}
5313Conditional branch instruction combined with a compare instruction.
5314Operand 0 is a comparison operator. Operand 1 and operand 2 are the
5315first and second operands of the comparison, respectively. Operand 3
5316is a @code{label_ref} that refers to the label to jump to.
5317
d26eedb6
HPN
5318@cindex @code{jump} instruction pattern
5319@item @samp{jump}
5320A jump inside a function; an unconditional branch. Operand 0 is the
5321@code{label_ref} of the label to jump to. This pattern name is mandatory
5322on all machines.
5323
03dda8e3
RK
5324@cindex @code{call} instruction pattern
5325@item @samp{call}
5326Subroutine call instruction returning no value. Operand 0 is the
5327function to call; operand 1 is the number of bytes of arguments pushed
f5963e61
JL
5328as a @code{const_int}; operand 2 is the number of registers used as
5329operands.
03dda8e3
RK
5330
5331On most machines, operand 2 is not actually stored into the RTL
5332pattern. It is supplied for the sake of some RISC machines which need
5333to put this information into the assembler code; they can put it in
5334the RTL instead of operand 1.
5335
5336Operand 0 should be a @code{mem} RTX whose address is the address of the
5337function. Note, however, that this address can be a @code{symbol_ref}
5338expression even if it would not be a legitimate memory address on the
5339target machine. If it is also not a valid argument for a call
5340instruction, the pattern for this operation should be a
5341@code{define_expand} (@pxref{Expander Definitions}) that places the
5342address into a register and uses that register in the call instruction.
5343
5344@cindex @code{call_value} instruction pattern
5345@item @samp{call_value}
5346Subroutine call instruction returning a value. Operand 0 is the hard
5347register in which the value is returned. There are three more
5348operands, the same as the three operands of the @samp{call}
5349instruction (but with numbers increased by one).
5350
5351Subroutines that return @code{BLKmode} objects use the @samp{call}
5352insn.
5353
5354@cindex @code{call_pop} instruction pattern
5355@cindex @code{call_value_pop} instruction pattern
5356@item @samp{call_pop}, @samp{call_value_pop}
5357Similar to @samp{call} and @samp{call_value}, except used if defined and
df2a54e9 5358if @code{RETURN_POPS_ARGS} is nonzero. They should emit a @code{parallel}
03dda8e3
RK
5359that contains both the function call and a @code{set} to indicate the
5360adjustment made to the frame pointer.
5361
df2a54e9 5362For machines where @code{RETURN_POPS_ARGS} can be nonzero, the use of these
03dda8e3
RK
5363patterns increases the number of functions for which the frame pointer
5364can be eliminated, if desired.
5365
5366@cindex @code{untyped_call} instruction pattern
5367@item @samp{untyped_call}
5368Subroutine call instruction returning a value of any type. Operand 0 is
5369the function to call; operand 1 is a memory location where the result of
5370calling the function is to be stored; operand 2 is a @code{parallel}
5371expression where each element is a @code{set} expression that indicates
5372the saving of a function return value into the result block.
5373
5374This instruction pattern should be defined to support
5375@code{__builtin_apply} on machines where special instructions are needed
5376to call a subroutine with arbitrary arguments or to save the value
5377returned. This instruction pattern is required on machines that have
e979f9e8
JM
5378multiple registers that can hold a return value
5379(i.e.@: @code{FUNCTION_VALUE_REGNO_P} is true for more than one register).
03dda8e3
RK
5380
5381@cindex @code{return} instruction pattern
5382@item @samp{return}
5383Subroutine return instruction. This instruction pattern name should be
5384defined only if a single instruction can do all the work of returning
5385from a function.
5386
5387Like the @samp{mov@var{m}} patterns, this pattern is also used after the
5388RTL generation phase. In this case it is to support machines where
5389multiple instructions are usually needed to return from a function, but
5390some class of functions only requires one instruction to implement a
5391return. Normally, the applicable functions are those which do not need
5392to save any registers or allocate stack space.
5393
26898771
BS
5394It is valid for this pattern to expand to an instruction using
5395@code{simple_return} if no epilogue is required.
5396
5397@cindex @code{simple_return} instruction pattern
5398@item @samp{simple_return}
5399Subroutine return instruction. This instruction pattern name should be
5400defined only if a single instruction can do all the work of returning
5401from a function on a path where no epilogue is required. This pattern
5402is very similar to the @code{return} instruction pattern, but it is emitted
5403only by the shrink-wrapping optimization on paths where the function
5404prologue has not been executed, and a function return should occur without
5405any of the effects of the epilogue. Additional uses may be introduced on
5406paths where both the prologue and the epilogue have executed.
5407
03dda8e3
RK
5408@findex reload_completed
5409@findex leaf_function_p
5410For such machines, the condition specified in this pattern should only
df2a54e9 5411be true when @code{reload_completed} is nonzero and the function's
03dda8e3
RK
5412epilogue would only be a single instruction. For machines with register
5413windows, the routine @code{leaf_function_p} may be used to determine if
5414a register window push is required.
5415
5416Machines that have conditional return instructions should define patterns
5417such as
5418
5419@smallexample
5420(define_insn ""
5421 [(set (pc)
5422 (if_then_else (match_operator
5423 0 "comparison_operator"
5424 [(cc0) (const_int 0)])
5425 (return)
5426 (pc)))]
5427 "@var{condition}"
5428 "@dots{}")
5429@end smallexample
5430
5431where @var{condition} would normally be the same condition specified on the
5432named @samp{return} pattern.
5433
5434@cindex @code{untyped_return} instruction pattern
5435@item @samp{untyped_return}
5436Untyped subroutine return instruction. This instruction pattern should
5437be defined to support @code{__builtin_return} on machines where special
5438instructions are needed to return a value of any type.
5439
5440Operand 0 is a memory location where the result of calling a function
5441with @code{__builtin_apply} is stored; operand 1 is a @code{parallel}
5442expression where each element is a @code{set} expression that indicates
5443the restoring of a function return value from the result block.
5444
5445@cindex @code{nop} instruction pattern
5446@item @samp{nop}
5447No-op instruction. This instruction pattern name should always be defined
5448to output a no-op in assembler code. @code{(const_int 0)} will do as an
5449RTL pattern.
5450
5451@cindex @code{indirect_jump} instruction pattern
5452@item @samp{indirect_jump}
5453An instruction to jump to an address which is operand zero.
5454This pattern name is mandatory on all machines.
5455
5456@cindex @code{casesi} instruction pattern
5457@item @samp{casesi}
5458Instruction to jump through a dispatch table, including bounds checking.
5459This instruction takes five operands:
5460
5461@enumerate
5462@item
5463The index to dispatch on, which has mode @code{SImode}.
5464
5465@item
5466The lower bound for indices in the table, an integer constant.
5467
5468@item
5469The total range of indices in the table---the largest index
5470minus the smallest one (both inclusive).
5471
5472@item
5473A label that precedes the table itself.
5474
5475@item
5476A label to jump to if the index has a value outside the bounds.
03dda8e3
RK
5477@end enumerate
5478
e4ae5e77 5479The table is an @code{addr_vec} or @code{addr_diff_vec} inside of a
03dda8e3
RK
5480@code{jump_insn}. The number of elements in the table is one plus the
5481difference between the upper bound and the lower bound.
5482
5483@cindex @code{tablejump} instruction pattern
5484@item @samp{tablejump}
5485Instruction to jump to a variable address. This is a low-level
5486capability which can be used to implement a dispatch table when there
5487is no @samp{casesi} pattern.
5488
5489This pattern requires two operands: the address or offset, and a label
5490which should immediately precede the jump table. If the macro
f1f5f142
JL
5491@code{CASE_VECTOR_PC_RELATIVE} evaluates to a nonzero value then the first
5492operand is an offset which counts from the address of the table; otherwise,
5493it is an absolute address to jump to. In either case, the first operand has
03dda8e3
RK
5494mode @code{Pmode}.
5495
5496The @samp{tablejump} insn is always the last insn before the jump
5497table it uses. Its assembler code normally has no need to use the
5498second operand, but you should incorporate it in the RTL pattern so
5499that the jump optimizer will not delete the table as unreachable code.
5500
6e4fcc95
MH
5501
5502@cindex @code{decrement_and_branch_until_zero} instruction pattern
5503@item @samp{decrement_and_branch_until_zero}
5504Conditional branch instruction that decrements a register and
df2a54e9 5505jumps if the register is nonzero. Operand 0 is the register to
6e4fcc95 5506decrement and test; operand 1 is the label to jump to if the
df2a54e9 5507register is nonzero. @xref{Looping Patterns}.
6e4fcc95
MH
5508
5509This optional instruction pattern is only used by the combiner,
5510typically for loops reversed by the loop optimizer when strength
5511reduction is enabled.
5512
5513@cindex @code{doloop_end} instruction pattern
5514@item @samp{doloop_end}
5515Conditional branch instruction that decrements a register and jumps if
df2a54e9 5516the register is nonzero. This instruction takes five operands: Operand
6e4fcc95
MH
55170 is the register to decrement and test; operand 1 is the number of loop
5518iterations as a @code{const_int} or @code{const0_rtx} if this cannot be
5519determined until run-time; operand 2 is the actual or estimated maximum
5520number of iterations as a @code{const_int}; operand 3 is the number of
5521enclosed loops as a @code{const_int} (an innermost loop has a value of
2407343c
JR
55221); operand 4 is the label to jump to if the register is nonzero;
5523operand 5 is const1_rtx if the loop in entered at its top, const0_rtx
5524otherwise.
5c25e11d 5525@xref{Looping Patterns}.
6e4fcc95
MH
5526
5527This optional instruction pattern should be defined for machines with
5528low-overhead looping instructions as the loop optimizer will try to
5529modify suitable loops to utilize it. If nested low-overhead looping is
5530not supported, use a @code{define_expand} (@pxref{Expander Definitions})
5531and make the pattern fail if operand 3 is not @code{const1_rtx}.
5532Similarly, if the actual or estimated maximum number of iterations is
5533too large for this instruction, make it fail.
5534
5535@cindex @code{doloop_begin} instruction pattern
5536@item @samp{doloop_begin}
5537Companion instruction to @code{doloop_end} required for machines that
c21cd8b1
JM
5538need to perform some initialization, such as loading special registers
5539used by a low-overhead looping instruction. If initialization insns do
6e4fcc95
MH
5540not always need to be emitted, use a @code{define_expand}
5541(@pxref{Expander Definitions}) and make it fail.
5542
5543
03dda8e3
RK
5544@cindex @code{canonicalize_funcptr_for_compare} instruction pattern
5545@item @samp{canonicalize_funcptr_for_compare}
5546Canonicalize the function pointer in operand 1 and store the result
5547into operand 0.
5548
5549Operand 0 is always a @code{reg} and has mode @code{Pmode}; operand 1
5550may be a @code{reg}, @code{mem}, @code{symbol_ref}, @code{const_int}, etc
5551and also has mode @code{Pmode}.
5552
5553Canonicalization of a function pointer usually involves computing
5554the address of the function which would be called if the function
5555pointer were used in an indirect call.
5556
5557Only define this pattern if function pointers on the target machine
5558can have different values but still call the same function when
5559used in an indirect call.
5560
5561@cindex @code{save_stack_block} instruction pattern
5562@cindex @code{save_stack_function} instruction pattern
5563@cindex @code{save_stack_nonlocal} instruction pattern
5564@cindex @code{restore_stack_block} instruction pattern
5565@cindex @code{restore_stack_function} instruction pattern
5566@cindex @code{restore_stack_nonlocal} instruction pattern
5567@item @samp{save_stack_block}
5568@itemx @samp{save_stack_function}
5569@itemx @samp{save_stack_nonlocal}
5570@itemx @samp{restore_stack_block}
5571@itemx @samp{restore_stack_function}
5572@itemx @samp{restore_stack_nonlocal}
5573Most machines save and restore the stack pointer by copying it to or
5574from an object of mode @code{Pmode}. Do not define these patterns on
5575such machines.
5576
5577Some machines require special handling for stack pointer saves and
5578restores. On those machines, define the patterns corresponding to the
5579non-standard cases by using a @code{define_expand} (@pxref{Expander
5580Definitions}) that produces the required insns. The three types of
5581saves and restores are:
5582
5583@enumerate
5584@item
5585@samp{save_stack_block} saves the stack pointer at the start of a block
5586that allocates a variable-sized object, and @samp{restore_stack_block}
5587restores the stack pointer when the block is exited.
5588
5589@item
5590@samp{save_stack_function} and @samp{restore_stack_function} do a
5591similar job for the outermost block of a function and are used when the
5592function allocates variable-sized objects or calls @code{alloca}. Only
5593the epilogue uses the restored stack pointer, allowing a simpler save or
5594restore sequence on some machines.
5595
5596@item
5597@samp{save_stack_nonlocal} is used in functions that contain labels
5598branched to by nested functions. It saves the stack pointer in such a
5599way that the inner function can use @samp{restore_stack_nonlocal} to
5600restore the stack pointer. The compiler generates code to restore the
5601frame and argument pointer registers, but some machines require saving
5602and restoring additional data such as register window information or
5603stack backchains. Place insns in these patterns to save and restore any
5604such required data.
5605@end enumerate
5606
5607When saving the stack pointer, operand 0 is the save area and operand 1
73c8090f
DE
5608is the stack pointer. The mode used to allocate the save area defaults
5609to @code{Pmode} but you can override that choice by defining the
7e390c9d 5610@code{STACK_SAVEAREA_MODE} macro (@pxref{Storage Layout}). You must
73c8090f
DE
5611specify an integral mode, or @code{VOIDmode} if no save area is needed
5612for a particular type of save (either because no save is needed or
5613because a machine-specific save area can be used). Operand 0 is the
5614stack pointer and operand 1 is the save area for restore operations. If
5615@samp{save_stack_block} is defined, operand 0 must not be
5616@code{VOIDmode} since these saves can be arbitrarily nested.
03dda8e3
RK
5617
5618A save area is a @code{mem} that is at a constant offset from
5619@code{virtual_stack_vars_rtx} when the stack pointer is saved for use by
5620nonlocal gotos and a @code{reg} in the other two cases.
5621
5622@cindex @code{allocate_stack} instruction pattern
5623@item @samp{allocate_stack}
72938a4c 5624Subtract (or add if @code{STACK_GROWS_DOWNWARD} is undefined) operand 1 from
03dda8e3
RK
5625the stack pointer to create space for dynamically allocated data.
5626
72938a4c
MM
5627Store the resultant pointer to this space into operand 0. If you
5628are allocating space from the main stack, do this by emitting a
5629move insn to copy @code{virtual_stack_dynamic_rtx} to operand 0.
5630If you are allocating the space elsewhere, generate code to copy the
5631location of the space to operand 0. In the latter case, you must
956d6950 5632ensure this space gets freed when the corresponding space on the main
72938a4c
MM
5633stack is free.
5634
03dda8e3
RK
5635Do not define this pattern if all that must be done is the subtraction.
5636Some machines require other operations such as stack probes or
5637maintaining the back chain. Define this pattern to emit those
5638operations in addition to updating the stack pointer.
5639
861bb6c1
JL
5640@cindex @code{check_stack} instruction pattern
5641@item @samp{check_stack}
507d0069
EB
5642If stack checking (@pxref{Stack Checking}) cannot be done on your system by
5643probing the stack, define this pattern to perform the needed check and signal
5644an error if the stack has overflowed. The single operand is the address in
5645the stack farthest from the current stack pointer that you need to validate.
5646Normally, on platforms where this pattern is needed, you would obtain the
5647stack limit from a global or thread-specific variable or register.
d809253a 5648
7b84aac0
EB
5649@cindex @code{probe_stack_address} instruction pattern
5650@item @samp{probe_stack_address}
5651If stack checking (@pxref{Stack Checking}) can be done on your system by
5652probing the stack but without the need to actually access it, define this
5653pattern and signal an error if the stack has overflowed. The single operand
5654is the memory address in the stack that needs to be probed.
5655
d809253a
EB
5656@cindex @code{probe_stack} instruction pattern
5657@item @samp{probe_stack}
507d0069
EB
5658If stack checking (@pxref{Stack Checking}) can be done on your system by
5659probing the stack but doing it with a ``store zero'' instruction is not valid
5660or optimal, define this pattern to do the probing differently and signal an
5661error if the stack has overflowed. The single operand is the memory reference
5662in the stack that needs to be probed.
861bb6c1 5663
03dda8e3
RK
5664@cindex @code{nonlocal_goto} instruction pattern
5665@item @samp{nonlocal_goto}
5666Emit code to generate a non-local goto, e.g., a jump from one function
5667to a label in an outer function. This pattern has four arguments,
5668each representing a value to be used in the jump. The first
45bb86fd 5669argument is to be loaded into the frame pointer, the second is
03dda8e3
RK
5670the address to branch to (code to dispatch to the actual label),
5671the third is the address of a location where the stack is saved,
5672and the last is the address of the label, to be placed in the
5673location for the incoming static chain.
5674
f0523f02 5675On most machines you need not define this pattern, since GCC will
03dda8e3
RK
5676already generate the correct code, which is to load the frame pointer
5677and static chain, restore the stack (using the
5678@samp{restore_stack_nonlocal} pattern, if defined), and jump indirectly
5679to the dispatcher. You need only define this pattern if this code will
5680not work on your machine.
5681
5682@cindex @code{nonlocal_goto_receiver} instruction pattern
5683@item @samp{nonlocal_goto_receiver}
5684This pattern, if defined, contains code needed at the target of a
161d7b59 5685nonlocal goto after the code already generated by GCC@. You will not
03dda8e3
RK
5686normally need to define this pattern. A typical reason why you might
5687need this pattern is if some value, such as a pointer to a global table,
c30ddbc9 5688must be restored when the frame pointer is restored. Note that a nonlocal
89bcce1b 5689goto only occurs within a unit-of-translation, so a global table pointer
c30ddbc9
RH
5690that is shared by all functions of a given module need not be restored.
5691There are no arguments.
861bb6c1
JL
5692
5693@cindex @code{exception_receiver} instruction pattern
5694@item @samp{exception_receiver}
5695This pattern, if defined, contains code needed at the site of an
5696exception handler that isn't needed at the site of a nonlocal goto. You
5697will not normally need to define this pattern. A typical reason why you
5698might need this pattern is if some value, such as a pointer to a global
5699table, must be restored after control flow is branched to the handler of
5700an exception. There are no arguments.
c85f7c16 5701
c30ddbc9
RH
5702@cindex @code{builtin_setjmp_setup} instruction pattern
5703@item @samp{builtin_setjmp_setup}
5704This pattern, if defined, contains additional code needed to initialize
5705the @code{jmp_buf}. You will not normally need to define this pattern.
5706A typical reason why you might need this pattern is if some value, such
5707as a pointer to a global table, must be restored. Though it is
5708preferred that the pointer value be recalculated if possible (given the
5709address of a label for instance). The single argument is a pointer to
5710the @code{jmp_buf}. Note that the buffer is five words long and that
5711the first three are normally used by the generic mechanism.
5712
c85f7c16
JL
5713@cindex @code{builtin_setjmp_receiver} instruction pattern
5714@item @samp{builtin_setjmp_receiver}
e4ae5e77 5715This pattern, if defined, contains code needed at the site of a
c771326b 5716built-in setjmp that isn't needed at the site of a nonlocal goto. You
c85f7c16
JL
5717will not normally need to define this pattern. A typical reason why you
5718might need this pattern is if some value, such as a pointer to a global
c30ddbc9 5719table, must be restored. It takes one argument, which is the label
073a8998 5720to which builtin_longjmp transferred control; this pattern may be emitted
c30ddbc9
RH
5721at a small offset from that label.
5722
5723@cindex @code{builtin_longjmp} instruction pattern
5724@item @samp{builtin_longjmp}
5725This pattern, if defined, performs the entire action of the longjmp.
5726You will not normally need to define this pattern unless you also define
5727@code{builtin_setjmp_setup}. The single argument is a pointer to the
5728@code{jmp_buf}.
f69864aa 5729
52a11cbf
RH
5730@cindex @code{eh_return} instruction pattern
5731@item @samp{eh_return}
f69864aa 5732This pattern, if defined, affects the way @code{__builtin_eh_return},
52a11cbf
RH
5733and thence the call frame exception handling library routines, are
5734built. It is intended to handle non-trivial actions needed along
5735the abnormal return path.
5736
34dc173c 5737The address of the exception handler to which the function should return
daf2f129 5738is passed as operand to this pattern. It will normally need to copied by
34dc173c
UW
5739the pattern to some special register or memory location.
5740If the pattern needs to determine the location of the target call
5741frame in order to do so, it may use @code{EH_RETURN_STACKADJ_RTX},
5742if defined; it will have already been assigned.
5743
5744If this pattern is not defined, the default action will be to simply
5745copy the return address to @code{EH_RETURN_HANDLER_RTX}. Either
5746that macro or this pattern needs to be defined if call frame exception
5747handling is to be used.
0b433de6
JL
5748
5749@cindex @code{prologue} instruction pattern
17b53c33 5750@anchor{prologue instruction pattern}
0b433de6
JL
5751@item @samp{prologue}
5752This pattern, if defined, emits RTL for entry to a function. The function
b192711e 5753entry is responsible for setting up the stack frame, initializing the frame
0b433de6
JL
5754pointer register, saving callee saved registers, etc.
5755
5756Using a prologue pattern is generally preferred over defining
17b53c33 5757@code{TARGET_ASM_FUNCTION_PROLOGUE} to emit assembly code for the prologue.
0b433de6
JL
5758
5759The @code{prologue} pattern is particularly useful for targets which perform
5760instruction scheduling.
5761
12c5ffe5
EB
5762@cindex @code{window_save} instruction pattern
5763@anchor{window_save instruction pattern}
5764@item @samp{window_save}
5765This pattern, if defined, emits RTL for a register window save. It should
5766be defined if the target machine has register windows but the window events
5767are decoupled from calls to subroutines. The canonical example is the SPARC
5768architecture.
5769
0b433de6 5770@cindex @code{epilogue} instruction pattern
17b53c33 5771@anchor{epilogue instruction pattern}
0b433de6 5772@item @samp{epilogue}
396ad517 5773This pattern emits RTL for exit from a function. The function
b192711e 5774exit is responsible for deallocating the stack frame, restoring callee saved
0b433de6
JL
5775registers and emitting the return instruction.
5776
5777Using an epilogue pattern is generally preferred over defining
17b53c33 5778@code{TARGET_ASM_FUNCTION_EPILOGUE} to emit assembly code for the epilogue.
0b433de6
JL
5779
5780The @code{epilogue} pattern is particularly useful for targets which perform
5781instruction scheduling or which have delay slots for their return instruction.
5782
5783@cindex @code{sibcall_epilogue} instruction pattern
5784@item @samp{sibcall_epilogue}
5785This pattern, if defined, emits RTL for exit from a function without the final
5786branch back to the calling function. This pattern will be emitted before any
5787sibling call (aka tail call) sites.
5788
5789The @code{sibcall_epilogue} pattern must not clobber any arguments used for
5790parameter passing or any stack slots for arguments passed to the current
ebb48a4d 5791function.
a157febd
GK
5792
5793@cindex @code{trap} instruction pattern
5794@item @samp{trap}
5795This pattern, if defined, signals an error, typically by causing some
5796kind of signal to be raised. Among other places, it is used by the Java
c771326b 5797front end to signal `invalid array index' exceptions.
a157febd 5798
f90b7a5a
PB
5799@cindex @code{ctrap@var{MM}4} instruction pattern
5800@item @samp{ctrap@var{MM}4}
a157febd 5801Conditional trap instruction. Operand 0 is a piece of RTL which
f90b7a5a
PB
5802performs a comparison, and operands 1 and 2 are the arms of the
5803comparison. Operand 3 is the trap code, an integer.
a157febd 5804
f90b7a5a 5805A typical @code{ctrap} pattern looks like
a157febd
GK
5806
5807@smallexample
f90b7a5a 5808(define_insn "ctrapsi4"
ebb48a4d 5809 [(trap_if (match_operator 0 "trap_operator"
f90b7a5a 5810 [(match_operand 1 "register_operand")
73b8bfe1 5811 (match_operand 2 "immediate_operand")])
f90b7a5a 5812 (match_operand 3 "const_int_operand" "i"))]
a157febd
GK
5813 ""
5814 "@dots{}")
5815@end smallexample
5816
e83d297b
JJ
5817@cindex @code{prefetch} instruction pattern
5818@item @samp{prefetch}
5819
5820This pattern, if defined, emits code for a non-faulting data prefetch
5821instruction. Operand 0 is the address of the memory to prefetch. Operand 1
5822is a constant 1 if the prefetch is preparing for a write to the memory
5823address, or a constant 0 otherwise. Operand 2 is the expected degree of
5824temporal locality of the data and is a value between 0 and 3, inclusive; 0
5825means that the data has no temporal locality, so it need not be left in the
5826cache after the access; 3 means that the data has a high degree of temporal
5827locality and should be left in all levels of cache possible; 1 and 2 mean,
5828respectively, a low or moderate degree of temporal locality.
5829
5830Targets that do not support write prefetches or locality hints can ignore
5831the values of operands 1 and 2.
5832
b6bd3371
DE
5833@cindex @code{blockage} instruction pattern
5834@item @samp{blockage}
5835
5836This pattern defines a pseudo insn that prevents the instruction
5837scheduler from moving instructions across the boundary defined by the
5838blockage insn. Normally an UNSPEC_VOLATILE pattern.
5839
48ae6c13
RH
5840@cindex @code{memory_barrier} instruction pattern
5841@item @samp{memory_barrier}
5842
5843If the target memory model is not fully synchronous, then this pattern
5844should be defined to an instruction that orders both loads and stores
5845before the instruction with respect to loads and stores after the instruction.
5846This pattern has no operands.
5847
5848@cindex @code{sync_compare_and_swap@var{mode}} instruction pattern
5849@item @samp{sync_compare_and_swap@var{mode}}
5850
5851This pattern, if defined, emits code for an atomic compare-and-swap
5852operation. Operand 1 is the memory on which the atomic operation is
5853performed. Operand 2 is the ``old'' value to be compared against the
5854current contents of the memory location. Operand 3 is the ``new'' value
5855to store in the memory if the compare succeeds. Operand 0 is the result
915167f5
GK
5856of the operation; it should contain the contents of the memory
5857before the operation. If the compare succeeds, this should obviously be
5858a copy of operand 2.
48ae6c13
RH
5859
5860This pattern must show that both operand 0 and operand 1 are modified.
5861
915167f5
GK
5862This pattern must issue any memory barrier instructions such that all
5863memory operations before the atomic operation occur before the atomic
5864operation and all memory operations after the atomic operation occur
5865after the atomic operation.
48ae6c13 5866
4a77c72b 5867For targets where the success or failure of the compare-and-swap
f90b7a5a
PB
5868operation is available via the status flags, it is possible to
5869avoid a separate compare operation and issue the subsequent
5870branch or store-flag operation immediately after the compare-and-swap.
5871To this end, GCC will look for a @code{MODE_CC} set in the
5872output of @code{sync_compare_and_swap@var{mode}}; if the machine
5873description includes such a set, the target should also define special
5874@code{cbranchcc4} and/or @code{cstorecc4} instructions. GCC will then
5875be able to take the destination of the @code{MODE_CC} set and pass it
5876to the @code{cbranchcc4} or @code{cstorecc4} pattern as the first
5877operand of the comparison (the second will be @code{(const_int 0)}).
48ae6c13 5878
cedb4a1a
RH
5879For targets where the operating system may provide support for this
5880operation via library calls, the @code{sync_compare_and_swap_optab}
5881may be initialized to a function with the same interface as the
5882@code{__sync_val_compare_and_swap_@var{n}} built-in. If the entire
5883set of @var{__sync} builtins are supported via library calls, the
5884target can initialize all of the optabs at once with
5885@code{init_sync_libfuncs}.
5886For the purposes of C++11 @code{std::atomic::is_lock_free}, it is
5887assumed that these library calls do @emph{not} use any kind of
5888interruptable locking.
5889
48ae6c13
RH
5890@cindex @code{sync_add@var{mode}} instruction pattern
5891@cindex @code{sync_sub@var{mode}} instruction pattern
5892@cindex @code{sync_ior@var{mode}} instruction pattern
5893@cindex @code{sync_and@var{mode}} instruction pattern
5894@cindex @code{sync_xor@var{mode}} instruction pattern
5895@cindex @code{sync_nand@var{mode}} instruction pattern
5896@item @samp{sync_add@var{mode}}, @samp{sync_sub@var{mode}}
5897@itemx @samp{sync_ior@var{mode}}, @samp{sync_and@var{mode}}
5898@itemx @samp{sync_xor@var{mode}}, @samp{sync_nand@var{mode}}
5899
5900These patterns emit code for an atomic operation on memory.
5901Operand 0 is the memory on which the atomic operation is performed.
5902Operand 1 is the second operand to the binary operator.
5903
915167f5
GK
5904This pattern must issue any memory barrier instructions such that all
5905memory operations before the atomic operation occur before the atomic
5906operation and all memory operations after the atomic operation occur
5907after the atomic operation.
48ae6c13
RH
5908
5909If these patterns are not defined, the operation will be constructed
5910from a compare-and-swap operation, if defined.
5911
5912@cindex @code{sync_old_add@var{mode}} instruction pattern
5913@cindex @code{sync_old_sub@var{mode}} instruction pattern
5914@cindex @code{sync_old_ior@var{mode}} instruction pattern
5915@cindex @code{sync_old_and@var{mode}} instruction pattern
5916@cindex @code{sync_old_xor@var{mode}} instruction pattern
5917@cindex @code{sync_old_nand@var{mode}} instruction pattern
5918@item @samp{sync_old_add@var{mode}}, @samp{sync_old_sub@var{mode}}
5919@itemx @samp{sync_old_ior@var{mode}}, @samp{sync_old_and@var{mode}}
5920@itemx @samp{sync_old_xor@var{mode}}, @samp{sync_old_nand@var{mode}}
5921
c29c1030 5922These patterns emit code for an atomic operation on memory,
48ae6c13
RH
5923and return the value that the memory contained before the operation.
5924Operand 0 is the result value, operand 1 is the memory on which the
5925atomic operation is performed, and operand 2 is the second operand
5926to the binary operator.
5927
915167f5
GK
5928This pattern must issue any memory barrier instructions such that all
5929memory operations before the atomic operation occur before the atomic
5930operation and all memory operations after the atomic operation occur
5931after the atomic operation.
48ae6c13
RH
5932
5933If these patterns are not defined, the operation will be constructed
5934from a compare-and-swap operation, if defined.
5935
5936@cindex @code{sync_new_add@var{mode}} instruction pattern
5937@cindex @code{sync_new_sub@var{mode}} instruction pattern
5938@cindex @code{sync_new_ior@var{mode}} instruction pattern
5939@cindex @code{sync_new_and@var{mode}} instruction pattern
5940@cindex @code{sync_new_xor@var{mode}} instruction pattern
5941@cindex @code{sync_new_nand@var{mode}} instruction pattern
5942@item @samp{sync_new_add@var{mode}}, @samp{sync_new_sub@var{mode}}
5943@itemx @samp{sync_new_ior@var{mode}}, @samp{sync_new_and@var{mode}}
5944@itemx @samp{sync_new_xor@var{mode}}, @samp{sync_new_nand@var{mode}}
5945
5946These patterns are like their @code{sync_old_@var{op}} counterparts,
5947except that they return the value that exists in the memory location
5948after the operation, rather than before the operation.
5949
5950@cindex @code{sync_lock_test_and_set@var{mode}} instruction pattern
5951@item @samp{sync_lock_test_and_set@var{mode}}
5952
5953This pattern takes two forms, based on the capabilities of the target.
5954In either case, operand 0 is the result of the operand, operand 1 is
5955the memory on which the atomic operation is performed, and operand 2
5956is the value to set in the lock.
5957
5958In the ideal case, this operation is an atomic exchange operation, in
5959which the previous value in memory operand is copied into the result
5960operand, and the value operand is stored in the memory operand.
5961
5962For less capable targets, any value operand that is not the constant 1
5963should be rejected with @code{FAIL}. In this case the target may use
5964an atomic test-and-set bit operation. The result operand should contain
59651 if the bit was previously set and 0 if the bit was previously clear.
5966The true contents of the memory operand are implementation defined.
5967
5968This pattern must issue any memory barrier instructions such that the
915167f5
GK
5969pattern as a whole acts as an acquire barrier, that is all memory
5970operations after the pattern do not occur until the lock is acquired.
48ae6c13
RH
5971
5972If this pattern is not defined, the operation will be constructed from
5973a compare-and-swap operation, if defined.
5974
5975@cindex @code{sync_lock_release@var{mode}} instruction pattern
5976@item @samp{sync_lock_release@var{mode}}
5977
5978This pattern, if defined, releases a lock set by
5979@code{sync_lock_test_and_set@var{mode}}. Operand 0 is the memory
8635a919
GK
5980that contains the lock; operand 1 is the value to store in the lock.
5981
5982If the target doesn't implement full semantics for
5983@code{sync_lock_test_and_set@var{mode}}, any value operand which is not
5984the constant 0 should be rejected with @code{FAIL}, and the true contents
5985of the memory operand are implementation defined.
48ae6c13
RH
5986
5987This pattern must issue any memory barrier instructions such that the
915167f5
GK
5988pattern as a whole acts as a release barrier, that is the lock is
5989released only after all previous memory operations have completed.
48ae6c13
RH
5990
5991If this pattern is not defined, then a @code{memory_barrier} pattern
8635a919 5992will be emitted, followed by a store of the value to the memory operand.
48ae6c13 5993
86951993
AM
5994@cindex @code{atomic_compare_and_swap@var{mode}} instruction pattern
5995@item @samp{atomic_compare_and_swap@var{mode}}
5996This pattern, if defined, emits code for an atomic compare-and-swap
5997operation with memory model semantics. Operand 2 is the memory on which
5998the atomic operation is performed. Operand 0 is an output operand which
5999is set to true or false based on whether the operation succeeded. Operand
60001 is an output operand which is set to the contents of the memory before
6001the operation was attempted. Operand 3 is the value that is expected to
6002be in memory. Operand 4 is the value to put in memory if the expected
6003value is found there. Operand 5 is set to 1 if this compare and swap is to
6004be treated as a weak operation. Operand 6 is the memory model to be used
6005if the operation is a success. Operand 7 is the memory model to be used
6006if the operation fails.
6007
6008If memory referred to in operand 2 contains the value in operand 3, then
6009operand 4 is stored in memory pointed to by operand 2 and fencing based on
6010the memory model in operand 6 is issued.
6011
6012If memory referred to in operand 2 does not contain the value in operand 3,
6013then fencing based on the memory model in operand 7 is issued.
6014
6015If a target does not support weak compare-and-swap operations, or the port
6016elects not to implement weak operations, the argument in operand 5 can be
6017ignored. Note a strong implementation must be provided.
6018
6019If this pattern is not provided, the @code{__atomic_compare_exchange}
6020built-in functions will utilize the legacy @code{sync_compare_and_swap}
6021pattern with an @code{__ATOMIC_SEQ_CST} memory model.
6022
6023@cindex @code{atomic_load@var{mode}} instruction pattern
6024@item @samp{atomic_load@var{mode}}
6025This pattern implements an atomic load operation with memory model
6026semantics. Operand 1 is the memory address being loaded from. Operand 0
6027is the result of the load. Operand 2 is the memory model to be used for
6028the load operation.
6029
6030If not present, the @code{__atomic_load} built-in function will either
6031resort to a normal load with memory barriers, or a compare-and-swap
6032operation if a normal load would not be atomic.
6033
6034@cindex @code{atomic_store@var{mode}} instruction pattern
6035@item @samp{atomic_store@var{mode}}
6036This pattern implements an atomic store operation with memory model
6037semantics. Operand 0 is the memory address being stored to. Operand 1
6038is the value to be written. Operand 2 is the memory model to be used for
6039the operation.
6040
6041If not present, the @code{__atomic_store} built-in function will attempt to
6042perform a normal store and surround it with any required memory fences. If
6043the store would not be atomic, then an @code{__atomic_exchange} is
6044attempted with the result being ignored.
6045
6046@cindex @code{atomic_exchange@var{mode}} instruction pattern
6047@item @samp{atomic_exchange@var{mode}}
6048This pattern implements an atomic exchange operation with memory model
6049semantics. Operand 1 is the memory location the operation is performed on.
6050Operand 0 is an output operand which is set to the original value contained
6051in the memory pointed to by operand 1. Operand 2 is the value to be
6052stored. Operand 3 is the memory model to be used.
6053
6054If this pattern is not present, the built-in function
6055@code{__atomic_exchange} will attempt to preform the operation with a
6056compare and swap loop.
6057
6058@cindex @code{atomic_add@var{mode}} instruction pattern
6059@cindex @code{atomic_sub@var{mode}} instruction pattern
6060@cindex @code{atomic_or@var{mode}} instruction pattern
6061@cindex @code{atomic_and@var{mode}} instruction pattern
6062@cindex @code{atomic_xor@var{mode}} instruction pattern
6063@cindex @code{atomic_nand@var{mode}} instruction pattern
6064@item @samp{atomic_add@var{mode}}, @samp{atomic_sub@var{mode}}
6065@itemx @samp{atomic_or@var{mode}}, @samp{atomic_and@var{mode}}
6066@itemx @samp{atomic_xor@var{mode}}, @samp{atomic_nand@var{mode}}
6067
6068These patterns emit code for an atomic operation on memory with memory
6069model semantics. Operand 0 is the memory on which the atomic operation is
6070performed. Operand 1 is the second operand to the binary operator.
6071Operand 2 is the memory model to be used by the operation.
6072
6073If these patterns are not defined, attempts will be made to use legacy
c29c1030 6074@code{sync} patterns, or equivalent patterns which return a result. If
86951993
AM
6075none of these are available a compare-and-swap loop will be used.
6076
6077@cindex @code{atomic_fetch_add@var{mode}} instruction pattern
6078@cindex @code{atomic_fetch_sub@var{mode}} instruction pattern
6079@cindex @code{atomic_fetch_or@var{mode}} instruction pattern
6080@cindex @code{atomic_fetch_and@var{mode}} instruction pattern
6081@cindex @code{atomic_fetch_xor@var{mode}} instruction pattern
6082@cindex @code{atomic_fetch_nand@var{mode}} instruction pattern
6083@item @samp{atomic_fetch_add@var{mode}}, @samp{atomic_fetch_sub@var{mode}}
6084@itemx @samp{atomic_fetch_or@var{mode}}, @samp{atomic_fetch_and@var{mode}}
6085@itemx @samp{atomic_fetch_xor@var{mode}}, @samp{atomic_fetch_nand@var{mode}}
6086
6087These patterns emit code for an atomic operation on memory with memory
6088model semantics, and return the original value. Operand 0 is an output
6089operand which contains the value of the memory location before the
6090operation was performed. Operand 1 is the memory on which the atomic
6091operation is performed. Operand 2 is the second operand to the binary
6092operator. Operand 3 is the memory model to be used by the operation.
6093
6094If these patterns are not defined, attempts will be made to use legacy
6095@code{sync} patterns. If none of these are available a compare-and-swap
6096loop will be used.
6097
6098@cindex @code{atomic_add_fetch@var{mode}} instruction pattern
6099@cindex @code{atomic_sub_fetch@var{mode}} instruction pattern
6100@cindex @code{atomic_or_fetch@var{mode}} instruction pattern
6101@cindex @code{atomic_and_fetch@var{mode}} instruction pattern
6102@cindex @code{atomic_xor_fetch@var{mode}} instruction pattern
6103@cindex @code{atomic_nand_fetch@var{mode}} instruction pattern
6104@item @samp{atomic_add_fetch@var{mode}}, @samp{atomic_sub_fetch@var{mode}}
6105@itemx @samp{atomic_or_fetch@var{mode}}, @samp{atomic_and_fetch@var{mode}}
6106@itemx @samp{atomic_xor_fetch@var{mode}}, @samp{atomic_nand_fetch@var{mode}}
6107
6108These patterns emit code for an atomic operation on memory with memory
6109model semantics and return the result after the operation is performed.
6110Operand 0 is an output operand which contains the value after the
6111operation. Operand 1 is the memory on which the atomic operation is
6112performed. Operand 2 is the second operand to the binary operator.
6113Operand 3 is the memory model to be used by the operation.
6114
6115If these patterns are not defined, attempts will be made to use legacy
c29c1030 6116@code{sync} patterns, or equivalent patterns which return the result before
86951993
AM
6117the operation followed by the arithmetic operation required to produce the
6118result. If none of these are available a compare-and-swap loop will be
6119used.
6120
f8a27aa6
RH
6121@cindex @code{atomic_test_and_set} instruction pattern
6122@item @samp{atomic_test_and_set}
6123
6124This pattern emits code for @code{__builtin_atomic_test_and_set}.
6125Operand 0 is an output operand which is set to true if the previous
6126previous contents of the byte was "set", and false otherwise. Operand 1
6127is the @code{QImode} memory to be modified. Operand 2 is the memory
6128model to be used.
6129
6130The specific value that defines "set" is implementation defined, and
6131is normally based on what is performed by the native atomic test and set
6132instruction.
6133
86951993
AM
6134@cindex @code{mem_thread_fence@var{mode}} instruction pattern
6135@item @samp{mem_thread_fence@var{mode}}
6136This pattern emits code required to implement a thread fence with
6137memory model semantics. Operand 0 is the memory model to be used.
6138
6139If this pattern is not specified, all memory models except
6140@code{__ATOMIC_RELAXED} will result in issuing a @code{sync_synchronize}
6141barrier pattern.
6142
6143@cindex @code{mem_signal_fence@var{mode}} instruction pattern
6144@item @samp{mem_signal_fence@var{mode}}
6145This pattern emits code required to implement a signal fence with
6146memory model semantics. Operand 0 is the memory model to be used.
6147
6148This pattern should impact the compiler optimizers the same way that
6149mem_signal_fence does, but it does not need to issue any barrier
6150instructions.
6151
6152If this pattern is not specified, all memory models except
6153@code{__ATOMIC_RELAXED} will result in issuing a @code{sync_synchronize}
6154barrier pattern.
6155
f959607b
CLT
6156@cindex @code{get_thread_pointer@var{mode}} instruction pattern
6157@cindex @code{set_thread_pointer@var{mode}} instruction pattern
6158@item @samp{get_thread_pointer@var{mode}}
6159@itemx @samp{set_thread_pointer@var{mode}}
6160These patterns emit code that reads/sets the TLS thread pointer. Currently,
6161these are only needed if the target needs to support the
6162@code{__builtin_thread_pointer} and @code{__builtin_set_thread_pointer}
6163builtins.
6164
6165The get/set patterns have a single output/input operand respectively,
6166with @var{mode} intended to be @code{Pmode}.
6167
7d69de61
RH
6168@cindex @code{stack_protect_set} instruction pattern
6169@item @samp{stack_protect_set}
6170
643e867f 6171This pattern, if defined, moves a @code{ptr_mode} value from the memory
7d69de61
RH
6172in operand 1 to the memory in operand 0 without leaving the value in
6173a register afterward. This is to avoid leaking the value some place
759915ca 6174that an attacker might use to rewrite the stack guard slot after
7d69de61
RH
6175having clobbered it.
6176
6177If this pattern is not defined, then a plain move pattern is generated.
6178
6179@cindex @code{stack_protect_test} instruction pattern
6180@item @samp{stack_protect_test}
6181
643e867f 6182This pattern, if defined, compares a @code{ptr_mode} value from the
7d69de61 6183memory in operand 1 with the memory in operand 0 without leaving the
3aebbe5f 6184value in a register afterward and branches to operand 2 if the values
e9d3ef3b 6185were equal.
7d69de61 6186
3aebbe5f
JJ
6187If this pattern is not defined, then a plain compare pattern and
6188conditional branch pattern is used.
7d69de61 6189
677feb77
DD
6190@cindex @code{clear_cache} instruction pattern
6191@item @samp{clear_cache}
6192
6193This pattern, if defined, flushes the instruction cache for a region of
6194memory. The region is bounded to by the Pmode pointers in operand 0
6195inclusive and operand 1 exclusive.
6196
6197If this pattern is not defined, a call to the library function
6198@code{__clear_cache} is used.
6199
03dda8e3
RK
6200@end table
6201
a5249a21
HPN
6202@end ifset
6203@c Each of the following nodes are wrapped in separate
6204@c "@ifset INTERNALS" to work around memory limits for the default
6205@c configuration in older tetex distributions. Known to not work:
6206@c tetex-1.0.7, known to work: tetex-2.0.2.
6207@ifset INTERNALS
03dda8e3
RK
6208@node Pattern Ordering
6209@section When the Order of Patterns Matters
6210@cindex Pattern Ordering
6211@cindex Ordering of Patterns
6212
6213Sometimes an insn can match more than one instruction pattern. Then the
6214pattern that appears first in the machine description is the one used.
6215Therefore, more specific patterns (patterns that will match fewer things)
6216and faster instructions (those that will produce better code when they
6217do match) should usually go first in the description.
6218
6219In some cases the effect of ordering the patterns can be used to hide
6220a pattern when it is not valid. For example, the 68000 has an
6221instruction for converting a fullword to floating point and another
6222for converting a byte to floating point. An instruction converting
6223an integer to floating point could match either one. We put the
6224pattern to convert the fullword first to make sure that one will
6225be used rather than the other. (Otherwise a large integer might
6226be generated as a single-byte immediate quantity, which would not work.)
6227Instead of using this pattern ordering it would be possible to make the
6228pattern for convert-a-byte smart enough to deal properly with any
6229constant value.
6230
a5249a21
HPN
6231@end ifset
6232@ifset INTERNALS
03dda8e3
RK
6233@node Dependent Patterns
6234@section Interdependence of Patterns
6235@cindex Dependent Patterns
6236@cindex Interdependence of Patterns
6237
03dda8e3
RK
6238In some cases machines support instructions identical except for the
6239machine mode of one or more operands. For example, there may be
6240``sign-extend halfword'' and ``sign-extend byte'' instructions whose
6241patterns are
6242
3ab51846 6243@smallexample
03dda8e3
RK
6244(set (match_operand:SI 0 @dots{})
6245 (extend:SI (match_operand:HI 1 @dots{})))
6246
6247(set (match_operand:SI 0 @dots{})
6248 (extend:SI (match_operand:QI 1 @dots{})))
3ab51846 6249@end smallexample
03dda8e3
RK
6250
6251@noindent
6252Constant integers do not specify a machine mode, so an instruction to
6253extend a constant value could match either pattern. The pattern it
6254actually will match is the one that appears first in the file. For correct
6255results, this must be the one for the widest possible mode (@code{HImode},
6256here). If the pattern matches the @code{QImode} instruction, the results
6257will be incorrect if the constant value does not actually fit that mode.
6258
6259Such instructions to extend constants are rarely generated because they are
6260optimized away, but they do occasionally happen in nonoptimized
6261compilations.
6262
6263If a constraint in a pattern allows a constant, the reload pass may
6264replace a register with a constant permitted by the constraint in some
6265cases. Similarly for memory references. Because of this substitution,
6266you should not provide separate patterns for increment and decrement
6267instructions. Instead, they should be generated from the same pattern
6268that supports register-register add insns by examining the operands and
6269generating the appropriate machine instruction.
6270
a5249a21
HPN
6271@end ifset
6272@ifset INTERNALS
03dda8e3
RK
6273@node Jump Patterns
6274@section Defining Jump Instruction Patterns
6275@cindex jump instruction patterns
6276@cindex defining jump instruction patterns
6277
f90b7a5a
PB
6278GCC does not assume anything about how the machine realizes jumps.
6279The machine description should define a single pattern, usually
6280a @code{define_expand}, which expands to all the required insns.
6281
6282Usually, this would be a comparison insn to set the condition code
6283and a separate branch insn testing the condition code and branching
6284or not according to its value. For many machines, however,
6285separating compares and branches is limiting, which is why the
6286more flexible approach with one @code{define_expand} is used in GCC.
6287The machine description becomes clearer for architectures that
6288have compare-and-branch instructions but no condition code. It also
6289works better when different sets of comparison operators are supported
6290by different kinds of conditional branches (e.g. integer vs. floating-point),
6291or by conditional branches with respect to conditional stores.
6292
6293Two separate insns are always used if the machine description represents
6294a condition code register using the legacy RTL expression @code{(cc0)},
6295and on most machines that use a separate condition code register
6296(@pxref{Condition Code}). For machines that use @code{(cc0)}, in
6297fact, the set and use of the condition code must be separate and
6298adjacent@footnote{@code{note} insns can separate them, though.}, thus
6299allowing flags in @code{cc_status} to be used (@pxref{Condition Code}) and
6300so that the comparison and branch insns could be located from each other
6301by using the functions @code{prev_cc0_setter} and @code{next_cc0_user}.
6302
6303Even in this case having a single entry point for conditional branches
6304is advantageous, because it handles equally well the case where a single
6305comparison instruction records the results of both signed and unsigned
6306comparison of the given operands (with the branch insns coming in distinct
6307signed and unsigned flavors) as in the x86 or SPARC, and the case where
6308there are distinct signed and unsigned compare instructions and only
6309one set of conditional branch instructions as in the PowerPC.
03dda8e3 6310
a5249a21
HPN
6311@end ifset
6312@ifset INTERNALS
6e4fcc95
MH
6313@node Looping Patterns
6314@section Defining Looping Instruction Patterns
6315@cindex looping instruction patterns
6316@cindex defining looping instruction patterns
6317
05713b80 6318Some machines have special jump instructions that can be utilized to
6e4fcc95
MH
6319make loops more efficient. A common example is the 68000 @samp{dbra}
6320instruction which performs a decrement of a register and a branch if the
6321result was greater than zero. Other machines, in particular digital
6322signal processors (DSPs), have special block repeat instructions to
6323provide low-overhead loop support. For example, the TI TMS320C3x/C4x
6324DSPs have a block repeat instruction that loads special registers to
6325mark the top and end of a loop and to count the number of loop
6326iterations. This avoids the need for fetching and executing a
c771326b 6327@samp{dbra}-like instruction and avoids pipeline stalls associated with
6e4fcc95
MH
6328the jump.
6329
9c34dbbf
ZW
6330GCC has three special named patterns to support low overhead looping.
6331They are @samp{decrement_and_branch_until_zero}, @samp{doloop_begin},
6332and @samp{doloop_end}. The first pattern,
6e4fcc95
MH
6333@samp{decrement_and_branch_until_zero}, is not emitted during RTL
6334generation but may be emitted during the instruction combination phase.
6335This requires the assistance of the loop optimizer, using information
6336collected during strength reduction, to reverse a loop to count down to
6337zero. Some targets also require the loop optimizer to add a
6338@code{REG_NONNEG} note to indicate that the iteration count is always
6339positive. This is needed if the target performs a signed loop
6340termination test. For example, the 68000 uses a pattern similar to the
6341following for its @code{dbra} instruction:
6342
6343@smallexample
6344@group
6345(define_insn "decrement_and_branch_until_zero"
6346 [(set (pc)
6ccde948
RW
6347 (if_then_else
6348 (ge (plus:SI (match_operand:SI 0 "general_operand" "+d*am")
6349 (const_int -1))
6350 (const_int 0))
6351 (label_ref (match_operand 1 "" ""))
6352 (pc)))
6e4fcc95 6353 (set (match_dup 0)
6ccde948
RW
6354 (plus:SI (match_dup 0)
6355 (const_int -1)))]
6e4fcc95 6356 "find_reg_note (insn, REG_NONNEG, 0)"
630d3d5a 6357 "@dots{}")
6e4fcc95
MH
6358@end group
6359@end smallexample
6360
6361Note that since the insn is both a jump insn and has an output, it must
6362deal with its own reloads, hence the `m' constraints. Also note that
6363since this insn is generated by the instruction combination phase
6364combining two sequential insns together into an implicit parallel insn,
6365the iteration counter needs to be biased by the same amount as the
630d3d5a 6366decrement operation, in this case @minus{}1. Note that the following similar
6e4fcc95
MH
6367pattern will not be matched by the combiner.
6368
6369@smallexample
6370@group
6371(define_insn "decrement_and_branch_until_zero"
6372 [(set (pc)
6ccde948
RW
6373 (if_then_else
6374 (ge (match_operand:SI 0 "general_operand" "+d*am")
6375 (const_int 1))
6376 (label_ref (match_operand 1 "" ""))
6377 (pc)))
6e4fcc95 6378 (set (match_dup 0)
6ccde948
RW
6379 (plus:SI (match_dup 0)
6380 (const_int -1)))]
6e4fcc95 6381 "find_reg_note (insn, REG_NONNEG, 0)"
630d3d5a 6382 "@dots{}")
6e4fcc95
MH
6383@end group
6384@end smallexample
6385
6386The other two special looping patterns, @samp{doloop_begin} and
c21cd8b1 6387@samp{doloop_end}, are emitted by the loop optimizer for certain
6e4fcc95 6388well-behaved loops with a finite number of loop iterations using
ebb48a4d 6389information collected during strength reduction.
6e4fcc95
MH
6390
6391The @samp{doloop_end} pattern describes the actual looping instruction
6392(or the implicit looping operation) and the @samp{doloop_begin} pattern
c21cd8b1 6393is an optional companion pattern that can be used for initialization
6e4fcc95
MH
6394needed for some low-overhead looping instructions.
6395
6396Note that some machines require the actual looping instruction to be
6397emitted at the top of the loop (e.g., the TMS320C3x/C4x DSPs). Emitting
6398the true RTL for a looping instruction at the top of the loop can cause
6399problems with flow analysis. So instead, a dummy @code{doloop} insn is
6400emitted at the end of the loop. The machine dependent reorg pass checks
6401for the presence of this @code{doloop} insn and then searches back to
6402the top of the loop, where it inserts the true looping insn (provided
6403there are no instructions in the loop which would cause problems). Any
6404additional labels can be emitted at this point. In addition, if the
6405desired special iteration counter register was not allocated, this
6406machine dependent reorg pass could emit a traditional compare and jump
6407instruction pair.
6408
6409The essential difference between the
6410@samp{decrement_and_branch_until_zero} and the @samp{doloop_end}
6411patterns is that the loop optimizer allocates an additional pseudo
6412register for the latter as an iteration counter. This pseudo register
6413cannot be used within the loop (i.e., general induction variables cannot
6414be derived from it), however, in many cases the loop induction variable
6415may become redundant and removed by the flow pass.
6416
6417
a5249a21
HPN
6418@end ifset
6419@ifset INTERNALS
03dda8e3
RK
6420@node Insn Canonicalizations
6421@section Canonicalization of Instructions
6422@cindex canonicalization of instructions
6423@cindex insn canonicalization
6424
6425There are often cases where multiple RTL expressions could represent an
6426operation performed by a single machine instruction. This situation is
6427most commonly encountered with logical, branch, and multiply-accumulate
6428instructions. In such cases, the compiler attempts to convert these
6429multiple RTL expressions into a single canonical form to reduce the
6430number of insn patterns required.
6431
6432In addition to algebraic simplifications, following canonicalizations
6433are performed:
6434
6435@itemize @bullet
6436@item
6437For commutative and comparison operators, a constant is always made the
6438second operand. If a machine only supports a constant as the second
6439operand, only patterns that match a constant in the second operand need
6440be supplied.
6441
e3d6e740
GK
6442@item
6443For associative operators, a sequence of operators will always chain
6444to the left; for instance, only the left operand of an integer @code{plus}
6445can itself be a @code{plus}. @code{and}, @code{ior}, @code{xor},
6446@code{plus}, @code{mult}, @code{smin}, @code{smax}, @code{umin}, and
6447@code{umax} are associative when applied to integers, and sometimes to
6448floating-point.
6449
6450@item
03dda8e3
RK
6451@cindex @code{neg}, canonicalization of
6452@cindex @code{not}, canonicalization of
6453@cindex @code{mult}, canonicalization of
6454@cindex @code{plus}, canonicalization of
6455@cindex @code{minus}, canonicalization of
6456For these operators, if only one operand is a @code{neg}, @code{not},
6457@code{mult}, @code{plus}, or @code{minus} expression, it will be the
6458first operand.
6459
16823694
GK
6460@item
6461In combinations of @code{neg}, @code{mult}, @code{plus}, and
6462@code{minus}, the @code{neg} operations (if any) will be moved inside
daf2f129 6463the operations as far as possible. For instance,
16823694 6464@code{(neg (mult A B))} is canonicalized as @code{(mult (neg A) B)}, but
9302a061 6465@code{(plus (mult (neg B) C) A)} is canonicalized as
16823694
GK
6466@code{(minus A (mult B C))}.
6467
03dda8e3
RK
6468@cindex @code{compare}, canonicalization of
6469@item
6470For the @code{compare} operator, a constant is always the second operand
f90b7a5a 6471if the first argument is a condition code register or @code{(cc0)}.
03dda8e3 6472
f90b7a5a 6473@item
03dda8e3
RK
6474An operand of @code{neg}, @code{not}, @code{mult}, @code{plus}, or
6475@code{minus} is made the first operand under the same conditions as
6476above.
6477
921c4418
RIL
6478@item
6479@code{(ltu (plus @var{a} @var{b}) @var{b})} is converted to
6480@code{(ltu (plus @var{a} @var{b}) @var{a})}. Likewise with @code{geu} instead
6481of @code{ltu}.
6482
03dda8e3
RK
6483@item
6484@code{(minus @var{x} (const_int @var{n}))} is converted to
6485@code{(plus @var{x} (const_int @var{-n}))}.
6486
6487@item
6488Within address computations (i.e., inside @code{mem}), a left shift is
6489converted into the appropriate multiplication by a power of two.
6490
6491@cindex @code{ior}, canonicalization of
6492@cindex @code{and}, canonicalization of
6493@cindex De Morgan's law
72938a4c 6494@item
090359d6 6495De Morgan's Law is used to move bitwise negation inside a bitwise
03dda8e3
RK
6496logical-and or logical-or operation. If this results in only one
6497operand being a @code{not} expression, it will be the first one.
6498
6499A machine that has an instruction that performs a bitwise logical-and of one
6500operand with the bitwise negation of the other should specify the pattern
6501for that instruction as
6502
3ab51846 6503@smallexample
03dda8e3
RK
6504(define_insn ""
6505 [(set (match_operand:@var{m} 0 @dots{})
6506 (and:@var{m} (not:@var{m} (match_operand:@var{m} 1 @dots{}))
6507 (match_operand:@var{m} 2 @dots{})))]
6508 "@dots{}"
6509 "@dots{}")
3ab51846 6510@end smallexample
03dda8e3
RK
6511
6512@noindent
6513Similarly, a pattern for a ``NAND'' instruction should be written
6514
3ab51846 6515@smallexample
03dda8e3
RK
6516(define_insn ""
6517 [(set (match_operand:@var{m} 0 @dots{})
6518 (ior:@var{m} (not:@var{m} (match_operand:@var{m} 1 @dots{}))
6519 (not:@var{m} (match_operand:@var{m} 2 @dots{}))))]
6520 "@dots{}"
6521 "@dots{}")
3ab51846 6522@end smallexample
03dda8e3
RK
6523
6524In both cases, it is not necessary to include patterns for the many
6525logically equivalent RTL expressions.
6526
6527@cindex @code{xor}, canonicalization of
6528@item
6529The only possible RTL expressions involving both bitwise exclusive-or
6530and bitwise negation are @code{(xor:@var{m} @var{x} @var{y})}
bd819a4a 6531and @code{(not:@var{m} (xor:@var{m} @var{x} @var{y}))}.
03dda8e3
RK
6532
6533@item
6534The sum of three items, one of which is a constant, will only appear in
6535the form
6536
3ab51846 6537@smallexample
03dda8e3 6538(plus:@var{m} (plus:@var{m} @var{x} @var{y}) @var{constant})
3ab51846 6539@end smallexample
03dda8e3 6540
03dda8e3
RK
6541@cindex @code{zero_extract}, canonicalization of
6542@cindex @code{sign_extract}, canonicalization of
6543@item
6544Equality comparisons of a group of bits (usually a single bit) with zero
6545will be written using @code{zero_extract} rather than the equivalent
6546@code{and} or @code{sign_extract} operations.
6547
c536876e
AS
6548@cindex @code{mult}, canonicalization of
6549@item
6550@code{(sign_extend:@var{m1} (mult:@var{m2} (sign_extend:@var{m2} @var{x})
6551(sign_extend:@var{m2} @var{y})))} is converted to @code{(mult:@var{m1}
6552(sign_extend:@var{m1} @var{x}) (sign_extend:@var{m1} @var{y}))}, and likewise
6553for @code{zero_extend}.
6554
6555@item
6556@code{(sign_extend:@var{m1} (mult:@var{m2} (ashiftrt:@var{m2}
6557@var{x} @var{s}) (sign_extend:@var{m2} @var{y})))} is converted
6558to @code{(mult:@var{m1} (sign_extend:@var{m1} (ashiftrt:@var{m2}
6559@var{x} @var{s})) (sign_extend:@var{m1} @var{y}))}, and likewise for
6560patterns using @code{zero_extend} and @code{lshiftrt}. If the second
6561operand of @code{mult} is also a shift, then that is extended also.
6562This transformation is only applied when it can be proven that the
6563original operation had sufficient precision to prevent overflow.
6564
03dda8e3
RK
6565@end itemize
6566
cd16503a
HPN
6567Further canonicalization rules are defined in the function
6568@code{commutative_operand_precedence} in @file{gcc/rtlanal.c}.
6569
a5249a21
HPN
6570@end ifset
6571@ifset INTERNALS
03dda8e3
RK
6572@node Expander Definitions
6573@section Defining RTL Sequences for Code Generation
6574@cindex expander definitions
6575@cindex code generation RTL sequences
6576@cindex defining RTL sequences for code generation
6577
6578On some target machines, some standard pattern names for RTL generation
6579cannot be handled with single insn, but a sequence of RTL insns can
6580represent them. For these target machines, you can write a
161d7b59 6581@code{define_expand} to specify how to generate the sequence of RTL@.
03dda8e3
RK
6582
6583@findex define_expand
6584A @code{define_expand} is an RTL expression that looks almost like a
6585@code{define_insn}; but, unlike the latter, a @code{define_expand} is used
6586only for RTL generation and it can produce more than one RTL insn.
6587
6588A @code{define_expand} RTX has four operands:
6589
6590@itemize @bullet
6591@item
6592The name. Each @code{define_expand} must have a name, since the only
6593use for it is to refer to it by name.
6594
03dda8e3 6595@item
f3a3d0d3
RH
6596The RTL template. This is a vector of RTL expressions representing
6597a sequence of separate instructions. Unlike @code{define_insn}, there
6598is no implicit surrounding @code{PARALLEL}.
03dda8e3
RK
6599
6600@item
6601The condition, a string containing a C expression. This expression is
6602used to express how the availability of this pattern depends on
f0523f02
JM
6603subclasses of target machine, selected by command-line options when GCC
6604is run. This is just like the condition of a @code{define_insn} that
03dda8e3
RK
6605has a standard name. Therefore, the condition (if present) may not
6606depend on the data in the insn being matched, but only the
6607target-machine-type flags. The compiler needs to test these conditions
6608during initialization in order to learn exactly which named instructions
6609are available in a particular run.
6610
6611@item
6612The preparation statements, a string containing zero or more C
6613statements which are to be executed before RTL code is generated from
6614the RTL template.
6615
6616Usually these statements prepare temporary registers for use as
6617internal operands in the RTL template, but they can also generate RTL
6618insns directly by calling routines such as @code{emit_insn}, etc.
6619Any such insns precede the ones that come from the RTL template.
6620@end itemize
6621
6622Every RTL insn emitted by a @code{define_expand} must match some
6623@code{define_insn} in the machine description. Otherwise, the compiler
6624will crash when trying to generate code for the insn or trying to optimize
6625it.
6626
6627The RTL template, in addition to controlling generation of RTL insns,
6628also describes the operands that need to be specified when this pattern
6629is used. In particular, it gives a predicate for each operand.
6630
6631A true operand, which needs to be specified in order to generate RTL from
6632the pattern, should be described with a @code{match_operand} in its first
6633occurrence in the RTL template. This enters information on the operand's
f0523f02 6634predicate into the tables that record such things. GCC uses the
03dda8e3
RK
6635information to preload the operand into a register if that is required for
6636valid RTL code. If the operand is referred to more than once, subsequent
6637references should use @code{match_dup}.
6638
6639The RTL template may also refer to internal ``operands'' which are
6640temporary registers or labels used only within the sequence made by the
6641@code{define_expand}. Internal operands are substituted into the RTL
6642template with @code{match_dup}, never with @code{match_operand}. The
6643values of the internal operands are not passed in as arguments by the
6644compiler when it requests use of this pattern. Instead, they are computed
6645within the pattern, in the preparation statements. These statements
6646compute the values and store them into the appropriate elements of
6647@code{operands} so that @code{match_dup} can find them.
6648
6649There are two special macros defined for use in the preparation statements:
6650@code{DONE} and @code{FAIL}. Use them with a following semicolon,
6651as a statement.
6652
6653@table @code
6654
6655@findex DONE
6656@item DONE
6657Use the @code{DONE} macro to end RTL generation for the pattern. The
6658only RTL insns resulting from the pattern on this occasion will be
6659those already emitted by explicit calls to @code{emit_insn} within the
6660preparation statements; the RTL template will not be generated.
6661
6662@findex FAIL
6663@item FAIL
6664Make the pattern fail on this occasion. When a pattern fails, it means
6665that the pattern was not truly available. The calling routines in the
6666compiler will try other strategies for code generation using other patterns.
6667
6668Failure is currently supported only for binary (addition, multiplication,
c771326b 6669shifting, etc.) and bit-field (@code{extv}, @code{extzv}, and @code{insv})
03dda8e3
RK
6670operations.
6671@end table
6672
55e4756f
DD
6673If the preparation falls through (invokes neither @code{DONE} nor
6674@code{FAIL}), then the @code{define_expand} acts like a
6675@code{define_insn} in that the RTL template is used to generate the
6676insn.
6677
6678The RTL template is not used for matching, only for generating the
6679initial insn list. If the preparation statement always invokes
6680@code{DONE} or @code{FAIL}, the RTL template may be reduced to a simple
6681list of operands, such as this example:
6682
6683@smallexample
6684@group
6685(define_expand "addsi3"
6686 [(match_operand:SI 0 "register_operand" "")
6687 (match_operand:SI 1 "register_operand" "")
6688 (match_operand:SI 2 "register_operand" "")]
6689@end group
6690@group
6691 ""
6692 "
58097133 6693@{
55e4756f
DD
6694 handle_add (operands[0], operands[1], operands[2]);
6695 DONE;
58097133 6696@}")
55e4756f
DD
6697@end group
6698@end smallexample
6699
03dda8e3
RK
6700Here is an example, the definition of left-shift for the SPUR chip:
6701
6702@smallexample
6703@group
6704(define_expand "ashlsi3"
6705 [(set (match_operand:SI 0 "register_operand" "")
6706 (ashift:SI
6707@end group
6708@group
6709 (match_operand:SI 1 "register_operand" "")
6710 (match_operand:SI 2 "nonmemory_operand" "")))]
6711 ""
6712 "
6713@end group
6714@end smallexample
6715
6716@smallexample
6717@group
6718@{
6719 if (GET_CODE (operands[2]) != CONST_INT
6720 || (unsigned) INTVAL (operands[2]) > 3)
6721 FAIL;
6722@}")
6723@end group
6724@end smallexample
6725
6726@noindent
6727This example uses @code{define_expand} so that it can generate an RTL insn
6728for shifting when the shift-count is in the supported range of 0 to 3 but
6729fail in other cases where machine insns aren't available. When it fails,
6730the compiler tries another strategy using different patterns (such as, a
6731library call).
6732
6733If the compiler were able to handle nontrivial condition-strings in
6734patterns with names, then it would be possible to use a
6735@code{define_insn} in that case. Here is another case (zero-extension
6736on the 68000) which makes more use of the power of @code{define_expand}:
6737
6738@smallexample
6739(define_expand "zero_extendhisi2"
6740 [(set (match_operand:SI 0 "general_operand" "")
6741 (const_int 0))
6742 (set (strict_low_part
6743 (subreg:HI
6744 (match_dup 0)
6745 0))
6746 (match_operand:HI 1 "general_operand" ""))]
6747 ""
6748 "operands[1] = make_safe_from (operands[1], operands[0]);")
6749@end smallexample
6750
6751@noindent
6752@findex make_safe_from
6753Here two RTL insns are generated, one to clear the entire output operand
6754and the other to copy the input operand into its low half. This sequence
6755is incorrect if the input operand refers to [the old value of] the output
6756operand, so the preparation statement makes sure this isn't so. The
6757function @code{make_safe_from} copies the @code{operands[1]} into a
6758temporary register if it refers to @code{operands[0]}. It does this
6759by emitting another RTL insn.
6760
6761Finally, a third example shows the use of an internal operand.
6762Zero-extension on the SPUR chip is done by @code{and}-ing the result
6763against a halfword mask. But this mask cannot be represented by a
6764@code{const_int} because the constant value is too large to be legitimate
6765on this machine. So it must be copied into a register with
6766@code{force_reg} and then the register used in the @code{and}.
6767
6768@smallexample
6769(define_expand "zero_extendhisi2"
6770 [(set (match_operand:SI 0 "register_operand" "")
6771 (and:SI (subreg:SI
6772 (match_operand:HI 1 "register_operand" "")
6773 0)
6774 (match_dup 2)))]
6775 ""
6776 "operands[2]
3a598fbe 6777 = force_reg (SImode, GEN_INT (65535)); ")
03dda8e3
RK
6778@end smallexample
6779
f4559287 6780@emph{Note:} If the @code{define_expand} is used to serve a
c771326b 6781standard binary or unary arithmetic operation or a bit-field operation,
03dda8e3
RK
6782then the last insn it generates must not be a @code{code_label},
6783@code{barrier} or @code{note}. It must be an @code{insn},
6784@code{jump_insn} or @code{call_insn}. If you don't need a real insn
6785at the end, emit an insn to copy the result of the operation into
6786itself. Such an insn will generate no code, but it can avoid problems
bd819a4a 6787in the compiler.
03dda8e3 6788
a5249a21
HPN
6789@end ifset
6790@ifset INTERNALS
03dda8e3
RK
6791@node Insn Splitting
6792@section Defining How to Split Instructions
6793@cindex insn splitting
6794@cindex instruction splitting
6795@cindex splitting instructions
6796
fae15c93
VM
6797There are two cases where you should specify how to split a pattern
6798into multiple insns. On machines that have instructions requiring
6799delay slots (@pxref{Delay Slots}) or that have instructions whose
6800output is not available for multiple cycles (@pxref{Processor pipeline
6801description}), the compiler phases that optimize these cases need to
6802be able to move insns into one-instruction delay slots. However, some
6803insns may generate more than one machine instruction. These insns
6804cannot be placed into a delay slot.
03dda8e3
RK
6805
6806Often you can rewrite the single insn as a list of individual insns,
6807each corresponding to one machine instruction. The disadvantage of
6808doing so is that it will cause the compilation to be slower and require
6809more space. If the resulting insns are too complex, it may also
6810suppress some optimizations. The compiler splits the insn if there is a
6811reason to believe that it might improve instruction or delay slot
6812scheduling.
6813
6814The insn combiner phase also splits putative insns. If three insns are
6815merged into one insn with a complex expression that cannot be matched by
6816some @code{define_insn} pattern, the combiner phase attempts to split
6817the complex pattern into two insns that are recognized. Usually it can
6818break the complex pattern into two patterns by splitting out some
6819subexpression. However, in some other cases, such as performing an
6820addition of a large constant in two insns on a RISC machine, the way to
6821split the addition into two insns is machine-dependent.
6822
f3a3d0d3 6823@findex define_split
03dda8e3
RK
6824The @code{define_split} definition tells the compiler how to split a
6825complex insn into several simpler insns. It looks like this:
6826
6827@smallexample
6828(define_split
6829 [@var{insn-pattern}]
6830 "@var{condition}"
6831 [@var{new-insn-pattern-1}
6832 @var{new-insn-pattern-2}
6833 @dots{}]
630d3d5a 6834 "@var{preparation-statements}")
03dda8e3
RK
6835@end smallexample
6836
6837@var{insn-pattern} is a pattern that needs to be split and
6838@var{condition} is the final condition to be tested, as in a
6839@code{define_insn}. When an insn matching @var{insn-pattern} and
6840satisfying @var{condition} is found, it is replaced in the insn list
6841with the insns given by @var{new-insn-pattern-1},
6842@var{new-insn-pattern-2}, etc.
6843
630d3d5a 6844The @var{preparation-statements} are similar to those statements that
03dda8e3
RK
6845are specified for @code{define_expand} (@pxref{Expander Definitions})
6846and are executed before the new RTL is generated to prepare for the
6847generated code or emit some insns whose pattern is not fixed. Unlike
6848those in @code{define_expand}, however, these statements must not
6849generate any new pseudo-registers. Once reload has completed, they also
6850must not allocate any space in the stack frame.
6851
6852Patterns are matched against @var{insn-pattern} in two different
6853circumstances. If an insn needs to be split for delay slot scheduling
6854or insn scheduling, the insn is already known to be valid, which means
6855that it must have been matched by some @code{define_insn} and, if
df2a54e9 6856@code{reload_completed} is nonzero, is known to satisfy the constraints
03dda8e3
RK
6857of that @code{define_insn}. In that case, the new insn patterns must
6858also be insns that are matched by some @code{define_insn} and, if
df2a54e9 6859@code{reload_completed} is nonzero, must also satisfy the constraints
03dda8e3
RK
6860of those definitions.
6861
6862As an example of this usage of @code{define_split}, consider the following
6863example from @file{a29k.md}, which splits a @code{sign_extend} from
6864@code{HImode} to @code{SImode} into a pair of shift insns:
6865
6866@smallexample
6867(define_split
6868 [(set (match_operand:SI 0 "gen_reg_operand" "")
6869 (sign_extend:SI (match_operand:HI 1 "gen_reg_operand" "")))]
6870 ""
6871 [(set (match_dup 0)
6872 (ashift:SI (match_dup 1)
6873 (const_int 16)))
6874 (set (match_dup 0)
6875 (ashiftrt:SI (match_dup 0)
6876 (const_int 16)))]
6877 "
6878@{ operands[1] = gen_lowpart (SImode, operands[1]); @}")
6879@end smallexample
6880
6881When the combiner phase tries to split an insn pattern, it is always the
6882case that the pattern is @emph{not} matched by any @code{define_insn}.
6883The combiner pass first tries to split a single @code{set} expression
6884and then the same @code{set} expression inside a @code{parallel}, but
6885followed by a @code{clobber} of a pseudo-reg to use as a scratch
6886register. In these cases, the combiner expects exactly two new insn
6887patterns to be generated. It will verify that these patterns match some
6888@code{define_insn} definitions, so you need not do this test in the
6889@code{define_split} (of course, there is no point in writing a
6890@code{define_split} that will never produce insns that match).
6891
6892Here is an example of this use of @code{define_split}, taken from
6893@file{rs6000.md}:
6894
6895@smallexample
6896(define_split
6897 [(set (match_operand:SI 0 "gen_reg_operand" "")
6898 (plus:SI (match_operand:SI 1 "gen_reg_operand" "")
6899 (match_operand:SI 2 "non_add_cint_operand" "")))]
6900 ""
6901 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
6902 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
6903"
6904@{
6905 int low = INTVAL (operands[2]) & 0xffff;
6906 int high = (unsigned) INTVAL (operands[2]) >> 16;
6907
6908 if (low & 0x8000)
6909 high++, low |= 0xffff0000;
6910
3a598fbe
JL
6911 operands[3] = GEN_INT (high << 16);
6912 operands[4] = GEN_INT (low);
03dda8e3
RK
6913@}")
6914@end smallexample
6915
6916Here the predicate @code{non_add_cint_operand} matches any
6917@code{const_int} that is @emph{not} a valid operand of a single add
6918insn. The add with the smaller displacement is written so that it
6919can be substituted into the address of a subsequent operation.
6920
6921An example that uses a scratch register, from the same file, generates
6922an equality comparison of a register and a large constant:
6923
6924@smallexample
6925(define_split
6926 [(set (match_operand:CC 0 "cc_reg_operand" "")
6927 (compare:CC (match_operand:SI 1 "gen_reg_operand" "")
6928 (match_operand:SI 2 "non_short_cint_operand" "")))
6929 (clobber (match_operand:SI 3 "gen_reg_operand" ""))]
6930 "find_single_use (operands[0], insn, 0)
6931 && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
6932 || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
6933 [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
6934 (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
6935 "
6936@{
12bcfaa1 6937 /* @r{Get the constant we are comparing against, C, and see what it
03dda8e3 6938 looks like sign-extended to 16 bits. Then see what constant
12bcfaa1 6939 could be XOR'ed with C to get the sign-extended value.} */
03dda8e3
RK
6940
6941 int c = INTVAL (operands[2]);
6942 int sextc = (c << 16) >> 16;
6943 int xorv = c ^ sextc;
6944
3a598fbe
JL
6945 operands[4] = GEN_INT (xorv);
6946 operands[5] = GEN_INT (sextc);
03dda8e3
RK
6947@}")
6948@end smallexample
6949
6950To avoid confusion, don't write a single @code{define_split} that
6951accepts some insns that match some @code{define_insn} as well as some
6952insns that don't. Instead, write two separate @code{define_split}
6953definitions, one for the insns that are valid and one for the insns that
6954are not valid.
6955
6b24c259
JH
6956The splitter is allowed to split jump instructions into sequence of
6957jumps or create new jumps in while splitting non-jump instructions. As
6958the central flowgraph and branch prediction information needs to be updated,
f282ffb3 6959several restriction apply.
6b24c259
JH
6960
6961Splitting of jump instruction into sequence that over by another jump
c21cd8b1 6962instruction is always valid, as compiler expect identical behavior of new
6b24c259
JH
6963jump. When new sequence contains multiple jump instructions or new labels,
6964more assistance is needed. Splitter is required to create only unconditional
6965jumps, or simple conditional jump instructions. Additionally it must attach a
63519d23 6966@code{REG_BR_PROB} note to each conditional jump. A global variable
addd6f64 6967@code{split_branch_probability} holds the probability of the original branch in case
e4ae5e77 6968it was a simple conditional jump, @minus{}1 otherwise. To simplify
addd6f64 6969recomputing of edge frequencies, the new sequence is required to have only
6b24c259
JH
6970forward jumps to the newly created labels.
6971
fae81b38 6972@findex define_insn_and_split
c88c0d42
CP
6973For the common case where the pattern of a define_split exactly matches the
6974pattern of a define_insn, use @code{define_insn_and_split}. It looks like
6975this:
6976
6977@smallexample
6978(define_insn_and_split
6979 [@var{insn-pattern}]
6980 "@var{condition}"
6981 "@var{output-template}"
6982 "@var{split-condition}"
6983 [@var{new-insn-pattern-1}
6984 @var{new-insn-pattern-2}
6985 @dots{}]
630d3d5a 6986 "@var{preparation-statements}"
c88c0d42
CP
6987 [@var{insn-attributes}])
6988
6989@end smallexample
6990
6991@var{insn-pattern}, @var{condition}, @var{output-template}, and
6992@var{insn-attributes} are used as in @code{define_insn}. The
6993@var{new-insn-pattern} vector and the @var{preparation-statements} are used as
6994in a @code{define_split}. The @var{split-condition} is also used as in
6995@code{define_split}, with the additional behavior that if the condition starts
6996with @samp{&&}, the condition used for the split will be the constructed as a
d7d9c429 6997logical ``and'' of the split condition with the insn condition. For example,
c88c0d42
CP
6998from i386.md:
6999
7000@smallexample
7001(define_insn_and_split "zero_extendhisi2_and"
7002 [(set (match_operand:SI 0 "register_operand" "=r")
7003 (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
7004 (clobber (reg:CC 17))]
7005 "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
7006 "#"
7007 "&& reload_completed"
f282ffb3 7008 [(parallel [(set (match_dup 0)
9c34dbbf 7009 (and:SI (match_dup 0) (const_int 65535)))
6ccde948 7010 (clobber (reg:CC 17))])]
c88c0d42
CP
7011 ""
7012 [(set_attr "type" "alu1")])
7013
7014@end smallexample
7015
ebb48a4d 7016In this case, the actual split condition will be
aee96fe9 7017@samp{TARGET_ZERO_EXTEND_WITH_AND && !optimize_size && reload_completed}.
c88c0d42
CP
7018
7019The @code{define_insn_and_split} construction provides exactly the same
7020functionality as two separate @code{define_insn} and @code{define_split}
7021patterns. It exists for compactness, and as a maintenance tool to prevent
7022having to ensure the two patterns' templates match.
7023
a5249a21
HPN
7024@end ifset
7025@ifset INTERNALS
04d8aa70
AM
7026@node Including Patterns
7027@section Including Patterns in Machine Descriptions.
7028@cindex insn includes
7029
7030@findex include
7031The @code{include} pattern tells the compiler tools where to
7032look for patterns that are in files other than in the file
8a36672b 7033@file{.md}. This is used only at build time and there is no preprocessing allowed.
04d8aa70
AM
7034
7035It looks like:
7036
7037@smallexample
7038
7039(include
7040 @var{pathname})
7041@end smallexample
7042
7043For example:
7044
7045@smallexample
7046
f282ffb3 7047(include "filestuff")
04d8aa70
AM
7048
7049@end smallexample
7050
27d30956 7051Where @var{pathname} is a string that specifies the location of the file,
8a36672b 7052specifies the include file to be in @file{gcc/config/target/filestuff}. The
04d8aa70
AM
7053directory @file{gcc/config/target} is regarded as the default directory.
7054
7055
f282ffb3
JM
7056Machine descriptions may be split up into smaller more manageable subsections
7057and placed into subdirectories.
04d8aa70
AM
7058
7059By specifying:
7060
7061@smallexample
7062
f282ffb3 7063(include "BOGUS/filestuff")
04d8aa70
AM
7064
7065@end smallexample
7066
7067the include file is specified to be in @file{gcc/config/@var{target}/BOGUS/filestuff}.
7068
7069Specifying an absolute path for the include file such as;
7070@smallexample
7071
f282ffb3 7072(include "/u2/BOGUS/filestuff")
04d8aa70
AM
7073
7074@end smallexample
f282ffb3 7075is permitted but is not encouraged.
04d8aa70
AM
7076
7077@subsection RTL Generation Tool Options for Directory Search
7078@cindex directory options .md
7079@cindex options, directory search
7080@cindex search options
7081
7082The @option{-I@var{dir}} option specifies directories to search for machine descriptions.
7083For example:
7084
7085@smallexample
7086
7087genrecog -I/p1/abc/proc1 -I/p2/abcd/pro2 target.md
7088
7089@end smallexample
7090
7091
7092Add the directory @var{dir} to the head of the list of directories to be
7093searched for header files. This can be used to override a system machine definition
7094file, substituting your own version, since these directories are
7095searched before the default machine description file directories. If you use more than
7096one @option{-I} option, the directories are scanned in left-to-right
7097order; the standard default directory come after.
7098
7099
a5249a21
HPN
7100@end ifset
7101@ifset INTERNALS
f3a3d0d3
RH
7102@node Peephole Definitions
7103@section Machine-Specific Peephole Optimizers
7104@cindex peephole optimizer definitions
7105@cindex defining peephole optimizers
7106
7107In addition to instruction patterns the @file{md} file may contain
7108definitions of machine-specific peephole optimizations.
7109
7110The combiner does not notice certain peephole optimizations when the data
7111flow in the program does not suggest that it should try them. For example,
7112sometimes two consecutive insns related in purpose can be combined even
7113though the second one does not appear to use a register computed in the
7114first one. A machine-specific peephole optimizer can detect such
7115opportunities.
7116
7117There are two forms of peephole definitions that may be used. The
7118original @code{define_peephole} is run at assembly output time to
7119match insns and substitute assembly text. Use of @code{define_peephole}
7120is deprecated.
7121
7122A newer @code{define_peephole2} matches insns and substitutes new
7123insns. The @code{peephole2} pass is run after register allocation
ebb48a4d 7124but before scheduling, which may result in much better code for
f3a3d0d3
RH
7125targets that do scheduling.
7126
7127@menu
7128* define_peephole:: RTL to Text Peephole Optimizers
7129* define_peephole2:: RTL to RTL Peephole Optimizers
7130@end menu
7131
a5249a21
HPN
7132@end ifset
7133@ifset INTERNALS
f3a3d0d3
RH
7134@node define_peephole
7135@subsection RTL to Text Peephole Optimizers
7136@findex define_peephole
7137
7138@need 1000
7139A definition looks like this:
7140
7141@smallexample
7142(define_peephole
7143 [@var{insn-pattern-1}
7144 @var{insn-pattern-2}
7145 @dots{}]
7146 "@var{condition}"
7147 "@var{template}"
630d3d5a 7148 "@var{optional-insn-attributes}")
f3a3d0d3
RH
7149@end smallexample
7150
7151@noindent
7152The last string operand may be omitted if you are not using any
7153machine-specific information in this machine description. If present,
7154it must obey the same rules as in a @code{define_insn}.
7155
7156In this skeleton, @var{insn-pattern-1} and so on are patterns to match
7157consecutive insns. The optimization applies to a sequence of insns when
7158@var{insn-pattern-1} matches the first one, @var{insn-pattern-2} matches
bd819a4a 7159the next, and so on.
f3a3d0d3
RH
7160
7161Each of the insns matched by a peephole must also match a
7162@code{define_insn}. Peepholes are checked only at the last stage just
7163before code generation, and only optionally. Therefore, any insn which
7164would match a peephole but no @code{define_insn} will cause a crash in code
7165generation in an unoptimized compilation, or at various optimization
7166stages.
7167
7168The operands of the insns are matched with @code{match_operands},
7169@code{match_operator}, and @code{match_dup}, as usual. What is not
7170usual is that the operand numbers apply to all the insn patterns in the
7171definition. So, you can check for identical operands in two insns by
7172using @code{match_operand} in one insn and @code{match_dup} in the
7173other.
7174
7175The operand constraints used in @code{match_operand} patterns do not have
7176any direct effect on the applicability of the peephole, but they will
7177be validated afterward, so make sure your constraints are general enough
7178to apply whenever the peephole matches. If the peephole matches
7179but the constraints are not satisfied, the compiler will crash.
7180
7181It is safe to omit constraints in all the operands of the peephole; or
7182you can write constraints which serve as a double-check on the criteria
7183previously tested.
7184
7185Once a sequence of insns matches the patterns, the @var{condition} is
7186checked. This is a C expression which makes the final decision whether to
7187perform the optimization (we do so if the expression is nonzero). If
7188@var{condition} is omitted (in other words, the string is empty) then the
7189optimization is applied to every sequence of insns that matches the
7190patterns.
7191
7192The defined peephole optimizations are applied after register allocation
7193is complete. Therefore, the peephole definition can check which
7194operands have ended up in which kinds of registers, just by looking at
7195the operands.
7196
7197@findex prev_active_insn
7198The way to refer to the operands in @var{condition} is to write
7199@code{operands[@var{i}]} for operand number @var{i} (as matched by
7200@code{(match_operand @var{i} @dots{})}). Use the variable @code{insn}
7201to refer to the last of the insns being matched; use
7202@code{prev_active_insn} to find the preceding insns.
7203
7204@findex dead_or_set_p
7205When optimizing computations with intermediate results, you can use
7206@var{condition} to match only when the intermediate results are not used
7207elsewhere. Use the C expression @code{dead_or_set_p (@var{insn},
7208@var{op})}, where @var{insn} is the insn in which you expect the value
7209to be used for the last time (from the value of @code{insn}, together
7210with use of @code{prev_nonnote_insn}), and @var{op} is the intermediate
bd819a4a 7211value (from @code{operands[@var{i}]}).
f3a3d0d3
RH
7212
7213Applying the optimization means replacing the sequence of insns with one
7214new insn. The @var{template} controls ultimate output of assembler code
7215for this combined insn. It works exactly like the template of a
7216@code{define_insn}. Operand numbers in this template are the same ones
7217used in matching the original sequence of insns.
7218
7219The result of a defined peephole optimizer does not need to match any of
7220the insn patterns in the machine description; it does not even have an
7221opportunity to match them. The peephole optimizer definition itself serves
7222as the insn pattern to control how the insn is output.
7223
7224Defined peephole optimizers are run as assembler code is being output,
7225so the insns they produce are never combined or rearranged in any way.
7226
7227Here is an example, taken from the 68000 machine description:
7228
7229@smallexample
7230(define_peephole
7231 [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
7232 (set (match_operand:DF 0 "register_operand" "=f")
7233 (match_operand:DF 1 "register_operand" "ad"))]
7234 "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
f3a3d0d3
RH
7235@{
7236 rtx xoperands[2];
a2a8cc44 7237 xoperands[1] = gen_rtx_REG (SImode, REGNO (operands[1]) + 1);
f3a3d0d3 7238#ifdef MOTOROLA
0f40f9f7
ZW
7239 output_asm_insn ("move.l %1,(sp)", xoperands);
7240 output_asm_insn ("move.l %1,-(sp)", operands);
7241 return "fmove.d (sp)+,%0";
f3a3d0d3 7242#else
0f40f9f7
ZW
7243 output_asm_insn ("movel %1,sp@@", xoperands);
7244 output_asm_insn ("movel %1,sp@@-", operands);
7245 return "fmoved sp@@+,%0";
f3a3d0d3 7246#endif
0f40f9f7 7247@})
f3a3d0d3
RH
7248@end smallexample
7249
7250@need 1000
7251The effect of this optimization is to change
7252
7253@smallexample
7254@group
7255jbsr _foobar
7256addql #4,sp
7257movel d1,sp@@-
7258movel d0,sp@@-
7259fmoved sp@@+,fp0
7260@end group
7261@end smallexample
7262
7263@noindent
7264into
7265
7266@smallexample
7267@group
7268jbsr _foobar
7269movel d1,sp@@
7270movel d0,sp@@-
7271fmoved sp@@+,fp0
7272@end group
7273@end smallexample
7274
7275@ignore
7276@findex CC_REVERSED
7277If a peephole matches a sequence including one or more jump insns, you must
7278take account of the flags such as @code{CC_REVERSED} which specify that the
7279condition codes are represented in an unusual manner. The compiler
7280automatically alters any ordinary conditional jumps which occur in such
7281situations, but the compiler cannot alter jumps which have been replaced by
7282peephole optimizations. So it is up to you to alter the assembler code
7283that the peephole produces. Supply C code to write the assembler output,
7284and in this C code check the condition code status flags and change the
7285assembler code as appropriate.
7286@end ignore
7287
7288@var{insn-pattern-1} and so on look @emph{almost} like the second
7289operand of @code{define_insn}. There is one important difference: the
7290second operand of @code{define_insn} consists of one or more RTX's
7291enclosed in square brackets. Usually, there is only one: then the same
7292action can be written as an element of a @code{define_peephole}. But
7293when there are multiple actions in a @code{define_insn}, they are
7294implicitly enclosed in a @code{parallel}. Then you must explicitly
7295write the @code{parallel}, and the square brackets within it, in the
7296@code{define_peephole}. Thus, if an insn pattern looks like this,
7297
7298@smallexample
7299(define_insn "divmodsi4"
7300 [(set (match_operand:SI 0 "general_operand" "=d")
7301 (div:SI (match_operand:SI 1 "general_operand" "0")
7302 (match_operand:SI 2 "general_operand" "dmsK")))
7303 (set (match_operand:SI 3 "general_operand" "=d")
7304 (mod:SI (match_dup 1) (match_dup 2)))]
7305 "TARGET_68020"
7306 "divsl%.l %2,%3:%0")
7307@end smallexample
7308
7309@noindent
7310then the way to mention this insn in a peephole is as follows:
7311
7312@smallexample
7313(define_peephole
7314 [@dots{}
7315 (parallel
7316 [(set (match_operand:SI 0 "general_operand" "=d")
7317 (div:SI (match_operand:SI 1 "general_operand" "0")
7318 (match_operand:SI 2 "general_operand" "dmsK")))
7319 (set (match_operand:SI 3 "general_operand" "=d")
7320 (mod:SI (match_dup 1) (match_dup 2)))])
7321 @dots{}]
7322 @dots{})
7323@end smallexample
7324
a5249a21
HPN
7325@end ifset
7326@ifset INTERNALS
f3a3d0d3
RH
7327@node define_peephole2
7328@subsection RTL to RTL Peephole Optimizers
7329@findex define_peephole2
7330
7331The @code{define_peephole2} definition tells the compiler how to
ebb48a4d 7332substitute one sequence of instructions for another sequence,
f3a3d0d3
RH
7333what additional scratch registers may be needed and what their
7334lifetimes must be.
7335
7336@smallexample
7337(define_peephole2
7338 [@var{insn-pattern-1}
7339 @var{insn-pattern-2}
7340 @dots{}]
7341 "@var{condition}"
7342 [@var{new-insn-pattern-1}
7343 @var{new-insn-pattern-2}
7344 @dots{}]
630d3d5a 7345 "@var{preparation-statements}")
f3a3d0d3
RH
7346@end smallexample
7347
7348The definition is almost identical to @code{define_split}
7349(@pxref{Insn Splitting}) except that the pattern to match is not a
7350single instruction, but a sequence of instructions.
7351
7352It is possible to request additional scratch registers for use in the
7353output template. If appropriate registers are not free, the pattern
7354will simply not match.
7355
7356@findex match_scratch
7357@findex match_dup
7358Scratch registers are requested with a @code{match_scratch} pattern at
7359the top level of the input pattern. The allocated register (initially) will
7360be dead at the point requested within the original sequence. If the scratch
7361is used at more than a single point, a @code{match_dup} pattern at the
7362top level of the input pattern marks the last position in the input sequence
7363at which the register must be available.
7364
7365Here is an example from the IA-32 machine description:
7366
7367@smallexample
7368(define_peephole2
7369 [(match_scratch:SI 2 "r")
7370 (parallel [(set (match_operand:SI 0 "register_operand" "")
7371 (match_operator:SI 3 "arith_or_logical_operator"
7372 [(match_dup 0)
7373 (match_operand:SI 1 "memory_operand" "")]))
7374 (clobber (reg:CC 17))])]
7375 "! optimize_size && ! TARGET_READ_MODIFY"
7376 [(set (match_dup 2) (match_dup 1))
7377 (parallel [(set (match_dup 0)
7378 (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
7379 (clobber (reg:CC 17))])]
7380 "")
7381@end smallexample
7382
7383@noindent
7384This pattern tries to split a load from its use in the hopes that we'll be
7385able to schedule around the memory load latency. It allocates a single
7386@code{SImode} register of class @code{GENERAL_REGS} (@code{"r"}) that needs
7387to be live only at the point just before the arithmetic.
7388
b192711e 7389A real example requiring extended scratch lifetimes is harder to come by,
f3a3d0d3
RH
7390so here's a silly made-up example:
7391
7392@smallexample
7393(define_peephole2
7394 [(match_scratch:SI 4 "r")
7395 (set (match_operand:SI 0 "" "") (match_operand:SI 1 "" ""))
7396 (set (match_operand:SI 2 "" "") (match_dup 1))
7397 (match_dup 4)
7398 (set (match_operand:SI 3 "" "") (match_dup 1))]
630d3d5a 7399 "/* @r{determine 1 does not overlap 0 and 2} */"
f3a3d0d3
RH
7400 [(set (match_dup 4) (match_dup 1))
7401 (set (match_dup 0) (match_dup 4))
7402 (set (match_dup 2) (match_dup 4))]
7403 (set (match_dup 3) (match_dup 4))]
7404 "")
7405@end smallexample
7406
7407@noindent
a628d195
RH
7408If we had not added the @code{(match_dup 4)} in the middle of the input
7409sequence, it might have been the case that the register we chose at the
7410beginning of the sequence is killed by the first or second @code{set}.
f3a3d0d3 7411
a5249a21
HPN
7412@end ifset
7413@ifset INTERNALS
03dda8e3
RK
7414@node Insn Attributes
7415@section Instruction Attributes
7416@cindex insn attributes
7417@cindex instruction attributes
7418
7419In addition to describing the instruction supported by the target machine,
7420the @file{md} file also defines a group of @dfn{attributes} and a set of
7421values for each. Every generated insn is assigned a value for each attribute.
7422One possible attribute would be the effect that the insn has on the machine's
7423condition code. This attribute can then be used by @code{NOTICE_UPDATE_CC}
7424to track the condition codes.
7425
7426@menu
7427* Defining Attributes:: Specifying attributes and their values.
7428* Expressions:: Valid expressions for attribute values.
7429* Tagging Insns:: Assigning attribute values to insns.
7430* Attr Example:: An example of assigning attributes.
7431* Insn Lengths:: Computing the length of insns.
7432* Constant Attributes:: Defining attributes that are constant.
7433* Delay Slots:: Defining delay slots required for a machine.
fae15c93 7434* Processor pipeline description:: Specifying information for insn scheduling.
03dda8e3
RK
7435@end menu
7436
a5249a21
HPN
7437@end ifset
7438@ifset INTERNALS
03dda8e3
RK
7439@node Defining Attributes
7440@subsection Defining Attributes and their Values
7441@cindex defining attributes and their values
7442@cindex attributes, defining
7443
7444@findex define_attr
7445The @code{define_attr} expression is used to define each attribute required
7446by the target machine. It looks like:
7447
7448@smallexample
7449(define_attr @var{name} @var{list-of-values} @var{default})
7450@end smallexample
7451
7452@var{name} is a string specifying the name of the attribute being defined.
0bddee8e
BS
7453Some attributes are used in a special way by the rest of the compiler. The
7454@code{enabled} attribute can be used to conditionally enable or disable
7455insn alternatives (@pxref{Disable Insn Alternatives}). The @code{predicable}
7456attribute, together with a suitable @code{define_cond_exec}
7457(@pxref{Conditional Execution}), can be used to automatically generate
7458conditional variants of instruction patterns. The compiler internally uses
7459the names @code{ce_enabled} and @code{nonce_enabled}, so they should not be
7460used elsewhere as alternative names.
03dda8e3
RK
7461
7462@var{list-of-values} is either a string that specifies a comma-separated
7463list of values that can be assigned to the attribute, or a null string to
7464indicate that the attribute takes numeric values.
7465
7466@var{default} is an attribute expression that gives the value of this
7467attribute for insns that match patterns whose definition does not include
7468an explicit value for this attribute. @xref{Attr Example}, for more
7469information on the handling of defaults. @xref{Constant Attributes},
7470for information on attributes that do not depend on any particular insn.
7471
7472@findex insn-attr.h
7473For each defined attribute, a number of definitions are written to the
7474@file{insn-attr.h} file. For cases where an explicit set of values is
7475specified for an attribute, the following are defined:
7476
7477@itemize @bullet
7478@item
7479A @samp{#define} is written for the symbol @samp{HAVE_ATTR_@var{name}}.
7480
7481@item
2eac577f 7482An enumerated class is defined for @samp{attr_@var{name}} with
03dda8e3 7483elements of the form @samp{@var{upper-name}_@var{upper-value}} where
4bd0bee9 7484the attribute name and value are first converted to uppercase.
03dda8e3
RK
7485
7486@item
7487A function @samp{get_attr_@var{name}} is defined that is passed an insn and
7488returns the attribute value for that insn.
7489@end itemize
7490
7491For example, if the following is present in the @file{md} file:
7492
7493@smallexample
7494(define_attr "type" "branch,fp,load,store,arith" @dots{})
7495@end smallexample
7496
7497@noindent
7498the following lines will be written to the file @file{insn-attr.h}.
7499
7500@smallexample
7501#define HAVE_ATTR_type
7502enum attr_type @{TYPE_BRANCH, TYPE_FP, TYPE_LOAD,
7503 TYPE_STORE, TYPE_ARITH@};
7504extern enum attr_type get_attr_type ();
7505@end smallexample
7506
7507If the attribute takes numeric values, no @code{enum} type will be
7508defined and the function to obtain the attribute's value will return
7509@code{int}.
7510
7ac28727
AK
7511There are attributes which are tied to a specific meaning. These
7512attributes are not free to use for other purposes:
7513
7514@table @code
7515@item length
7516The @code{length} attribute is used to calculate the length of emitted
7517code chunks. This is especially important when verifying branch
7518distances. @xref{Insn Lengths}.
7519
7520@item enabled
7521The @code{enabled} attribute can be defined to prevent certain
7522alternatives of an insn definition from being used during code
7523generation. @xref{Disable Insn Alternatives}.
7ac28727
AK
7524@end table
7525
8f4fe86c
RS
7526@findex define_enum_attr
7527@anchor{define_enum_attr}
7528Another way of defining an attribute is to use:
7529
7530@smallexample
7531(define_enum_attr "@var{attr}" "@var{enum}" @var{default})
7532@end smallexample
7533
7534This works in just the same way as @code{define_attr}, except that
7535the list of values is taken from a separate enumeration called
7536@var{enum} (@pxref{define_enum}). This form allows you to use
7537the same list of values for several attributes without having to
7538repeat the list each time. For example:
7539
7540@smallexample
7541(define_enum "processor" [
7542 model_a
7543 model_b
7544 @dots{}
7545])
7546(define_enum_attr "arch" "processor"
7547 (const (symbol_ref "target_arch")))
7548(define_enum_attr "tune" "processor"
7549 (const (symbol_ref "target_tune")))
7550@end smallexample
7551
7552defines the same attributes as:
7553
7554@smallexample
7555(define_attr "arch" "model_a,model_b,@dots{}"
7556 (const (symbol_ref "target_arch")))
7557(define_attr "tune" "model_a,model_b,@dots{}"
7558 (const (symbol_ref "target_tune")))
7559@end smallexample
7560
7561but without duplicating the processor list. The second example defines two
7562separate C enums (@code{attr_arch} and @code{attr_tune}) whereas the first
7563defines a single C enum (@code{processor}).
a5249a21
HPN
7564@end ifset
7565@ifset INTERNALS
03dda8e3
RK
7566@node Expressions
7567@subsection Attribute Expressions
7568@cindex attribute expressions
7569
7570RTL expressions used to define attributes use the codes described above
7571plus a few specific to attribute definitions, to be discussed below.
7572Attribute value expressions must have one of the following forms:
7573
7574@table @code
7575@cindex @code{const_int} and attributes
7576@item (const_int @var{i})
7577The integer @var{i} specifies the value of a numeric attribute. @var{i}
7578must be non-negative.
7579
7580The value of a numeric attribute can be specified either with a
00bc45c1
RH
7581@code{const_int}, or as an integer represented as a string in
7582@code{const_string}, @code{eq_attr} (see below), @code{attr},
7583@code{symbol_ref}, simple arithmetic expressions, and @code{set_attr}
7584overrides on specific instructions (@pxref{Tagging Insns}).
03dda8e3
RK
7585
7586@cindex @code{const_string} and attributes
7587@item (const_string @var{value})
7588The string @var{value} specifies a constant attribute value.
7589If @var{value} is specified as @samp{"*"}, it means that the default value of
7590the attribute is to be used for the insn containing this expression.
7591@samp{"*"} obviously cannot be used in the @var{default} expression
bd819a4a 7592of a @code{define_attr}.
03dda8e3
RK
7593
7594If the attribute whose value is being specified is numeric, @var{value}
7595must be a string containing a non-negative integer (normally
7596@code{const_int} would be used in this case). Otherwise, it must
7597contain one of the valid values for the attribute.
7598
7599@cindex @code{if_then_else} and attributes
7600@item (if_then_else @var{test} @var{true-value} @var{false-value})
7601@var{test} specifies an attribute test, whose format is defined below.
7602The value of this expression is @var{true-value} if @var{test} is true,
7603otherwise it is @var{false-value}.
7604
7605@cindex @code{cond} and attributes
7606@item (cond [@var{test1} @var{value1} @dots{}] @var{default})
7607The first operand of this expression is a vector containing an even
7608number of expressions and consisting of pairs of @var{test} and @var{value}
7609expressions. The value of the @code{cond} expression is that of the
7610@var{value} corresponding to the first true @var{test} expression. If
7611none of the @var{test} expressions are true, the value of the @code{cond}
7612expression is that of the @var{default} expression.
7613@end table
7614
7615@var{test} expressions can have one of the following forms:
7616
7617@table @code
7618@cindex @code{const_int} and attribute tests
7619@item (const_int @var{i})
df2a54e9 7620This test is true if @var{i} is nonzero and false otherwise.
03dda8e3
RK
7621
7622@cindex @code{not} and attributes
7623@cindex @code{ior} and attributes
7624@cindex @code{and} and attributes
7625@item (not @var{test})
7626@itemx (ior @var{test1} @var{test2})
7627@itemx (and @var{test1} @var{test2})
7628These tests are true if the indicated logical function is true.
7629
7630@cindex @code{match_operand} and attributes
7631@item (match_operand:@var{m} @var{n} @var{pred} @var{constraints})
7632This test is true if operand @var{n} of the insn whose attribute value
7633is being determined has mode @var{m} (this part of the test is ignored
7634if @var{m} is @code{VOIDmode}) and the function specified by the string
df2a54e9 7635@var{pred} returns a nonzero value when passed operand @var{n} and mode
03dda8e3
RK
7636@var{m} (this part of the test is ignored if @var{pred} is the null
7637string).
7638
7639The @var{constraints} operand is ignored and should be the null string.
7640
0c0d3957
RS
7641@cindex @code{match_test} and attributes
7642@item (match_test @var{c-expr})
7643The test is true if C expression @var{c-expr} is true. In non-constant
7644attributes, @var{c-expr} has access to the following variables:
7645
7646@table @var
7647@item insn
7648The rtl instruction under test.
7649@item which_alternative
7650The @code{define_insn} alternative that @var{insn} matches.
7651@xref{Output Statement}.
7652@item operands
7653An array of @var{insn}'s rtl operands.
7654@end table
7655
7656@var{c-expr} behaves like the condition in a C @code{if} statement,
7657so there is no need to explicitly convert the expression into a boolean
76580 or 1 value. For example, the following two tests are equivalent:
7659
7660@smallexample
7661(match_test "x & 2")
7662(match_test "(x & 2) != 0")
7663@end smallexample
7664
03dda8e3
RK
7665@cindex @code{le} and attributes
7666@cindex @code{leu} and attributes
7667@cindex @code{lt} and attributes
7668@cindex @code{gt} and attributes
7669@cindex @code{gtu} and attributes
7670@cindex @code{ge} and attributes
7671@cindex @code{geu} and attributes
7672@cindex @code{ne} and attributes
7673@cindex @code{eq} and attributes
7674@cindex @code{plus} and attributes
7675@cindex @code{minus} and attributes
7676@cindex @code{mult} and attributes
7677@cindex @code{div} and attributes
7678@cindex @code{mod} and attributes
7679@cindex @code{abs} and attributes
7680@cindex @code{neg} and attributes
7681@cindex @code{ashift} and attributes
7682@cindex @code{lshiftrt} and attributes
7683@cindex @code{ashiftrt} and attributes
7684@item (le @var{arith1} @var{arith2})
7685@itemx (leu @var{arith1} @var{arith2})
7686@itemx (lt @var{arith1} @var{arith2})
7687@itemx (ltu @var{arith1} @var{arith2})
7688@itemx (gt @var{arith1} @var{arith2})
7689@itemx (gtu @var{arith1} @var{arith2})
7690@itemx (ge @var{arith1} @var{arith2})
7691@itemx (geu @var{arith1} @var{arith2})
7692@itemx (ne @var{arith1} @var{arith2})
7693@itemx (eq @var{arith1} @var{arith2})
7694These tests are true if the indicated comparison of the two arithmetic
7695expressions is true. Arithmetic expressions are formed with
7696@code{plus}, @code{minus}, @code{mult}, @code{div}, @code{mod},
7697@code{abs}, @code{neg}, @code{and}, @code{ior}, @code{xor}, @code{not},
bd819a4a 7698@code{ashift}, @code{lshiftrt}, and @code{ashiftrt} expressions.
03dda8e3
RK
7699
7700@findex get_attr
7701@code{const_int} and @code{symbol_ref} are always valid terms (@pxref{Insn
7702Lengths},for additional forms). @code{symbol_ref} is a string
7703denoting a C expression that yields an @code{int} when evaluated by the
7704@samp{get_attr_@dots{}} routine. It should normally be a global
bd819a4a 7705variable.
03dda8e3
RK
7706
7707@findex eq_attr
7708@item (eq_attr @var{name} @var{value})
7709@var{name} is a string specifying the name of an attribute.
7710
7711@var{value} is a string that is either a valid value for attribute
7712@var{name}, a comma-separated list of values, or @samp{!} followed by a
7713value or list. If @var{value} does not begin with a @samp{!}, this
7714test is true if the value of the @var{name} attribute of the current
7715insn is in the list specified by @var{value}. If @var{value} begins
7716with a @samp{!}, this test is true if the attribute's value is
7717@emph{not} in the specified list.
7718
7719For example,
7720
7721@smallexample
7722(eq_attr "type" "load,store")
7723@end smallexample
7724
7725@noindent
7726is equivalent to
7727
7728@smallexample
7729(ior (eq_attr "type" "load") (eq_attr "type" "store"))
7730@end smallexample
7731
7732If @var{name} specifies an attribute of @samp{alternative}, it refers to the
7733value of the compiler variable @code{which_alternative}
7734(@pxref{Output Statement}) and the values must be small integers. For
bd819a4a 7735example,
03dda8e3
RK
7736
7737@smallexample
7738(eq_attr "alternative" "2,3")
7739@end smallexample
7740
7741@noindent
7742is equivalent to
7743
7744@smallexample
7745(ior (eq (symbol_ref "which_alternative") (const_int 2))
7746 (eq (symbol_ref "which_alternative") (const_int 3)))
7747@end smallexample
7748
7749Note that, for most attributes, an @code{eq_attr} test is simplified in cases
7750where the value of the attribute being tested is known for all insns matching
bd819a4a 7751a particular pattern. This is by far the most common case.
03dda8e3
RK
7752
7753@findex attr_flag
7754@item (attr_flag @var{name})
7755The value of an @code{attr_flag} expression is true if the flag
7756specified by @var{name} is true for the @code{insn} currently being
7757scheduled.
7758
7759@var{name} is a string specifying one of a fixed set of flags to test.
7760Test the flags @code{forward} and @code{backward} to determine the
81e7aa8e 7761direction of a conditional branch.
03dda8e3
RK
7762
7763This example describes a conditional branch delay slot which
7764can be nullified for forward branches that are taken (annul-true) or
7765for backward branches which are not taken (annul-false).
7766
7767@smallexample
7768(define_delay (eq_attr "type" "cbranch")
7769 [(eq_attr "in_branch_delay" "true")
7770 (and (eq_attr "in_branch_delay" "true")
7771 (attr_flag "forward"))
7772 (and (eq_attr "in_branch_delay" "true")
7773 (attr_flag "backward"))])
7774@end smallexample
7775
7776The @code{forward} and @code{backward} flags are false if the current
7777@code{insn} being scheduled is not a conditional branch.
7778
03dda8e3
RK
7779@code{attr_flag} is only used during delay slot scheduling and has no
7780meaning to other passes of the compiler.
00bc45c1
RH
7781
7782@findex attr
7783@item (attr @var{name})
7784The value of another attribute is returned. This is most useful
7785for numeric attributes, as @code{eq_attr} and @code{attr_flag}
7786produce more efficient code for non-numeric attributes.
03dda8e3
RK
7787@end table
7788
a5249a21
HPN
7789@end ifset
7790@ifset INTERNALS
03dda8e3
RK
7791@node Tagging Insns
7792@subsection Assigning Attribute Values to Insns
7793@cindex tagging insns
7794@cindex assigning attribute values to insns
7795
7796The value assigned to an attribute of an insn is primarily determined by
7797which pattern is matched by that insn (or which @code{define_peephole}
7798generated it). Every @code{define_insn} and @code{define_peephole} can
7799have an optional last argument to specify the values of attributes for
7800matching insns. The value of any attribute not specified in a particular
7801insn is set to the default value for that attribute, as specified in its
7802@code{define_attr}. Extensive use of default values for attributes
7803permits the specification of the values for only one or two attributes
7804in the definition of most insn patterns, as seen in the example in the
bd819a4a 7805next section.
03dda8e3
RK
7806
7807The optional last argument of @code{define_insn} and
7808@code{define_peephole} is a vector of expressions, each of which defines
7809the value for a single attribute. The most general way of assigning an
7810attribute's value is to use a @code{set} expression whose first operand is an
7811@code{attr} expression giving the name of the attribute being set. The
7812second operand of the @code{set} is an attribute expression
bd819a4a 7813(@pxref{Expressions}) giving the value of the attribute.
03dda8e3
RK
7814
7815When the attribute value depends on the @samp{alternative} attribute
7816(i.e., which is the applicable alternative in the constraint of the
7817insn), the @code{set_attr_alternative} expression can be used. It
7818allows the specification of a vector of attribute expressions, one for
7819each alternative.
7820
7821@findex set_attr
7822When the generality of arbitrary attribute expressions is not required,
7823the simpler @code{set_attr} expression can be used, which allows
7824specifying a string giving either a single attribute value or a list
7825of attribute values, one for each alternative.
7826
7827The form of each of the above specifications is shown below. In each case,
7828@var{name} is a string specifying the attribute to be set.
7829
7830@table @code
7831@item (set_attr @var{name} @var{value-string})
7832@var{value-string} is either a string giving the desired attribute value,
7833or a string containing a comma-separated list giving the values for
7834succeeding alternatives. The number of elements must match the number
7835of alternatives in the constraint of the insn pattern.
7836
7837Note that it may be useful to specify @samp{*} for some alternative, in
7838which case the attribute will assume its default value for insns matching
7839that alternative.
7840
7841@findex set_attr_alternative
7842@item (set_attr_alternative @var{name} [@var{value1} @var{value2} @dots{}])
7843Depending on the alternative of the insn, the value will be one of the
7844specified values. This is a shorthand for using a @code{cond} with
7845tests on the @samp{alternative} attribute.
7846
7847@findex attr
7848@item (set (attr @var{name}) @var{value})
7849The first operand of this @code{set} must be the special RTL expression
7850@code{attr}, whose sole operand is a string giving the name of the
7851attribute being set. @var{value} is the value of the attribute.
7852@end table
7853
7854The following shows three different ways of representing the same
7855attribute value specification:
7856
7857@smallexample
7858(set_attr "type" "load,store,arith")
7859
7860(set_attr_alternative "type"
7861 [(const_string "load") (const_string "store")
7862 (const_string "arith")])
7863
7864(set (attr "type")
7865 (cond [(eq_attr "alternative" "1") (const_string "load")
7866 (eq_attr "alternative" "2") (const_string "store")]
7867 (const_string "arith")))
7868@end smallexample
7869
7870@need 1000
7871@findex define_asm_attributes
7872The @code{define_asm_attributes} expression provides a mechanism to
7873specify the attributes assigned to insns produced from an @code{asm}
7874statement. It has the form:
7875
7876@smallexample
7877(define_asm_attributes [@var{attr-sets}])
7878@end smallexample
7879
7880@noindent
7881where @var{attr-sets} is specified the same as for both the
7882@code{define_insn} and the @code{define_peephole} expressions.
7883
7884These values will typically be the ``worst case'' attribute values. For
7885example, they might indicate that the condition code will be clobbered.
7886
7887A specification for a @code{length} attribute is handled specially. The
7888way to compute the length of an @code{asm} insn is to multiply the
7889length specified in the expression @code{define_asm_attributes} by the
7890number of machine instructions specified in the @code{asm} statement,
7891determined by counting the number of semicolons and newlines in the
7892string. Therefore, the value of the @code{length} attribute specified
7893in a @code{define_asm_attributes} should be the maximum possible length
7894of a single machine instruction.
7895
a5249a21
HPN
7896@end ifset
7897@ifset INTERNALS
03dda8e3
RK
7898@node Attr Example
7899@subsection Example of Attribute Specifications
7900@cindex attribute specifications example
7901@cindex attribute specifications
7902
7903The judicious use of defaulting is important in the efficient use of
7904insn attributes. Typically, insns are divided into @dfn{types} and an
7905attribute, customarily called @code{type}, is used to represent this
7906value. This attribute is normally used only to define the default value
7907for other attributes. An example will clarify this usage.
7908
7909Assume we have a RISC machine with a condition code and in which only
7910full-word operations are performed in registers. Let us assume that we
7911can divide all insns into loads, stores, (integer) arithmetic
7912operations, floating point operations, and branches.
7913
7914Here we will concern ourselves with determining the effect of an insn on
7915the condition code and will limit ourselves to the following possible
7916effects: The condition code can be set unpredictably (clobbered), not
7917be changed, be set to agree with the results of the operation, or only
7918changed if the item previously set into the condition code has been
7919modified.
7920
7921Here is part of a sample @file{md} file for such a machine:
7922
7923@smallexample
7924(define_attr "type" "load,store,arith,fp,branch" (const_string "arith"))
7925
7926(define_attr "cc" "clobber,unchanged,set,change0"
7927 (cond [(eq_attr "type" "load")
7928 (const_string "change0")
7929 (eq_attr "type" "store,branch")
7930 (const_string "unchanged")
7931 (eq_attr "type" "arith")
7932 (if_then_else (match_operand:SI 0 "" "")
7933 (const_string "set")
7934 (const_string "clobber"))]
7935 (const_string "clobber")))
7936
7937(define_insn ""
7938 [(set (match_operand:SI 0 "general_operand" "=r,r,m")
7939 (match_operand:SI 1 "general_operand" "r,m,r"))]
7940 ""
7941 "@@
7942 move %0,%1
7943 load %0,%1
7944 store %0,%1"
7945 [(set_attr "type" "arith,load,store")])
7946@end smallexample
7947
7948Note that we assume in the above example that arithmetic operations
7949performed on quantities smaller than a machine word clobber the condition
7950code since they will set the condition code to a value corresponding to the
7951full-word result.
7952
a5249a21
HPN
7953@end ifset
7954@ifset INTERNALS
03dda8e3
RK
7955@node Insn Lengths
7956@subsection Computing the Length of an Insn
7957@cindex insn lengths, computing
7958@cindex computing the length of an insn
7959
7960For many machines, multiple types of branch instructions are provided, each
7961for different length branch displacements. In most cases, the assembler
7962will choose the correct instruction to use. However, when the assembler
b49900cc 7963cannot do so, GCC can when a special attribute, the @code{length}
03dda8e3
RK
7964attribute, is defined. This attribute must be defined to have numeric
7965values by specifying a null string in its @code{define_attr}.
7966
b49900cc 7967In the case of the @code{length} attribute, two additional forms of
03dda8e3
RK
7968arithmetic terms are allowed in test expressions:
7969
7970@table @code
7971@cindex @code{match_dup} and attributes
7972@item (match_dup @var{n})
7973This refers to the address of operand @var{n} of the current insn, which
7974must be a @code{label_ref}.
7975
7976@cindex @code{pc} and attributes
7977@item (pc)
7978This refers to the address of the @emph{current} insn. It might have
7979been more consistent with other usage to make this the address of the
7980@emph{next} insn but this would be confusing because the length of the
7981current insn is to be computed.
7982@end table
7983
7984@cindex @code{addr_vec}, length of
7985@cindex @code{addr_diff_vec}, length of
7986For normal insns, the length will be determined by value of the
b49900cc 7987@code{length} attribute. In the case of @code{addr_vec} and
03dda8e3
RK
7988@code{addr_diff_vec} insn patterns, the length is computed as
7989the number of vectors multiplied by the size of each vector.
7990
7991Lengths are measured in addressable storage units (bytes).
7992
7993The following macros can be used to refine the length computation:
7994
7995@table @code
03dda8e3
RK
7996@findex ADJUST_INSN_LENGTH
7997@item ADJUST_INSN_LENGTH (@var{insn}, @var{length})
7998If defined, modifies the length assigned to instruction @var{insn} as a
7999function of the context in which it is used. @var{length} is an lvalue
8000that contains the initially computed length of the insn and should be
a8aa4e0b 8001updated with the correct length of the insn.
03dda8e3
RK
8002
8003This macro will normally not be required. A case in which it is
161d7b59 8004required is the ROMP@. On this machine, the size of an @code{addr_vec}
03dda8e3
RK
8005insn must be increased by two to compensate for the fact that alignment
8006may be required.
8007@end table
8008
8009@findex get_attr_length
8010The routine that returns @code{get_attr_length} (the value of the
8011@code{length} attribute) can be used by the output routine to
8012determine the form of the branch instruction to be written, as the
8013example below illustrates.
8014
8015As an example of the specification of variable-length branches, consider
8016the IBM 360. If we adopt the convention that a register will be set to
8017the starting address of a function, we can jump to labels within 4k of
8018the start using a four-byte instruction. Otherwise, we need a six-byte
8019sequence to load the address from memory and then branch to it.
8020
8021On such a machine, a pattern for a branch instruction might be specified
8022as follows:
8023
8024@smallexample
8025(define_insn "jump"
8026 [(set (pc)
8027 (label_ref (match_operand 0 "" "")))]
8028 ""
03dda8e3
RK
8029@{
8030 return (get_attr_length (insn) == 4
0f40f9f7
ZW
8031 ? "b %l0" : "l r15,=a(%l0); br r15");
8032@}
9c34dbbf
ZW
8033 [(set (attr "length")
8034 (if_then_else (lt (match_dup 0) (const_int 4096))
8035 (const_int 4)
8036 (const_int 6)))])
03dda8e3
RK
8037@end smallexample
8038
a5249a21
HPN
8039@end ifset
8040@ifset INTERNALS
03dda8e3
RK
8041@node Constant Attributes
8042@subsection Constant Attributes
8043@cindex constant attributes
8044
8045A special form of @code{define_attr}, where the expression for the
8046default value is a @code{const} expression, indicates an attribute that
8047is constant for a given run of the compiler. Constant attributes may be
8048used to specify which variety of processor is used. For example,
8049
8050@smallexample
8051(define_attr "cpu" "m88100,m88110,m88000"
8052 (const
8053 (cond [(symbol_ref "TARGET_88100") (const_string "m88100")
8054 (symbol_ref "TARGET_88110") (const_string "m88110")]
8055 (const_string "m88000"))))
8056
8057(define_attr "memory" "fast,slow"
8058 (const
8059 (if_then_else (symbol_ref "TARGET_FAST_MEM")
8060 (const_string "fast")
8061 (const_string "slow"))))
8062@end smallexample
8063
8064The routine generated for constant attributes has no parameters as it
8065does not depend on any particular insn. RTL expressions used to define
8066the value of a constant attribute may use the @code{symbol_ref} form,
8067but may not use either the @code{match_operand} form or @code{eq_attr}
8068forms involving insn attributes.
8069
a5249a21
HPN
8070@end ifset
8071@ifset INTERNALS
03dda8e3
RK
8072@node Delay Slots
8073@subsection Delay Slot Scheduling
8074@cindex delay slots, defining
8075
8076The insn attribute mechanism can be used to specify the requirements for
8077delay slots, if any, on a target machine. An instruction is said to
8078require a @dfn{delay slot} if some instructions that are physically
8079after the instruction are executed as if they were located before it.
8080Classic examples are branch and call instructions, which often execute
8081the following instruction before the branch or call is performed.
8082
8083On some machines, conditional branch instructions can optionally
8084@dfn{annul} instructions in the delay slot. This means that the
8085instruction will not be executed for certain branch outcomes. Both
8086instructions that annul if the branch is true and instructions that
8087annul if the branch is false are supported.
8088
8089Delay slot scheduling differs from instruction scheduling in that
8090determining whether an instruction needs a delay slot is dependent only
8091on the type of instruction being generated, not on data flow between the
8092instructions. See the next section for a discussion of data-dependent
8093instruction scheduling.
8094
8095@findex define_delay
8096The requirement of an insn needing one or more delay slots is indicated
8097via the @code{define_delay} expression. It has the following form:
8098
8099@smallexample
8100(define_delay @var{test}
8101 [@var{delay-1} @var{annul-true-1} @var{annul-false-1}
8102 @var{delay-2} @var{annul-true-2} @var{annul-false-2}
8103 @dots{}])
8104@end smallexample
8105
8106@var{test} is an attribute test that indicates whether this
8107@code{define_delay} applies to a particular insn. If so, the number of
8108required delay slots is determined by the length of the vector specified
8109as the second argument. An insn placed in delay slot @var{n} must
8110satisfy attribute test @var{delay-n}. @var{annul-true-n} is an
8111attribute test that specifies which insns may be annulled if the branch
8112is true. Similarly, @var{annul-false-n} specifies which insns in the
8113delay slot may be annulled if the branch is false. If annulling is not
bd819a4a 8114supported for that delay slot, @code{(nil)} should be coded.
03dda8e3
RK
8115
8116For example, in the common case where branch and call insns require
8117a single delay slot, which may contain any insn other than a branch or
8118call, the following would be placed in the @file{md} file:
8119
8120@smallexample
8121(define_delay (eq_attr "type" "branch,call")
8122 [(eq_attr "type" "!branch,call") (nil) (nil)])
8123@end smallexample
8124
8125Multiple @code{define_delay} expressions may be specified. In this
8126case, each such expression specifies different delay slot requirements
8127and there must be no insn for which tests in two @code{define_delay}
8128expressions are both true.
8129
8130For example, if we have a machine that requires one delay slot for branches
8131but two for calls, no delay slot can contain a branch or call insn,
8132and any valid insn in the delay slot for the branch can be annulled if the
8133branch is true, we might represent this as follows:
8134
8135@smallexample
8136(define_delay (eq_attr "type" "branch")
8137 [(eq_attr "type" "!branch,call")
8138 (eq_attr "type" "!branch,call")
8139 (nil)])
8140
8141(define_delay (eq_attr "type" "call")
8142 [(eq_attr "type" "!branch,call") (nil) (nil)
8143 (eq_attr "type" "!branch,call") (nil) (nil)])
8144@end smallexample
8145@c the above is *still* too long. --mew 4feb93
8146
a5249a21
HPN
8147@end ifset
8148@ifset INTERNALS
fae15c93
VM
8149@node Processor pipeline description
8150@subsection Specifying processor pipeline description
8151@cindex processor pipeline description
8152@cindex processor functional units
8153@cindex instruction latency time
8154@cindex interlock delays
8155@cindex data dependence delays
8156@cindex reservation delays
8157@cindex pipeline hazard recognizer
8158@cindex automaton based pipeline description
8159@cindex regular expressions
8160@cindex deterministic finite state automaton
8161@cindex automaton based scheduler
8162@cindex RISC
8163@cindex VLIW
8164
ef261fee 8165To achieve better performance, most modern processors
fae15c93
VM
8166(super-pipelined, superscalar @acronym{RISC}, and @acronym{VLIW}
8167processors) have many @dfn{functional units} on which several
8168instructions can be executed simultaneously. An instruction starts
8169execution if its issue conditions are satisfied. If not, the
ef261fee 8170instruction is stalled until its conditions are satisfied. Such
fae15c93 8171@dfn{interlock (pipeline) delay} causes interruption of the fetching
431ae0bf 8172of successor instructions (or demands nop instructions, e.g.@: for some
fae15c93
VM
8173MIPS processors).
8174
8175There are two major kinds of interlock delays in modern processors.
8176The first one is a data dependence delay determining @dfn{instruction
8177latency time}. The instruction execution is not started until all
8178source data have been evaluated by prior instructions (there are more
8179complex cases when the instruction execution starts even when the data
c0478a66 8180are not available but will be ready in given time after the
fae15c93
VM
8181instruction execution start). Taking the data dependence delays into
8182account is simple. The data dependence (true, output, and
8183anti-dependence) delay between two instructions is given by a
8184constant. In most cases this approach is adequate. The second kind
8185of interlock delays is a reservation delay. The reservation delay
8186means that two instructions under execution will be in need of shared
431ae0bf 8187processors resources, i.e.@: buses, internal registers, and/or
fae15c93
VM
8188functional units, which are reserved for some time. Taking this kind
8189of delay into account is complex especially for modern @acronym{RISC}
8190processors.
8191
8192The task of exploiting more processor parallelism is solved by an
ef261fee 8193instruction scheduler. For a better solution to this problem, the
fae15c93 8194instruction scheduler has to have an adequate description of the
fa0aee89
PB
8195processor parallelism (or @dfn{pipeline description}). GCC
8196machine descriptions describe processor parallelism and functional
8197unit reservations for groups of instructions with the aid of
8198@dfn{regular expressions}.
ef261fee
R
8199
8200The GCC instruction scheduler uses a @dfn{pipeline hazard recognizer} to
fae15c93 8201figure out the possibility of the instruction issue by the processor
ef261fee
R
8202on a given simulated processor cycle. The pipeline hazard recognizer is
8203automatically generated from the processor pipeline description. The
fa0aee89
PB
8204pipeline hazard recognizer generated from the machine description
8205is based on a deterministic finite state automaton (@acronym{DFA}):
8206the instruction issue is possible if there is a transition from one
8207automaton state to another one. This algorithm is very fast, and
8208furthermore, its speed is not dependent on processor
8209complexity@footnote{However, the size of the automaton depends on
6ccde948
RW
8210processor complexity. To limit this effect, machine descriptions
8211can split orthogonal parts of the machine description among several
8212automata: but then, since each of these must be stepped independently,
8213this does cause a small decrease in the algorithm's performance.}.
fae15c93 8214
fae15c93 8215@cindex automaton based pipeline description
fa0aee89
PB
8216The rest of this section describes the directives that constitute
8217an automaton-based processor pipeline description. The order of
8218these constructions within the machine description file is not
8219important.
fae15c93
VM
8220
8221@findex define_automaton
8222@cindex pipeline hazard recognizer
8223The following optional construction describes names of automata
8224generated and used for the pipeline hazards recognition. Sometimes
8225the generated finite state automaton used by the pipeline hazard
ef261fee 8226recognizer is large. If we use more than one automaton and bind functional
daf2f129 8227units to the automata, the total size of the automata is usually
fae15c93
VM
8228less than the size of the single automaton. If there is no one such
8229construction, only one finite state automaton is generated.
8230
8231@smallexample
8232(define_automaton @var{automata-names})
8233@end smallexample
8234
8235@var{automata-names} is a string giving names of the automata. The
8236names are separated by commas. All the automata should have unique names.
c62347f0 8237The automaton name is used in the constructions @code{define_cpu_unit} and
fae15c93
VM
8238@code{define_query_cpu_unit}.
8239
8240@findex define_cpu_unit
8241@cindex processor functional units
c62347f0 8242Each processor functional unit used in the description of instruction
fae15c93
VM
8243reservations should be described by the following construction.
8244
8245@smallexample
8246(define_cpu_unit @var{unit-names} [@var{automaton-name}])
8247@end smallexample
8248
8249@var{unit-names} is a string giving the names of the functional units
8250separated by commas. Don't use name @samp{nothing}, it is reserved
8251for other goals.
8252
ef261fee 8253@var{automaton-name} is a string giving the name of the automaton with
fae15c93
VM
8254which the unit is bound. The automaton should be described in
8255construction @code{define_automaton}. You should give
8256@dfn{automaton-name}, if there is a defined automaton.
8257
30028c85
VM
8258The assignment of units to automata are constrained by the uses of the
8259units in insn reservations. The most important constraint is: if a
8260unit reservation is present on a particular cycle of an alternative
8261for an insn reservation, then some unit from the same automaton must
8262be present on the same cycle for the other alternatives of the insn
8263reservation. The rest of the constraints are mentioned in the
8264description of the subsequent constructions.
8265
fae15c93
VM
8266@findex define_query_cpu_unit
8267@cindex querying function unit reservations
8268The following construction describes CPU functional units analogously
30028c85
VM
8269to @code{define_cpu_unit}. The reservation of such units can be
8270queried for an automaton state. The instruction scheduler never
8271queries reservation of functional units for given automaton state. So
8272as a rule, you don't need this construction. This construction could
431ae0bf 8273be used for future code generation goals (e.g.@: to generate
30028c85 8274@acronym{VLIW} insn templates).
fae15c93
VM
8275
8276@smallexample
8277(define_query_cpu_unit @var{unit-names} [@var{automaton-name}])
8278@end smallexample
8279
8280@var{unit-names} is a string giving names of the functional units
8281separated by commas.
8282
ef261fee 8283@var{automaton-name} is a string giving the name of the automaton with
fae15c93
VM
8284which the unit is bound.
8285
8286@findex define_insn_reservation
8287@cindex instruction latency time
8288@cindex regular expressions
8289@cindex data bypass
ef261fee 8290The following construction is the major one to describe pipeline
fae15c93
VM
8291characteristics of an instruction.
8292
8293@smallexample
8294(define_insn_reservation @var{insn-name} @var{default_latency}
8295 @var{condition} @var{regexp})
8296@end smallexample
8297
8298@var{default_latency} is a number giving latency time of the
8299instruction. There is an important difference between the old
8300description and the automaton based pipeline description. The latency
8301time is used for all dependencies when we use the old description. In
ef261fee
R
8302the automaton based pipeline description, the given latency time is only
8303used for true dependencies. The cost of anti-dependencies is always
fae15c93
VM
8304zero and the cost of output dependencies is the difference between
8305latency times of the producing and consuming insns (if the difference
ef261fee
R
8306is negative, the cost is considered to be zero). You can always
8307change the default costs for any description by using the target hook
fae15c93
VM
8308@code{TARGET_SCHED_ADJUST_COST} (@pxref{Scheduling}).
8309
cc6a602b 8310@var{insn-name} is a string giving the internal name of the insn. The
fae15c93
VM
8311internal names are used in constructions @code{define_bypass} and in
8312the automaton description file generated for debugging. The internal
ef261fee 8313name has nothing in common with the names in @code{define_insn}. It is a
fae15c93
VM
8314good practice to use insn classes described in the processor manual.
8315
8316@var{condition} defines what RTL insns are described by this
8317construction. You should remember that you will be in trouble if
8318@var{condition} for two or more different
8319@code{define_insn_reservation} constructions is TRUE for an insn. In
8320this case what reservation will be used for the insn is not defined.
8321Such cases are not checked during generation of the pipeline hazards
8322recognizer because in general recognizing that two conditions may have
8323the same value is quite difficult (especially if the conditions
8324contain @code{symbol_ref}). It is also not checked during the
8325pipeline hazard recognizer work because it would slow down the
8326recognizer considerably.
8327
ef261fee 8328@var{regexp} is a string describing the reservation of the cpu's functional
fae15c93
VM
8329units by the instruction. The reservations are described by a regular
8330expression according to the following syntax:
8331
8332@smallexample
8333 regexp = regexp "," oneof
8334 | oneof
8335
8336 oneof = oneof "|" allof
8337 | allof
8338
8339 allof = allof "+" repeat
8340 | repeat
daf2f129 8341
fae15c93
VM
8342 repeat = element "*" number
8343 | element
8344
8345 element = cpu_function_unit_name
8346 | reservation_name
8347 | result_name
8348 | "nothing"
8349 | "(" regexp ")"
8350@end smallexample
8351
8352@itemize @bullet
8353@item
8354@samp{,} is used for describing the start of the next cycle in
8355the reservation.
8356
8357@item
8358@samp{|} is used for describing a reservation described by the first
8359regular expression @strong{or} a reservation described by the second
8360regular expression @strong{or} etc.
8361
8362@item
8363@samp{+} is used for describing a reservation described by the first
8364regular expression @strong{and} a reservation described by the
8365second regular expression @strong{and} etc.
8366
8367@item
8368@samp{*} is used for convenience and simply means a sequence in which
8369the regular expression are repeated @var{number} times with cycle
8370advancing (see @samp{,}).
8371
8372@item
8373@samp{cpu_function_unit_name} denotes reservation of the named
8374functional unit.
8375
8376@item
8377@samp{reservation_name} --- see description of construction
8378@samp{define_reservation}.
8379
8380@item
8381@samp{nothing} denotes no unit reservations.
8382@end itemize
8383
8384@findex define_reservation
8385Sometimes unit reservations for different insns contain common parts.
8386In such case, you can simplify the pipeline description by describing
8387the common part by the following construction
8388
8389@smallexample
8390(define_reservation @var{reservation-name} @var{regexp})
8391@end smallexample
8392
8393@var{reservation-name} is a string giving name of @var{regexp}.
8394Functional unit names and reservation names are in the same name
8395space. So the reservation names should be different from the
cc6a602b 8396functional unit names and can not be the reserved name @samp{nothing}.
fae15c93
VM
8397
8398@findex define_bypass
8399@cindex instruction latency time
8400@cindex data bypass
8401The following construction is used to describe exceptions in the
8402latency time for given instruction pair. This is so called bypasses.
8403
8404@smallexample
8405(define_bypass @var{number} @var{out_insn_names} @var{in_insn_names}
8406 [@var{guard}])
8407@end smallexample
8408
8409@var{number} defines when the result generated by the instructions
8410given in string @var{out_insn_names} will be ready for the
f9bf5a8e
RS
8411instructions given in string @var{in_insn_names}. Each of these
8412strings is a comma-separated list of filename-style globs and
8413they refer to the names of @code{define_insn_reservation}s.
8414For example:
8415@smallexample
8416(define_bypass 1 "cpu1_load_*, cpu1_store_*" "cpu1_load_*")
8417@end smallexample
8418defines a bypass between instructions that start with
8419@samp{cpu1_load_} or @samp{cpu1_store_} and those that start with
8420@samp{cpu1_load_}.
fae15c93 8421
ef261fee 8422@var{guard} is an optional string giving the name of a C function which
fae15c93
VM
8423defines an additional guard for the bypass. The function will get the
8424two insns as parameters. If the function returns zero the bypass will
8425be ignored for this case. The additional guard is necessary to
431ae0bf 8426recognize complicated bypasses, e.g.@: when the consumer is only an address
fae15c93
VM
8427of insn @samp{store} (not a stored value).
8428
20a07f44
VM
8429If there are more one bypass with the same output and input insns, the
8430chosen bypass is the first bypass with a guard in description whose
8431guard function returns nonzero. If there is no such bypass, then
8432bypass without the guard function is chosen.
8433
fae15c93
VM
8434@findex exclusion_set
8435@findex presence_set
30028c85 8436@findex final_presence_set
fae15c93 8437@findex absence_set
30028c85 8438@findex final_absence_set
fae15c93
VM
8439@cindex VLIW
8440@cindex RISC
cc6a602b
BE
8441The following five constructions are usually used to describe
8442@acronym{VLIW} processors, or more precisely, to describe a placement
8443of small instructions into @acronym{VLIW} instruction slots. They
8444can be used for @acronym{RISC} processors, too.
fae15c93
VM
8445
8446@smallexample
8447(exclusion_set @var{unit-names} @var{unit-names})
30028c85
VM
8448(presence_set @var{unit-names} @var{patterns})
8449(final_presence_set @var{unit-names} @var{patterns})
8450(absence_set @var{unit-names} @var{patterns})
8451(final_absence_set @var{unit-names} @var{patterns})
fae15c93
VM
8452@end smallexample
8453
8454@var{unit-names} is a string giving names of functional units
8455separated by commas.
8456
30028c85 8457@var{patterns} is a string giving patterns of functional units
0bdcd332 8458separated by comma. Currently pattern is one unit or units
30028c85
VM
8459separated by white-spaces.
8460
fae15c93
VM
8461The first construction (@samp{exclusion_set}) means that each
8462functional unit in the first string can not be reserved simultaneously
8463with a unit whose name is in the second string and vice versa. For
8464example, the construction is useful for describing processors
431ae0bf 8465(e.g.@: some SPARC processors) with a fully pipelined floating point
fae15c93
VM
8466functional unit which can execute simultaneously only single floating
8467point insns or only double floating point insns.
8468
8469The second construction (@samp{presence_set}) means that each
8470functional unit in the first string can not be reserved unless at
30028c85
VM
8471least one of pattern of units whose names are in the second string is
8472reserved. This is an asymmetric relation. For example, it is useful
8473for description that @acronym{VLIW} @samp{slot1} is reserved after
8474@samp{slot0} reservation. We could describe it by the following
8475construction
8476
8477@smallexample
8478(presence_set "slot1" "slot0")
8479@end smallexample
8480
8481Or @samp{slot1} is reserved only after @samp{slot0} and unit @samp{b0}
8482reservation. In this case we could write
8483
8484@smallexample
8485(presence_set "slot1" "slot0 b0")
8486@end smallexample
8487
8488The third construction (@samp{final_presence_set}) is analogous to
8489@samp{presence_set}. The difference between them is when checking is
8490done. When an instruction is issued in given automaton state
8491reflecting all current and planned unit reservations, the automaton
8492state is changed. The first state is a source state, the second one
8493is a result state. Checking for @samp{presence_set} is done on the
8494source state reservation, checking for @samp{final_presence_set} is
8495done on the result reservation. This construction is useful to
8496describe a reservation which is actually two subsequent reservations.
8497For example, if we use
8498
8499@smallexample
8500(presence_set "slot1" "slot0")
8501@end smallexample
8502
8503the following insn will be never issued (because @samp{slot1} requires
8504@samp{slot0} which is absent in the source state).
8505
8506@smallexample
8507(define_reservation "insn_and_nop" "slot0 + slot1")
8508@end smallexample
8509
8510but it can be issued if we use analogous @samp{final_presence_set}.
8511
8512The forth construction (@samp{absence_set}) means that each functional
8513unit in the first string can be reserved only if each pattern of units
8514whose names are in the second string is not reserved. This is an
8515asymmetric relation (actually @samp{exclusion_set} is analogous to
ff2ce160 8516this one but it is symmetric). For example it might be useful in a
a71b1c58
NC
8517@acronym{VLIW} description to say that @samp{slot0} cannot be reserved
8518after either @samp{slot1} or @samp{slot2} have been reserved. This
8519can be described as:
30028c85
VM
8520
8521@smallexample
a71b1c58 8522(absence_set "slot0" "slot1, slot2")
30028c85
VM
8523@end smallexample
8524
8525Or @samp{slot2} can not be reserved if @samp{slot0} and unit @samp{b0}
8526are reserved or @samp{slot1} and unit @samp{b1} are reserved. In
8527this case we could write
8528
8529@smallexample
8530(absence_set "slot2" "slot0 b0, slot1 b1")
8531@end smallexample
fae15c93 8532
ef261fee 8533All functional units mentioned in a set should belong to the same
fae15c93
VM
8534automaton.
8535
30028c85
VM
8536The last construction (@samp{final_absence_set}) is analogous to
8537@samp{absence_set} but checking is done on the result (state)
8538reservation. See comments for @samp{final_presence_set}.
8539
fae15c93
VM
8540@findex automata_option
8541@cindex deterministic finite state automaton
8542@cindex nondeterministic finite state automaton
8543@cindex finite state automaton minimization
8544You can control the generator of the pipeline hazard recognizer with
8545the following construction.
8546
8547@smallexample
8548(automata_option @var{options})
8549@end smallexample
8550
8551@var{options} is a string giving options which affect the generated
8552code. Currently there are the following options:
8553
8554@itemize @bullet
8555@item
8556@dfn{no-minimization} makes no minimization of the automaton. This is
30028c85
VM
8557only worth to do when we are debugging the description and need to
8558look more accurately at reservations of states.
fae15c93
VM
8559
8560@item
df1133a6
BE
8561@dfn{time} means printing time statistics about the generation of
8562automata.
8563
8564@item
8565@dfn{stats} means printing statistics about the generated automata
8566such as the number of DFA states, NDFA states and arcs.
e3c8eb86
VM
8567
8568@item
8569@dfn{v} means a generation of the file describing the result automata.
8570The file has suffix @samp{.dfa} and can be used for the description
8571verification and debugging.
8572
8573@item
8574@dfn{w} means a generation of warning instead of error for
8575non-critical errors.
fae15c93 8576
e12da141
BS
8577@item
8578@dfn{no-comb-vect} prevents the automaton generator from generating
8579two data structures and comparing them for space efficiency. Using
8580a comb vector to represent transitions may be better, but it can be
8581very expensive to construct. This option is useful if the build
8582process spends an unacceptably long time in genautomata.
8583
fae15c93
VM
8584@item
8585@dfn{ndfa} makes nondeterministic finite state automata. This affects
8586the treatment of operator @samp{|} in the regular expressions. The
8587usual treatment of the operator is to try the first alternative and,
8588if the reservation is not possible, the second alternative. The
8589nondeterministic treatment means trying all alternatives, some of them
96ddf8ef 8590may be rejected by reservations in the subsequent insns.
dfa849f3 8591
1e6a9047
BS
8592@item
8593@dfn{collapse-ndfa} modifies the behaviour of the generator when
8594producing an automaton. An additional state transition to collapse a
8595nondeterministic @acronym{NDFA} state to a deterministic @acronym{DFA}
8596state is generated. It can be triggered by passing @code{const0_rtx} to
8597state_transition. In such an automaton, cycle advance transitions are
8598available only for these collapsed states. This option is useful for
8599ports that want to use the @code{ndfa} option, but also want to use
8600@code{define_query_cpu_unit} to assign units to insns issued in a cycle.
8601
dfa849f3
VM
8602@item
8603@dfn{progress} means output of a progress bar showing how many states
8604were generated so far for automaton being processed. This is useful
8605during debugging a @acronym{DFA} description. If you see too many
8606generated states, you could interrupt the generator of the pipeline
8607hazard recognizer and try to figure out a reason for generation of the
8608huge automaton.
fae15c93
VM
8609@end itemize
8610
8611As an example, consider a superscalar @acronym{RISC} machine which can
8612issue three insns (two integer insns and one floating point insn) on
8613the cycle but can finish only two insns. To describe this, we define
8614the following functional units.
8615
8616@smallexample
8617(define_cpu_unit "i0_pipeline, i1_pipeline, f_pipeline")
ef261fee 8618(define_cpu_unit "port0, port1")
fae15c93
VM
8619@end smallexample
8620
8621All simple integer insns can be executed in any integer pipeline and
8622their result is ready in two cycles. The simple integer insns are
8623issued into the first pipeline unless it is reserved, otherwise they
8624are issued into the second pipeline. Integer division and
8625multiplication insns can be executed only in the second integer
8626pipeline and their results are ready correspondingly in 8 and 4
431ae0bf 8627cycles. The integer division is not pipelined, i.e.@: the subsequent
fae15c93
VM
8628integer division insn can not be issued until the current division
8629insn finished. Floating point insns are fully pipelined and their
ef261fee
R
8630results are ready in 3 cycles. Where the result of a floating point
8631insn is used by an integer insn, an additional delay of one cycle is
8632incurred. To describe all of this we could specify
fae15c93
VM
8633
8634@smallexample
8635(define_cpu_unit "div")
8636
68e4d4c5 8637(define_insn_reservation "simple" 2 (eq_attr "type" "int")
ef261fee 8638 "(i0_pipeline | i1_pipeline), (port0 | port1)")
fae15c93 8639
68e4d4c5 8640(define_insn_reservation "mult" 4 (eq_attr "type" "mult")
ef261fee 8641 "i1_pipeline, nothing*2, (port0 | port1)")
fae15c93 8642
68e4d4c5 8643(define_insn_reservation "div" 8 (eq_attr "type" "div")
ef261fee 8644 "i1_pipeline, div*7, div + (port0 | port1)")
fae15c93 8645
68e4d4c5 8646(define_insn_reservation "float" 3 (eq_attr "type" "float")
ef261fee 8647 "f_pipeline, nothing, (port0 | port1))
fae15c93 8648
ef261fee 8649(define_bypass 4 "float" "simple,mult,div")
fae15c93
VM
8650@end smallexample
8651
8652To simplify the description we could describe the following reservation
8653
8654@smallexample
8655(define_reservation "finish" "port0|port1")
8656@end smallexample
8657
8658and use it in all @code{define_insn_reservation} as in the following
8659construction
8660
8661@smallexample
68e4d4c5 8662(define_insn_reservation "simple" 2 (eq_attr "type" "int")
fae15c93
VM
8663 "(i0_pipeline | i1_pipeline), finish")
8664@end smallexample
8665
8666
a5249a21
HPN
8667@end ifset
8668@ifset INTERNALS
3262c1f5
RH
8669@node Conditional Execution
8670@section Conditional Execution
8671@cindex conditional execution
8672@cindex predication
8673
8674A number of architectures provide for some form of conditional
8675execution, or predication. The hallmark of this feature is the
8676ability to nullify most of the instructions in the instruction set.
8677When the instruction set is large and not entirely symmetric, it
8678can be quite tedious to describe these forms directly in the
8679@file{.md} file. An alternative is the @code{define_cond_exec} template.
8680
8681@findex define_cond_exec
8682@smallexample
8683(define_cond_exec
8684 [@var{predicate-pattern}]
8685 "@var{condition}"
630d3d5a 8686 "@var{output-template}")
3262c1f5
RH
8687@end smallexample
8688
8689@var{predicate-pattern} is the condition that must be true for the
8690insn to be executed at runtime and should match a relational operator.
8691One can use @code{match_operator} to match several relational operators
8692at once. Any @code{match_operand} operands must have no more than one
8693alternative.
8694
8695@var{condition} is a C expression that must be true for the generated
8696pattern to match.
8697
8698@findex current_insn_predicate
630d3d5a 8699@var{output-template} is a string similar to the @code{define_insn}
3262c1f5
RH
8700output template (@pxref{Output Template}), except that the @samp{*}
8701and @samp{@@} special cases do not apply. This is only useful if the
8702assembly text for the predicate is a simple prefix to the main insn.
8703In order to handle the general case, there is a global variable
8704@code{current_insn_predicate} that will contain the entire predicate
8705if the current insn is predicated, and will otherwise be @code{NULL}.
8706
ebb48a4d
JM
8707When @code{define_cond_exec} is used, an implicit reference to
8708the @code{predicable} instruction attribute is made.
0bddee8e
BS
8709@xref{Insn Attributes}. This attribute must be a boolean (i.e.@: have
8710exactly two elements in its @var{list-of-values}), with the possible
8711values being @code{no} and @code{yes}. The default and all uses in
8712the insns must be a simple constant, not a complex expressions. It
8713may, however, depend on the alternative, by using a comma-separated
8714list of values. If that is the case, the port should also define an
8715@code{enabled} attribute (@pxref{Disable Insn Alternatives}), which
8716should also allow only @code{no} and @code{yes} as its values.
3262c1f5 8717
ebb48a4d 8718For each @code{define_insn} for which the @code{predicable}
3262c1f5
RH
8719attribute is true, a new @code{define_insn} pattern will be
8720generated that matches a predicated version of the instruction.
8721For example,
8722
8723@smallexample
8724(define_insn "addsi"
8725 [(set (match_operand:SI 0 "register_operand" "r")
8726 (plus:SI (match_operand:SI 1 "register_operand" "r")
8727 (match_operand:SI 2 "register_operand" "r")))]
8728 "@var{test1}"
8729 "add %2,%1,%0")
8730
8731(define_cond_exec
8732 [(ne (match_operand:CC 0 "register_operand" "c")
8733 (const_int 0))]
8734 "@var{test2}"
8735 "(%0)")
8736@end smallexample
8737
8738@noindent
8739generates a new pattern
8740
8741@smallexample
8742(define_insn ""
8743 [(cond_exec
8744 (ne (match_operand:CC 3 "register_operand" "c") (const_int 0))
8745 (set (match_operand:SI 0 "register_operand" "r")
8746 (plus:SI (match_operand:SI 1 "register_operand" "r")
8747 (match_operand:SI 2 "register_operand" "r"))))]
8748 "(@var{test2}) && (@var{test1})"
8749 "(%3) add %2,%1,%0")
8750@end smallexample
c25c12b8 8751
a5249a21
HPN
8752@end ifset
8753@ifset INTERNALS
c25c12b8
R
8754@node Constant Definitions
8755@section Constant Definitions
8756@cindex constant definitions
8757@findex define_constants
8758
8759Using literal constants inside instruction patterns reduces legibility and
8760can be a maintenance problem.
8761
8762To overcome this problem, you may use the @code{define_constants}
8763expression. It contains a vector of name-value pairs. From that
8764point on, wherever any of the names appears in the MD file, it is as
8765if the corresponding value had been written instead. You may use
8766@code{define_constants} multiple times; each appearance adds more
8767constants to the table. It is an error to redefine a constant with
8768a different value.
8769
8770To come back to the a29k load multiple example, instead of
8771
8772@smallexample
8773(define_insn ""
8774 [(match_parallel 0 "load_multiple_operation"
8775 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
8776 (match_operand:SI 2 "memory_operand" "m"))
8777 (use (reg:SI 179))
8778 (clobber (reg:SI 179))])]
8779 ""
8780 "loadm 0,0,%1,%2")
8781@end smallexample
8782
8783You could write:
8784
8785@smallexample
8786(define_constants [
8787 (R_BP 177)
8788 (R_FC 178)
8789 (R_CR 179)
8790 (R_Q 180)
8791])
8792
8793(define_insn ""
8794 [(match_parallel 0 "load_multiple_operation"
8795 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
8796 (match_operand:SI 2 "memory_operand" "m"))
8797 (use (reg:SI R_CR))
8798 (clobber (reg:SI R_CR))])]
8799 ""
8800 "loadm 0,0,%1,%2")
8801@end smallexample
8802
8803The constants that are defined with a define_constant are also output
8804in the insn-codes.h header file as #defines.
24609606
RS
8805
8806@cindex enumerations
8807@findex define_c_enum
8808You can also use the machine description file to define enumerations.
8809Like the constants defined by @code{define_constant}, these enumerations
8810are visible to both the machine description file and the main C code.
8811
8812The syntax is as follows:
8813
8814@smallexample
8815(define_c_enum "@var{name}" [
8816 @var{value0}
8817 @var{value1}
8818 @dots{}
8819 @var{valuen}
8820])
8821@end smallexample
8822
8823This definition causes the equivalent of the following C code to appear
8824in @file{insn-constants.h}:
8825
8826@smallexample
8827enum @var{name} @{
8828 @var{value0} = 0,
8829 @var{value1} = 1,
8830 @dots{}
8831 @var{valuen} = @var{n}
8832@};
8833#define NUM_@var{cname}_VALUES (@var{n} + 1)
8834@end smallexample
8835
8836where @var{cname} is the capitalized form of @var{name}.
8837It also makes each @var{valuei} available in the machine description
8838file, just as if it had been declared with:
8839
8840@smallexample
8841(define_constants [(@var{valuei} @var{i})])
8842@end smallexample
8843
8844Each @var{valuei} is usually an upper-case identifier and usually
8845begins with @var{cname}.
8846
8847You can split the enumeration definition into as many statements as
8848you like. The above example is directly equivalent to:
8849
8850@smallexample
8851(define_c_enum "@var{name}" [@var{value0}])
8852(define_c_enum "@var{name}" [@var{value1}])
8853@dots{}
8854(define_c_enum "@var{name}" [@var{valuen}])
8855@end smallexample
8856
8857Splitting the enumeration helps to improve the modularity of each
8858individual @code{.md} file. For example, if a port defines its
8859synchronization instructions in a separate @file{sync.md} file,
8860it is convenient to define all synchronization-specific enumeration
8861values in @file{sync.md} rather than in the main @file{.md} file.
8862
0fe60a1b
RS
8863Some enumeration names have special significance to GCC:
8864
8865@table @code
8866@item unspecv
8867@findex unspec_volatile
8868If an enumeration called @code{unspecv} is defined, GCC will use it
8869when printing out @code{unspec_volatile} expressions. For example:
8870
8871@smallexample
8872(define_c_enum "unspecv" [
8873 UNSPECV_BLOCKAGE
8874])
8875@end smallexample
8876
8877causes GCC to print @samp{(unspec_volatile @dots{} 0)} as:
8878
8879@smallexample
8880(unspec_volatile ... UNSPECV_BLOCKAGE)
8881@end smallexample
8882
8883@item unspec
8884@findex unspec
8885If an enumeration called @code{unspec} is defined, GCC will use
8886it when printing out @code{unspec} expressions. GCC will also use
8887it when printing out @code{unspec_volatile} expressions unless an
8888@code{unspecv} enumeration is also defined. You can therefore
8889decide whether to keep separate enumerations for volatile and
8890non-volatile expressions or whether to use the same enumeration
8891for both.
8892@end table
8893
24609606 8894@findex define_enum
8f4fe86c 8895@anchor{define_enum}
24609606
RS
8896Another way of defining an enumeration is to use @code{define_enum}:
8897
8898@smallexample
8899(define_enum "@var{name}" [
8900 @var{value0}
8901 @var{value1}
8902 @dots{}
8903 @var{valuen}
8904])
8905@end smallexample
8906
8907This directive implies:
8908
8909@smallexample
8910(define_c_enum "@var{name}" [
8911 @var{cname}_@var{cvalue0}
8912 @var{cname}_@var{cvalue1}
8913 @dots{}
8914 @var{cname}_@var{cvaluen}
8915])
8916@end smallexample
8917
8f4fe86c 8918@findex define_enum_attr
24609606 8919where @var{cvaluei} is the capitalized form of @var{valuei}.
8f4fe86c
RS
8920However, unlike @code{define_c_enum}, the enumerations defined
8921by @code{define_enum} can be used in attribute specifications
8922(@pxref{define_enum_attr}).
b11cc610 8923@end ifset
032e8348 8924@ifset INTERNALS
3abcb3a7
HPN
8925@node Iterators
8926@section Iterators
8927@cindex iterators in @file{.md} files
032e8348
RS
8928
8929Ports often need to define similar patterns for more than one machine
3abcb3a7 8930mode or for more than one rtx code. GCC provides some simple iterator
032e8348
RS
8931facilities to make this process easier.
8932
8933@menu
3abcb3a7
HPN
8934* Mode Iterators:: Generating variations of patterns for different modes.
8935* Code Iterators:: Doing the same for codes.
57a4717b 8936* Int Iterators:: Doing the same for integers.
032e8348
RS
8937@end menu
8938
3abcb3a7
HPN
8939@node Mode Iterators
8940@subsection Mode Iterators
8941@cindex mode iterators in @file{.md} files
032e8348
RS
8942
8943Ports often need to define similar patterns for two or more different modes.
8944For example:
8945
8946@itemize @bullet
8947@item
8948If a processor has hardware support for both single and double
8949floating-point arithmetic, the @code{SFmode} patterns tend to be
8950very similar to the @code{DFmode} ones.
8951
8952@item
8953If a port uses @code{SImode} pointers in one configuration and
8954@code{DImode} pointers in another, it will usually have very similar
8955@code{SImode} and @code{DImode} patterns for manipulating pointers.
8956@end itemize
8957
3abcb3a7 8958Mode iterators allow several patterns to be instantiated from one
032e8348
RS
8959@file{.md} file template. They can be used with any type of
8960rtx-based construct, such as a @code{define_insn},
8961@code{define_split}, or @code{define_peephole2}.
8962
8963@menu
3abcb3a7 8964* Defining Mode Iterators:: Defining a new mode iterator.
6ccde948
RW
8965* Substitutions:: Combining mode iterators with substitutions
8966* Examples:: Examples
032e8348
RS
8967@end menu
8968
3abcb3a7
HPN
8969@node Defining Mode Iterators
8970@subsubsection Defining Mode Iterators
8971@findex define_mode_iterator
032e8348 8972
3abcb3a7 8973The syntax for defining a mode iterator is:
032e8348
RS
8974
8975@smallexample
923158be 8976(define_mode_iterator @var{name} [(@var{mode1} "@var{cond1}") @dots{} (@var{moden} "@var{condn}")])
032e8348
RS
8977@end smallexample
8978
8979This allows subsequent @file{.md} file constructs to use the mode suffix
8980@code{:@var{name}}. Every construct that does so will be expanded
8981@var{n} times, once with every use of @code{:@var{name}} replaced by
8982@code{:@var{mode1}}, once with every use replaced by @code{:@var{mode2}},
8983and so on. In the expansion for a particular @var{modei}, every
8984C condition will also require that @var{condi} be true.
8985
8986For example:
8987
8988@smallexample
3abcb3a7 8989(define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
032e8348
RS
8990@end smallexample
8991
8992defines a new mode suffix @code{:P}. Every construct that uses
8993@code{:P} will be expanded twice, once with every @code{:P} replaced
8994by @code{:SI} and once with every @code{:P} replaced by @code{:DI}.
8995The @code{:SI} version will only apply if @code{Pmode == SImode} and
8996the @code{:DI} version will only apply if @code{Pmode == DImode}.
8997
8998As with other @file{.md} conditions, an empty string is treated
8999as ``always true''. @code{(@var{mode} "")} can also be abbreviated
9000to @code{@var{mode}}. For example:
9001
9002@smallexample
3abcb3a7 9003(define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
032e8348
RS
9004@end smallexample
9005
9006means that the @code{:DI} expansion only applies if @code{TARGET_64BIT}
9007but that the @code{:SI} expansion has no such constraint.
9008
3abcb3a7
HPN
9009Iterators are applied in the order they are defined. This can be
9010significant if two iterators are used in a construct that requires
f30990b2 9011substitutions. @xref{Substitutions}.
032e8348 9012
f30990b2 9013@node Substitutions
3abcb3a7 9014@subsubsection Substitution in Mode Iterators
032e8348
RS
9015@findex define_mode_attr
9016
3abcb3a7 9017If an @file{.md} file construct uses mode iterators, each version of the
f30990b2
ILT
9018construct will often need slightly different strings or modes. For
9019example:
032e8348
RS
9020
9021@itemize @bullet
9022@item
9023When a @code{define_expand} defines several @code{add@var{m}3} patterns
9024(@pxref{Standard Names}), each expander will need to use the
9025appropriate mode name for @var{m}.
9026
9027@item
9028When a @code{define_insn} defines several instruction patterns,
9029each instruction will often use a different assembler mnemonic.
f30990b2
ILT
9030
9031@item
9032When a @code{define_insn} requires operands with different modes,
3abcb3a7 9033using an iterator for one of the operand modes usually requires a specific
f30990b2 9034mode for the other operand(s).
032e8348
RS
9035@end itemize
9036
9037GCC supports such variations through a system of ``mode attributes''.
9038There are two standard attributes: @code{mode}, which is the name of
9039the mode in lower case, and @code{MODE}, which is the same thing in
9040upper case. You can define other attributes using:
9041
9042@smallexample
923158be 9043(define_mode_attr @var{name} [(@var{mode1} "@var{value1}") @dots{} (@var{moden} "@var{valuen}")])
032e8348
RS
9044@end smallexample
9045
9046where @var{name} is the name of the attribute and @var{valuei}
9047is the value associated with @var{modei}.
9048
3abcb3a7 9049When GCC replaces some @var{:iterator} with @var{:mode}, it will scan
f30990b2 9050each string and mode in the pattern for sequences of the form
3abcb3a7 9051@code{<@var{iterator}:@var{attr}>}, where @var{attr} is the name of a
f30990b2 9052mode attribute. If the attribute is defined for @var{mode}, the whole
923158be 9053@code{<@dots{}>} sequence will be replaced by the appropriate attribute
f30990b2 9054value.
032e8348
RS
9055
9056For example, suppose an @file{.md} file has:
9057
9058@smallexample
3abcb3a7 9059(define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
032e8348
RS
9060(define_mode_attr load [(SI "lw") (DI "ld")])
9061@end smallexample
9062
9063If one of the patterns that uses @code{:P} contains the string
9064@code{"<P:load>\t%0,%1"}, the @code{SI} version of that pattern
9065will use @code{"lw\t%0,%1"} and the @code{DI} version will use
9066@code{"ld\t%0,%1"}.
9067
f30990b2
ILT
9068Here is an example of using an attribute for a mode:
9069
9070@smallexample
3abcb3a7 9071(define_mode_iterator LONG [SI DI])
f30990b2 9072(define_mode_attr SHORT [(SI "HI") (DI "SI")])
923158be
RW
9073(define_insn @dots{}
9074 (sign_extend:LONG (match_operand:<LONG:SHORT> @dots{})) @dots{})
f30990b2
ILT
9075@end smallexample
9076
3abcb3a7
HPN
9077The @code{@var{iterator}:} prefix may be omitted, in which case the
9078substitution will be attempted for every iterator expansion.
032e8348
RS
9079
9080@node Examples
3abcb3a7 9081@subsubsection Mode Iterator Examples
032e8348
RS
9082
9083Here is an example from the MIPS port. It defines the following
9084modes and attributes (among others):
9085
9086@smallexample
3abcb3a7 9087(define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
032e8348
RS
9088(define_mode_attr d [(SI "") (DI "d")])
9089@end smallexample
9090
9091and uses the following template to define both @code{subsi3}
9092and @code{subdi3}:
9093
9094@smallexample
9095(define_insn "sub<mode>3"
9096 [(set (match_operand:GPR 0 "register_operand" "=d")
9097 (minus:GPR (match_operand:GPR 1 "register_operand" "d")
9098 (match_operand:GPR 2 "register_operand" "d")))]
9099 ""
9100 "<d>subu\t%0,%1,%2"
9101 [(set_attr "type" "arith")
9102 (set_attr "mode" "<MODE>")])
9103@end smallexample
9104
9105This is exactly equivalent to:
9106
9107@smallexample
9108(define_insn "subsi3"
9109 [(set (match_operand:SI 0 "register_operand" "=d")
9110 (minus:SI (match_operand:SI 1 "register_operand" "d")
9111 (match_operand:SI 2 "register_operand" "d")))]
9112 ""
9113 "subu\t%0,%1,%2"
9114 [(set_attr "type" "arith")
9115 (set_attr "mode" "SI")])
9116
9117(define_insn "subdi3"
9118 [(set (match_operand:DI 0 "register_operand" "=d")
9119 (minus:DI (match_operand:DI 1 "register_operand" "d")
9120 (match_operand:DI 2 "register_operand" "d")))]
9121 ""
9122 "dsubu\t%0,%1,%2"
9123 [(set_attr "type" "arith")
9124 (set_attr "mode" "DI")])
9125@end smallexample
9126
3abcb3a7
HPN
9127@node Code Iterators
9128@subsection Code Iterators
9129@cindex code iterators in @file{.md} files
9130@findex define_code_iterator
032e8348
RS
9131@findex define_code_attr
9132
3abcb3a7 9133Code iterators operate in a similar way to mode iterators. @xref{Mode Iterators}.
032e8348
RS
9134
9135The construct:
9136
9137@smallexample
923158be 9138(define_code_iterator @var{name} [(@var{code1} "@var{cond1}") @dots{} (@var{coden} "@var{condn}")])
032e8348
RS
9139@end smallexample
9140
9141defines a pseudo rtx code @var{name} that can be instantiated as
9142@var{codei} if condition @var{condi} is true. Each @var{codei}
9143must have the same rtx format. @xref{RTL Classes}.
9144
3abcb3a7 9145As with mode iterators, each pattern that uses @var{name} will be
032e8348
RS
9146expanded @var{n} times, once with all uses of @var{name} replaced by
9147@var{code1}, once with all uses replaced by @var{code2}, and so on.
3abcb3a7 9148@xref{Defining Mode Iterators}.
032e8348
RS
9149
9150It is possible to define attributes for codes as well as for modes.
9151There are two standard code attributes: @code{code}, the name of the
9152code in lower case, and @code{CODE}, the name of the code in upper case.
9153Other attributes are defined using:
9154
9155@smallexample
923158be 9156(define_code_attr @var{name} [(@var{code1} "@var{value1}") @dots{} (@var{coden} "@var{valuen}")])
032e8348
RS
9157@end smallexample
9158
3abcb3a7 9159Here's an example of code iterators in action, taken from the MIPS port:
032e8348
RS
9160
9161@smallexample
3abcb3a7
HPN
9162(define_code_iterator any_cond [unordered ordered unlt unge uneq ltgt unle ungt
9163 eq ne gt ge lt le gtu geu ltu leu])
032e8348
RS
9164
9165(define_expand "b<code>"
9166 [(set (pc)
9167 (if_then_else (any_cond:CC (cc0)
9168 (const_int 0))
9169 (label_ref (match_operand 0 ""))
9170 (pc)))]
9171 ""
9172@{
9173 gen_conditional_branch (operands, <CODE>);
9174 DONE;
9175@})
9176@end smallexample
9177
9178This is equivalent to:
9179
9180@smallexample
9181(define_expand "bunordered"
9182 [(set (pc)
9183 (if_then_else (unordered:CC (cc0)
9184 (const_int 0))
9185 (label_ref (match_operand 0 ""))
9186 (pc)))]
9187 ""
9188@{
9189 gen_conditional_branch (operands, UNORDERED);
9190 DONE;
9191@})
9192
9193(define_expand "bordered"
9194 [(set (pc)
9195 (if_then_else (ordered:CC (cc0)
9196 (const_int 0))
9197 (label_ref (match_operand 0 ""))
9198 (pc)))]
9199 ""
9200@{
9201 gen_conditional_branch (operands, ORDERED);
9202 DONE;
9203@})
9204
923158be 9205@dots{}
032e8348
RS
9206@end smallexample
9207
57a4717b
TB
9208@node Int Iterators
9209@subsection Int Iterators
9210@cindex int iterators in @file{.md} files
9211@findex define_int_iterator
9212@findex define_int_attr
9213
9214Int iterators operate in a similar way to code iterators. @xref{Code Iterators}.
9215
9216The construct:
9217
9218@smallexample
9219(define_int_iterator @var{name} [(@var{int1} "@var{cond1}") @dots{} (@var{intn} "@var{condn}")])
9220@end smallexample
9221
9222defines a pseudo integer constant @var{name} that can be instantiated as
9223@var{inti} if condition @var{condi} is true. Each @var{int}
9224must have the same rtx format. @xref{RTL Classes}. Int iterators can appear
9225in only those rtx fields that have 'i' as the specifier. This means that
9226each @var{int} has to be a constant defined using define_constant or
9227define_c_enum.
9228
9229As with mode and code iterators, each pattern that uses @var{name} will be
9230expanded @var{n} times, once with all uses of @var{name} replaced by
9231@var{int1}, once with all uses replaced by @var{int2}, and so on.
9232@xref{Defining Mode Iterators}.
9233
9234It is possible to define attributes for ints as well as for codes and modes.
9235Attributes are defined using:
9236
9237@smallexample
9238(define_int_attr @var{name} [(@var{int1} "@var{value1}") @dots{} (@var{intn} "@var{valuen}")])
9239@end smallexample
9240
9241Here's an example of int iterators in action, taken from the ARM port:
9242
9243@smallexample
9244(define_int_iterator QABSNEG [UNSPEC_VQABS UNSPEC_VQNEG])
9245
9246(define_int_attr absneg [(UNSPEC_VQABS "abs") (UNSPEC_VQNEG "neg")])
9247
9248(define_insn "neon_vq<absneg><mode>"
9249 [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
9250 (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
9251 (match_operand:SI 2 "immediate_operand" "i")]
9252 QABSNEG))]
9253 "TARGET_NEON"
9254 "vq<absneg>.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
9255 [(set_attr "neon_type" "neon_vqneg_vqabs")]
9256)
9257
9258@end smallexample
9259
9260This is equivalent to:
9261
9262@smallexample
9263(define_insn "neon_vqabs<mode>"
9264 [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
9265 (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
9266 (match_operand:SI 2 "immediate_operand" "i")]
9267 UNSPEC_VQABS))]
9268 "TARGET_NEON"
9269 "vqabs.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
9270 [(set_attr "neon_type" "neon_vqneg_vqabs")]
9271)
9272
9273(define_insn "neon_vqneg<mode>"
9274 [(set (match_operand:VDQIW 0 "s_register_operand" "=w")
9275 (unspec:VDQIW [(match_operand:VDQIW 1 "s_register_operand" "w")
9276 (match_operand:SI 2 "immediate_operand" "i")]
9277 UNSPEC_VQNEG))]
9278 "TARGET_NEON"
9279 "vqneg.<V_s_elem>\t%<V_reg>0, %<V_reg>1"
9280 [(set_attr "neon_type" "neon_vqneg_vqabs")]
9281)
9282
9283@end smallexample
9284
032e8348 9285@end ifset