]> gcc.gnu.org Git - gcc.git/blame - gcc/doc/md.texi
basic-block.h: Fix comment formatting.
[gcc.git] / gcc / doc / md.texi
CommitLineData
b5e01d4b
RS
1@c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001,
2@c 2002, 2003 Free Software Foundation, Inc.
03dda8e3
RK
3@c This is part of the GCC manual.
4@c For copying conditions, see the file gcc.texi.
5
6@ifset INTERNALS
7@node Machine Desc
8@chapter Machine Descriptions
9@cindex machine descriptions
10
11A machine description has two parts: a file of instruction patterns
12(@file{.md} file) and a C header file of macro definitions.
13
14The @file{.md} file for a target machine contains a pattern for each
15instruction that the target machine supports (or at least each instruction
16that is worth telling the compiler about). It may also contain comments.
17A semicolon causes the rest of the line to be a comment, unless the semicolon
18is inside a quoted string.
19
20See the next chapter for information on the C header file.
21
22@menu
55e4756f 23* Overview:: How the machine description is used.
03dda8e3
RK
24* Patterns:: How to write instruction patterns.
25* Example:: An explained example of a @code{define_insn} pattern.
26* RTL Template:: The RTL template defines what insns match a pattern.
27* Output Template:: The output template says how to make assembler code
28 from such an insn.
29* Output Statement:: For more generality, write C code to output
30 the assembler code.
31* Constraints:: When not all operands are general operands.
32* Standard Names:: Names mark patterns to use for code generation.
33* Pattern Ordering:: When the order of patterns makes a difference.
34* Dependent Patterns:: Having one pattern may make you need another.
35* Jump Patterns:: Special considerations for patterns for jump insns.
6e4fcc95 36* Looping Patterns:: How to define patterns for special looping insns.
03dda8e3 37* Insn Canonicalizations::Canonicalization of Instructions
03dda8e3 38* Expander Definitions::Generating a sequence of several RTL insns
f3a3d0d3
RH
39 for a standard operation.
40* Insn Splitting:: Splitting Instructions into Multiple Instructions.
04d8aa70 41* Including Patterns:: Including Patterns in Machine Descriptions.
f3a3d0d3 42* Peephole Definitions::Defining machine-specific peephole optimizations.
03dda8e3 43* Insn Attributes:: Specifying the value of attributes for generated insns.
3262c1f5
RH
44* Conditional Execution::Generating @code{define_insn} patterns for
45 predication.
c25c12b8
R
46* Constant Definitions::Defining symbolic constants that can be used in the
47 md file.
03dda8e3
RK
48@end menu
49
55e4756f
DD
50@node Overview
51@section Overview of How the Machine Description is Used
52
53There are three main conversions that happen in the compiler:
54
55@enumerate
56
57@item
58The front end reads the source code and builds a parse tree.
59
60@item
61The parse tree is used to generate an RTL insn list based on named
62instruction patterns.
63
64@item
65The insn list is matched against the RTL templates to produce assembler
66code.
67
68@end enumerate
69
70For the generate pass, only the names of the insns matter, from either a
71named @code{define_insn} or a @code{define_expand}. The compiler will
72choose the pattern with the right name and apply the operands according
73to the documentation later in this chapter, without regard for the RTL
74template or operand constraints. Note that the names the compiler looks
d7d9c429 75for are hard-coded in the compiler---it will ignore unnamed patterns and
55e4756f
DD
76patterns with names it doesn't know about, but if you don't provide a
77named pattern it needs, it will abort.
78
79If a @code{define_insn} is used, the template given is inserted into the
80insn list. If a @code{define_expand} is used, one of three things
81happens, based on the condition logic. The condition logic may manually
82create new insns for the insn list, say via @code{emit_insn()}, and
aee96fe9 83invoke @code{DONE}. For certain named patterns, it may invoke @code{FAIL} to tell the
55e4756f
DD
84compiler to use an alternate way of performing that task. If it invokes
85neither @code{DONE} nor @code{FAIL}, the template given in the pattern
86is inserted, as if the @code{define_expand} were a @code{define_insn}.
87
88Once the insn list is generated, various optimization passes convert,
89replace, and rearrange the insns in the insn list. This is where the
90@code{define_split} and @code{define_peephole} patterns get used, for
91example.
92
93Finally, the insn list's RTL is matched up with the RTL templates in the
94@code{define_insn} patterns, and those patterns are used to emit the
95final assembly code. For this purpose, each named @code{define_insn}
96acts like it's unnamed, since the names are ignored.
97
03dda8e3
RK
98@node Patterns
99@section Everything about Instruction Patterns
100@cindex patterns
101@cindex instruction patterns
102
103@findex define_insn
104Each instruction pattern contains an incomplete RTL expression, with pieces
105to be filled in later, operand constraints that restrict how the pieces can
106be filled in, and an output pattern or C code to generate the assembler
107output, all wrapped up in a @code{define_insn} expression.
108
109A @code{define_insn} is an RTL expression containing four or five operands:
110
111@enumerate
112@item
113An optional name. The presence of a name indicate that this instruction
114pattern can perform a certain standard job for the RTL-generation
115pass of the compiler. This pass knows certain names and will use
116the instruction patterns with those names, if the names are defined
117in the machine description.
118
119The absence of a name is indicated by writing an empty string
120where the name should go. Nameless instruction patterns are never
121used for generating RTL code, but they may permit several simpler insns
122to be combined later on.
123
124Names that are not thus known and used in RTL-generation have no
125effect; they are equivalent to no name at all.
126
661cb0b7
RK
127For the purpose of debugging the compiler, you may also specify a
128name beginning with the @samp{*} character. Such a name is used only
129for identifying the instruction in RTL dumps; it is entirely equivalent
130to having a nameless pattern for all other purposes.
131
03dda8e3
RK
132@item
133The @dfn{RTL template} (@pxref{RTL Template}) is a vector of incomplete
134RTL expressions which show what the instruction should look like. It is
135incomplete because it may contain @code{match_operand},
136@code{match_operator}, and @code{match_dup} expressions that stand for
137operands of the instruction.
138
139If the vector has only one element, that element is the template for the
140instruction pattern. If the vector has multiple elements, then the
141instruction pattern is a @code{parallel} expression containing the
142elements described.
143
144@item
145@cindex pattern conditions
146@cindex conditions, in patterns
147A condition. This is a string which contains a C expression that is
148the final test to decide whether an insn body matches this pattern.
149
150@cindex named patterns and conditions
151For a named pattern, the condition (if present) may not depend on
152the data in the insn being matched, but only the target-machine-type
153flags. The compiler needs to test these conditions during
154initialization in order to learn exactly which named instructions are
155available in a particular run.
156
157@findex operands
158For nameless patterns, the condition is applied only when matching an
159individual insn, and only after the insn has matched the pattern's
160recognition template. The insn's operands may be found in the vector
fde6d81f
HPN
161@code{operands}. For an insn where the condition has once matched, it
162can't be used to control register allocation, for example by excluding
163certain hard registers or hard register combinations.
03dda8e3
RK
164
165@item
166The @dfn{output template}: a string that says how to output matching
167insns as assembler code. @samp{%} in this string specifies where
168to substitute the value of an operand. @xref{Output Template}.
169
170When simple substitution isn't general enough, you can specify a piece
171of C code to compute the output. @xref{Output Statement}.
172
173@item
174Optionally, a vector containing the values of attributes for insns matching
175this pattern. @xref{Insn Attributes}.
176@end enumerate
177
178@node Example
179@section Example of @code{define_insn}
180@cindex @code{define_insn} example
181
182Here is an actual example of an instruction pattern, for the 68000/68020.
183
184@example
185(define_insn "tstsi"
186 [(set (cc0)
187 (match_operand:SI 0 "general_operand" "rm"))]
188 ""
189 "*
f282ffb3 190@{
0f40f9f7 191 if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
03dda8e3 192 return \"tstl %0\";
f282ffb3 193 return \"cmpl #0,%0\";
0f40f9f7
ZW
194@}")
195@end example
196
197@noindent
198This can also be written using braced strings:
199
200@example
201(define_insn "tstsi"
202 [(set (cc0)
203 (match_operand:SI 0 "general_operand" "rm"))]
204 ""
f282ffb3 205@{
0f40f9f7
ZW
206 if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
207 return "tstl %0";
f282ffb3 208 return "cmpl #0,%0";
0f40f9f7 209@})
03dda8e3
RK
210@end example
211
212This is an instruction that sets the condition codes based on the value of
213a general operand. It has no condition, so any insn whose RTL description
214has the form shown may be handled according to this pattern. The name
215@samp{tstsi} means ``test a @code{SImode} value'' and tells the RTL generation
216pass that, when it is necessary to test such a value, an insn to do so
217can be constructed using this pattern.
218
219The output control string is a piece of C code which chooses which
220output template to return based on the kind of operand and the specific
221type of CPU for which code is being generated.
222
223@samp{"rm"} is an operand constraint. Its meaning is explained below.
224
225@node RTL Template
226@section RTL Template
227@cindex RTL insn template
228@cindex generating insns
229@cindex insns, generating
230@cindex recognizing insns
231@cindex insns, recognizing
232
233The RTL template is used to define which insns match the particular pattern
234and how to find their operands. For named patterns, the RTL template also
235says how to construct an insn from specified operands.
236
237Construction involves substituting specified operands into a copy of the
238template. Matching involves determining the values that serve as the
239operands in the insn being matched. Both of these activities are
240controlled by special expression types that direct matching and
241substitution of the operands.
242
243@table @code
244@findex match_operand
245@item (match_operand:@var{m} @var{n} @var{predicate} @var{constraint})
246This expression is a placeholder for operand number @var{n} of
247the insn. When constructing an insn, operand number @var{n}
248will be substituted at this point. When matching an insn, whatever
249appears at this position in the insn will be taken as operand
250number @var{n}; but it must satisfy @var{predicate} or this instruction
251pattern will not match at all.
252
253Operand numbers must be chosen consecutively counting from zero in
254each instruction pattern. There may be only one @code{match_operand}
255expression in the pattern for each operand number. Usually operands
256are numbered in the order of appearance in @code{match_operand}
72938a4c
MM
257expressions. In the case of a @code{define_expand}, any operand numbers
258used only in @code{match_dup} expressions have higher values than all
259other operand numbers.
03dda8e3
RK
260
261@var{predicate} is a string that is the name of a C function that accepts two
262arguments, an expression and a machine mode. During matching, the
263function will be called with the putative operand as the expression and
264@var{m} as the mode argument (if @var{m} is not specified,
265@code{VOIDmode} will be used, which normally causes @var{predicate} to accept
266any mode). If it returns zero, this instruction pattern fails to match.
267@var{predicate} may be an empty string; then it means no test is to be done
268on the operand, so anything which occurs in this position is valid.
269
270Most of the time, @var{predicate} will reject modes other than @var{m}---but
271not always. For example, the predicate @code{address_operand} uses
272@var{m} as the mode of memory ref that the address should be valid for.
273Many predicates accept @code{const_int} nodes even though their mode is
274@code{VOIDmode}.
275
276@var{constraint} controls reloading and the choice of the best register
277class to use for a value, as explained later (@pxref{Constraints}).
278
279People are often unclear on the difference between the constraint and the
280predicate. The predicate helps decide whether a given insn matches the
281pattern. The constraint plays no role in this decision; instead, it
282controls various decisions in the case of an insn which does match.
283
284@findex general_operand
285On CISC machines, the most common @var{predicate} is
286@code{"general_operand"}. This function checks that the putative
287operand is either a constant, a register or a memory reference, and that
288it is valid for mode @var{m}.
289
290@findex register_operand
291For an operand that must be a register, @var{predicate} should be
292@code{"register_operand"}. Using @code{"general_operand"} would be
293valid, since the reload pass would copy any non-register operands
f0523f02 294through registers, but this would make GCC do extra work, it would
03dda8e3
RK
295prevent invariant operands (such as constant) from being removed from
296loops, and it would prevent the register allocator from doing the best
297possible job. On RISC machines, it is usually most efficient to allow
298@var{predicate} to accept only objects that the constraints allow.
299
300@findex immediate_operand
301For an operand that must be a constant, you must be sure to either use
302@code{"immediate_operand"} for @var{predicate}, or make the instruction
303pattern's extra condition require a constant, or both. You cannot
304expect the constraints to do this work! If the constraints allow only
305constants, but the predicate allows something else, the compiler will
306crash when that case arises.
307
308@findex match_scratch
309@item (match_scratch:@var{m} @var{n} @var{constraint})
310This expression is also a placeholder for operand number @var{n}
311and indicates that operand must be a @code{scratch} or @code{reg}
312expression.
313
314When matching patterns, this is equivalent to
315
316@smallexample
317(match_operand:@var{m} @var{n} "scratch_operand" @var{pred})
318@end smallexample
319
320but, when generating RTL, it produces a (@code{scratch}:@var{m})
321expression.
322
323If the last few expressions in a @code{parallel} are @code{clobber}
324expressions whose operands are either a hard register or
325@code{match_scratch}, the combiner can add or delete them when
326necessary. @xref{Side Effects}.
327
328@findex match_dup
329@item (match_dup @var{n})
330This expression is also a placeholder for operand number @var{n}.
331It is used when the operand needs to appear more than once in the
332insn.
333
334In construction, @code{match_dup} acts just like @code{match_operand}:
335the operand is substituted into the insn being constructed. But in
336matching, @code{match_dup} behaves differently. It assumes that operand
337number @var{n} has already been determined by a @code{match_operand}
338appearing earlier in the recognition template, and it matches only an
339identical-looking expression.
340
55e4756f
DD
341Note that @code{match_dup} should not be used to tell the compiler that
342a particular register is being used for two operands (example:
343@code{add} that adds one register to another; the second register is
344both an input operand and the output operand). Use a matching
345constraint (@pxref{Simple Constraints}) for those. @code{match_dup} is for the cases where one
346operand is used in two places in the template, such as an instruction
347that computes both a quotient and a remainder, where the opcode takes
348two input operands but the RTL template has to refer to each of those
349twice; once for the quotient pattern and once for the remainder pattern.
350
03dda8e3
RK
351@findex match_operator
352@item (match_operator:@var{m} @var{n} @var{predicate} [@var{operands}@dots{}])
353This pattern is a kind of placeholder for a variable RTL expression
354code.
355
356When constructing an insn, it stands for an RTL expression whose
357expression code is taken from that of operand @var{n}, and whose
358operands are constructed from the patterns @var{operands}.
359
360When matching an expression, it matches an expression if the function
361@var{predicate} returns nonzero on that expression @emph{and} the
362patterns @var{operands} match the operands of the expression.
363
364Suppose that the function @code{commutative_operator} is defined as
365follows, to match any expression whose operator is one of the
366commutative arithmetic operators of RTL and whose mode is @var{mode}:
367
368@smallexample
369int
370commutative_operator (x, mode)
371 rtx x;
372 enum machine_mode mode;
373@{
374 enum rtx_code code = GET_CODE (x);
375 if (GET_MODE (x) != mode)
376 return 0;
377 return (GET_RTX_CLASS (code) == 'c'
378 || code == EQ || code == NE);
379@}
380@end smallexample
381
382Then the following pattern will match any RTL expression consisting
383of a commutative operator applied to two general operands:
384
385@smallexample
386(match_operator:SI 3 "commutative_operator"
387 [(match_operand:SI 1 "general_operand" "g")
388 (match_operand:SI 2 "general_operand" "g")])
389@end smallexample
390
391Here the vector @code{[@var{operands}@dots{}]} contains two patterns
392because the expressions to be matched all contain two operands.
393
394When this pattern does match, the two operands of the commutative
395operator are recorded as operands 1 and 2 of the insn. (This is done
396by the two instances of @code{match_operand}.) Operand 3 of the insn
397will be the entire commutative expression: use @code{GET_CODE
398(operands[3])} to see which commutative operator was used.
399
400The machine mode @var{m} of @code{match_operator} works like that of
401@code{match_operand}: it is passed as the second argument to the
402predicate function, and that function is solely responsible for
403deciding whether the expression to be matched ``has'' that mode.
404
405When constructing an insn, argument 3 of the gen-function will specify
e979f9e8 406the operation (i.e.@: the expression code) for the expression to be
03dda8e3
RK
407made. It should be an RTL expression, whose expression code is copied
408into a new expression whose operands are arguments 1 and 2 of the
409gen-function. The subexpressions of argument 3 are not used;
410only its expression code matters.
411
412When @code{match_operator} is used in a pattern for matching an insn,
413it usually best if the operand number of the @code{match_operator}
414is higher than that of the actual operands of the insn. This improves
415register allocation because the register allocator often looks at
416operands 1 and 2 of insns to see if it can do register tying.
417
418There is no way to specify constraints in @code{match_operator}. The
419operand of the insn which corresponds to the @code{match_operator}
420never has any constraints because it is never reloaded as a whole.
421However, if parts of its @var{operands} are matched by
422@code{match_operand} patterns, those parts may have constraints of
423their own.
424
425@findex match_op_dup
426@item (match_op_dup:@var{m} @var{n}[@var{operands}@dots{}])
427Like @code{match_dup}, except that it applies to operators instead of
428operands. When constructing an insn, operand number @var{n} will be
429substituted at this point. But in matching, @code{match_op_dup} behaves
430differently. It assumes that operand number @var{n} has already been
431determined by a @code{match_operator} appearing earlier in the
432recognition template, and it matches only an identical-looking
433expression.
434
435@findex match_parallel
436@item (match_parallel @var{n} @var{predicate} [@var{subpat}@dots{}])
437This pattern is a placeholder for an insn that consists of a
438@code{parallel} expression with a variable number of elements. This
439expression should only appear at the top level of an insn pattern.
440
441When constructing an insn, operand number @var{n} will be substituted at
442this point. When matching an insn, it matches if the body of the insn
443is a @code{parallel} expression with at least as many elements as the
444vector of @var{subpat} expressions in the @code{match_parallel}, if each
445@var{subpat} matches the corresponding element of the @code{parallel},
446@emph{and} the function @var{predicate} returns nonzero on the
447@code{parallel} that is the body of the insn. It is the responsibility
448of the predicate to validate elements of the @code{parallel} beyond
bd819a4a 449those listed in the @code{match_parallel}.
03dda8e3
RK
450
451A typical use of @code{match_parallel} is to match load and store
452multiple expressions, which can contain a variable number of elements
453in a @code{parallel}. For example,
03dda8e3
RK
454
455@smallexample
456(define_insn ""
457 [(match_parallel 0 "load_multiple_operation"
458 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
459 (match_operand:SI 2 "memory_operand" "m"))
460 (use (reg:SI 179))
461 (clobber (reg:SI 179))])]
462 ""
463 "loadm 0,0,%1,%2")
464@end smallexample
465
466This example comes from @file{a29k.md}. The function
9c34dbbf 467@code{load_multiple_operation} is defined in @file{a29k.c} and checks
03dda8e3
RK
468that subsequent elements in the @code{parallel} are the same as the
469@code{set} in the pattern, except that they are referencing subsequent
470registers and memory locations.
471
472An insn that matches this pattern might look like:
473
474@smallexample
475(parallel
476 [(set (reg:SI 20) (mem:SI (reg:SI 100)))
477 (use (reg:SI 179))
478 (clobber (reg:SI 179))
479 (set (reg:SI 21)
480 (mem:SI (plus:SI (reg:SI 100)
481 (const_int 4))))
482 (set (reg:SI 22)
483 (mem:SI (plus:SI (reg:SI 100)
484 (const_int 8))))])
485@end smallexample
486
487@findex match_par_dup
488@item (match_par_dup @var{n} [@var{subpat}@dots{}])
489Like @code{match_op_dup}, but for @code{match_parallel} instead of
490@code{match_operator}.
491
693e265f
MM
492@findex match_insn
493@item (match_insn @var{predicate})
494Match a complete insn. Unlike the other @code{match_*} recognizers,
495@code{match_insn} does not take an operand number.
496
497The machine mode @var{m} of @code{match_insn} works like that of
498@code{match_operand}: it is passed as the second argument to the
499predicate function, and that function is solely responsible for
500deciding whether the expression to be matched ``has'' that mode.
501
502@findex match_insn2
503@item (match_insn2 @var{n} @var{predicate})
504Match a complete insn.
505
506The machine mode @var{m} of @code{match_insn2} works like that of
507@code{match_operand}: it is passed as the second argument to the
508predicate function, and that function is solely responsible for
509deciding whether the expression to be matched ``has'' that mode.
510
03dda8e3
RK
511@end table
512
513@node Output Template
514@section Output Templates and Operand Substitution
515@cindex output templates
516@cindex operand substitution
517
518@cindex @samp{%} in template
519@cindex percent sign
520The @dfn{output template} is a string which specifies how to output the
521assembler code for an instruction pattern. Most of the template is a
522fixed string which is output literally. The character @samp{%} is used
523to specify where to substitute an operand; it can also be used to
524identify places where different variants of the assembler require
525different syntax.
526
527In the simplest case, a @samp{%} followed by a digit @var{n} says to output
528operand @var{n} at that point in the string.
529
530@samp{%} followed by a letter and a digit says to output an operand in an
531alternate fashion. Four letters have standard, built-in meanings described
532below. The machine description macro @code{PRINT_OPERAND} can define
533additional letters with nonstandard meanings.
534
535@samp{%c@var{digit}} can be used to substitute an operand that is a
536constant value without the syntax that normally indicates an immediate
537operand.
538
539@samp{%n@var{digit}} is like @samp{%c@var{digit}} except that the value of
540the constant is negated before printing.
541
542@samp{%a@var{digit}} can be used to substitute an operand as if it were a
543memory reference, with the actual operand treated as the address. This may
544be useful when outputting a ``load address'' instruction, because often the
545assembler syntax for such an instruction requires you to write the operand
546as if it were a memory reference.
547
548@samp{%l@var{digit}} is used to substitute a @code{label_ref} into a jump
549instruction.
550
551@samp{%=} outputs a number which is unique to each instruction in the
552entire compilation. This is useful for making local labels to be
553referred to more than once in a single template that generates multiple
554assembler instructions.
555
556@samp{%} followed by a punctuation character specifies a substitution that
557does not use an operand. Only one case is standard: @samp{%%} outputs a
558@samp{%} into the assembler code. Other nonstandard cases can be
559defined in the @code{PRINT_OPERAND} macro. You must also define
560which punctuation characters are valid with the
561@code{PRINT_OPERAND_PUNCT_VALID_P} macro.
562
563@cindex \
564@cindex backslash
565The template may generate multiple assembler instructions. Write the text
566for the instructions, with @samp{\;} between them.
567
568@cindex matching operands
569When the RTL contains two operands which are required by constraint to match
570each other, the output template must refer only to the lower-numbered operand.
571Matching operands are not always identical, and the rest of the compiler
572arranges to put the proper RTL expression for printing into the lower-numbered
573operand.
574
575One use of nonstandard letters or punctuation following @samp{%} is to
576distinguish between different assembler languages for the same machine; for
577example, Motorola syntax versus MIT syntax for the 68000. Motorola syntax
578requires periods in most opcode names, while MIT syntax does not. For
579example, the opcode @samp{movel} in MIT syntax is @samp{move.l} in Motorola
580syntax. The same file of patterns is used for both kinds of output syntax,
581but the character sequence @samp{%.} is used in each place where Motorola
582syntax wants a period. The @code{PRINT_OPERAND} macro for Motorola syntax
583defines the sequence to output a period; the macro for MIT syntax defines
584it to do nothing.
585
586@cindex @code{#} in template
587As a special case, a template consisting of the single character @code{#}
588instructs the compiler to first split the insn, and then output the
589resulting instructions separately. This helps eliminate redundancy in the
590output templates. If you have a @code{define_insn} that needs to emit
591multiple assembler instructions, and there is an matching @code{define_split}
592already defined, then you can simply use @code{#} as the output template
593instead of writing an output template that emits the multiple assembler
594instructions.
595
596If the macro @code{ASSEMBLER_DIALECT} is defined, you can use construct
597of the form @samp{@{option0|option1|option2@}} in the templates. These
598describe multiple variants of assembler language syntax.
599@xref{Instruction Output}.
600
601@node Output Statement
602@section C Statements for Assembler Output
603@cindex output statements
604@cindex C statements for assembler output
605@cindex generating assembler output
606
607Often a single fixed template string cannot produce correct and efficient
608assembler code for all the cases that are recognized by a single
609instruction pattern. For example, the opcodes may depend on the kinds of
610operands; or some unfortunate combinations of operands may require extra
611machine instructions.
612
613If the output control string starts with a @samp{@@}, then it is actually
614a series of templates, each on a separate line. (Blank lines and
615leading spaces and tabs are ignored.) The templates correspond to the
616pattern's constraint alternatives (@pxref{Multi-Alternative}). For example,
617if a target machine has a two-address add instruction @samp{addr} to add
618into a register and another @samp{addm} to add a register to memory, you
619might write this pattern:
620
621@smallexample
622(define_insn "addsi3"
623 [(set (match_operand:SI 0 "general_operand" "=r,m")
624 (plus:SI (match_operand:SI 1 "general_operand" "0,0")
625 (match_operand:SI 2 "general_operand" "g,r")))]
626 ""
627 "@@
628 addr %2,%0
629 addm %2,%0")
630@end smallexample
631
632@cindex @code{*} in template
633@cindex asterisk in template
634If the output control string starts with a @samp{*}, then it is not an
635output template but rather a piece of C program that should compute a
636template. It should execute a @code{return} statement to return the
637template-string you want. Most such templates use C string literals, which
638require doublequote characters to delimit them. To include these
639doublequote characters in the string, prefix each one with @samp{\}.
640
0f40f9f7
ZW
641If the output control string is written as a brace block instead of a
642double-quoted string, it is automatically assumed to be C code. In that
643case, it is not necessary to put in a leading asterisk, or to escape the
644doublequotes surrounding C string literals.
645
03dda8e3
RK
646The operands may be found in the array @code{operands}, whose C data type
647is @code{rtx []}.
648
649It is very common to select different ways of generating assembler code
650based on whether an immediate operand is within a certain range. Be
651careful when doing this, because the result of @code{INTVAL} is an
652integer on the host machine. If the host machine has more bits in an
653@code{int} than the target machine has in the mode in which the constant
654will be used, then some of the bits you get from @code{INTVAL} will be
655superfluous. For proper results, you must carefully disregard the
656values of those bits.
657
658@findex output_asm_insn
659It is possible to output an assembler instruction and then go on to output
660or compute more of them, using the subroutine @code{output_asm_insn}. This
661receives two arguments: a template-string and a vector of operands. The
662vector may be @code{operands}, or it may be another array of @code{rtx}
663that you declare locally and initialize yourself.
664
665@findex which_alternative
666When an insn pattern has multiple alternatives in its constraints, often
667the appearance of the assembler code is determined mostly by which alternative
668was matched. When this is so, the C code can test the variable
669@code{which_alternative}, which is the ordinal number of the alternative
670that was actually satisfied (0 for the first, 1 for the second alternative,
671etc.).
672
673For example, suppose there are two opcodes for storing zero, @samp{clrreg}
674for registers and @samp{clrmem} for memory locations. Here is how
675a pattern could use @code{which_alternative} to choose between them:
676
677@smallexample
678(define_insn ""
679 [(set (match_operand:SI 0 "general_operand" "=r,m")
680 (const_int 0))]
681 ""
0f40f9f7 682 @{
03dda8e3 683 return (which_alternative == 0
0f40f9f7
ZW
684 ? "clrreg %0" : "clrmem %0");
685 @})
03dda8e3
RK
686@end smallexample
687
688The example above, where the assembler code to generate was
689@emph{solely} determined by the alternative, could also have been specified
690as follows, having the output control string start with a @samp{@@}:
691
692@smallexample
693@group
694(define_insn ""
695 [(set (match_operand:SI 0 "general_operand" "=r,m")
696 (const_int 0))]
697 ""
698 "@@
699 clrreg %0
700 clrmem %0")
701@end group
702@end smallexample
703@end ifset
704
705@c Most of this node appears by itself (in a different place) even
b11cc610
JM
706@c when the INTERNALS flag is clear. Passages that require the internals
707@c manual's context are conditionalized to appear only in the internals manual.
03dda8e3
RK
708@ifset INTERNALS
709@node Constraints
710@section Operand Constraints
711@cindex operand constraints
712@cindex constraints
713
714Each @code{match_operand} in an instruction pattern can specify a
715constraint for the type of operands allowed.
716@end ifset
717@ifclear INTERNALS
718@node Constraints
719@section Constraints for @code{asm} Operands
720@cindex operand constraints, @code{asm}
721@cindex constraints, @code{asm}
722@cindex @code{asm} constraints
723
724Here are specific details on what constraint letters you can use with
725@code{asm} operands.
726@end ifclear
727Constraints can say whether
728an operand may be in a register, and which kinds of register; whether the
729operand can be a memory reference, and which kinds of address; whether the
730operand may be an immediate constant, and which possible values it may
731have. Constraints can also require two operands to match.
732
733@ifset INTERNALS
734@menu
735* Simple Constraints:: Basic use of constraints.
736* Multi-Alternative:: When an insn has two alternative constraint-patterns.
737* Class Preferences:: Constraints guide which hard register to put things in.
738* Modifiers:: More precise control over effects of constraints.
739* Machine Constraints:: Existing constraints for some particular machines.
03dda8e3
RK
740@end menu
741@end ifset
742
743@ifclear INTERNALS
744@menu
745* Simple Constraints:: Basic use of constraints.
746* Multi-Alternative:: When an insn has two alternative constraint-patterns.
747* Modifiers:: More precise control over effects of constraints.
748* Machine Constraints:: Special constraints for some particular machines.
749@end menu
750@end ifclear
751
752@node Simple Constraints
753@subsection Simple Constraints
754@cindex simple constraints
755
756The simplest kind of constraint is a string full of letters, each of
757which describes one kind of operand that is permitted. Here are
758the letters that are allowed:
759
760@table @asis
88a56c2e
HPN
761@item whitespace
762Whitespace characters are ignored and can be inserted at any position
763except the first. This enables each alternative for different operands to
764be visually aligned in the machine description even if they have different
765number of constraints and modifiers.
766
03dda8e3
RK
767@cindex @samp{m} in constraint
768@cindex memory references in constraints
769@item @samp{m}
770A memory operand is allowed, with any kind of address that the machine
771supports in general.
772
773@cindex offsettable address
774@cindex @samp{o} in constraint
775@item @samp{o}
776A memory operand is allowed, but only if the address is
777@dfn{offsettable}. This means that adding a small integer (actually,
778the width in bytes of the operand, as determined by its machine mode)
779may be added to the address and the result is also a valid memory
780address.
781
782@cindex autoincrement/decrement addressing
783For example, an address which is constant is offsettable; so is an
784address that is the sum of a register and a constant (as long as a
785slightly larger constant is also within the range of address-offsets
786supported by the machine); but an autoincrement or autodecrement
787address is not offsettable. More complicated indirect/indexed
788addresses may or may not be offsettable depending on the other
789addressing modes that the machine supports.
790
791Note that in an output operand which can be matched by another
792operand, the constraint letter @samp{o} is valid only when accompanied
793by both @samp{<} (if the target machine has predecrement addressing)
794and @samp{>} (if the target machine has preincrement addressing).
795
796@cindex @samp{V} in constraint
797@item @samp{V}
798A memory operand that is not offsettable. In other words, anything that
799would fit the @samp{m} constraint but not the @samp{o} constraint.
800
801@cindex @samp{<} in constraint
802@item @samp{<}
803A memory operand with autodecrement addressing (either predecrement or
804postdecrement) is allowed.
805
806@cindex @samp{>} in constraint
807@item @samp{>}
808A memory operand with autoincrement addressing (either preincrement or
809postincrement) is allowed.
810
811@cindex @samp{r} in constraint
812@cindex registers in constraints
813@item @samp{r}
814A register operand is allowed provided that it is in a general
815register.
816
03dda8e3
RK
817@cindex constants in constraints
818@cindex @samp{i} in constraint
819@item @samp{i}
820An immediate integer operand (one with constant value) is allowed.
821This includes symbolic constants whose values will be known only at
822assembly time.
823
824@cindex @samp{n} in constraint
825@item @samp{n}
826An immediate integer operand with a known numeric value is allowed.
827Many systems cannot support assembly-time constants for operands less
828than a word wide. Constraints for these operands should use @samp{n}
829rather than @samp{i}.
830
831@cindex @samp{I} in constraint
832@item @samp{I}, @samp{J}, @samp{K}, @dots{} @samp{P}
833Other letters in the range @samp{I} through @samp{P} may be defined in
834a machine-dependent fashion to permit immediate integer operands with
835explicit integer values in specified ranges. For example, on the
83668000, @samp{I} is defined to stand for the range of values 1 to 8.
837This is the range permitted as a shift count in the shift
838instructions.
839
840@cindex @samp{E} in constraint
841@item @samp{E}
842An immediate floating operand (expression code @code{const_double}) is
843allowed, but only if the target floating point format is the same as
844that of the host machine (on which the compiler is running).
845
846@cindex @samp{F} in constraint
847@item @samp{F}
bf7cd754
R
848An immediate floating operand (expression code @code{const_double} or
849@code{const_vector}) is allowed.
03dda8e3
RK
850
851@cindex @samp{G} in constraint
852@cindex @samp{H} in constraint
853@item @samp{G}, @samp{H}
854@samp{G} and @samp{H} may be defined in a machine-dependent fashion to
855permit immediate floating operands in particular ranges of values.
856
857@cindex @samp{s} in constraint
858@item @samp{s}
859An immediate integer operand whose value is not an explicit integer is
860allowed.
861
862This might appear strange; if an insn allows a constant operand with a
863value not known at compile time, it certainly must allow any known
864value. So why use @samp{s} instead of @samp{i}? Sometimes it allows
865better code to be generated.
866
867For example, on the 68000 in a fullword instruction it is possible to
630d3d5a 868use an immediate operand; but if the immediate value is between @minus{}128
03dda8e3
RK
869and 127, better code results from loading the value into a register and
870using the register. This is because the load into the register can be
871done with a @samp{moveq} instruction. We arrange for this to happen
872by defining the letter @samp{K} to mean ``any integer outside the
630d3d5a 873range @minus{}128 to 127'', and then specifying @samp{Ks} in the operand
03dda8e3
RK
874constraints.
875
876@cindex @samp{g} in constraint
877@item @samp{g}
878Any register, memory or immediate integer operand is allowed, except for
879registers that are not general registers.
880
881@cindex @samp{X} in constraint
882@item @samp{X}
883@ifset INTERNALS
884Any operand whatsoever is allowed, even if it does not satisfy
885@code{general_operand}. This is normally used in the constraint of
886a @code{match_scratch} when certain alternatives will not actually
887require a scratch register.
888@end ifset
889@ifclear INTERNALS
890Any operand whatsoever is allowed.
891@end ifclear
892
893@cindex @samp{0} in constraint
894@cindex digits in constraint
895@item @samp{0}, @samp{1}, @samp{2}, @dots{} @samp{9}
896An operand that matches the specified operand number is allowed. If a
897digit is used together with letters within the same alternative, the
898digit should come last.
899
84b72302 900This number is allowed to be more than a single digit. If multiple
c0478a66 901digits are encountered consecutively, they are interpreted as a single
84b72302
RH
902decimal integer. There is scant chance for ambiguity, since to-date
903it has never been desirable that @samp{10} be interpreted as matching
904either operand 1 @emph{or} operand 0. Should this be desired, one
905can use multiple alternatives instead.
906
03dda8e3
RK
907@cindex matching constraint
908@cindex constraint, matching
909This is called a @dfn{matching constraint} and what it really means is
910that the assembler has only a single operand that fills two roles
911@ifset INTERNALS
912considered separate in the RTL insn. For example, an add insn has two
913input operands and one output operand in the RTL, but on most CISC
914@end ifset
915@ifclear INTERNALS
916which @code{asm} distinguishes. For example, an add instruction uses
917two input operands and an output operand, but on most CISC
918@end ifclear
919machines an add instruction really has only two operands, one of them an
920input-output operand:
921
922@smallexample
923addl #35,r12
924@end smallexample
925
926Matching constraints are used in these circumstances.
927More precisely, the two operands that match must include one input-only
928operand and one output-only operand. Moreover, the digit must be a
929smaller number than the number of the operand that uses it in the
930constraint.
931
932@ifset INTERNALS
933For operands to match in a particular case usually means that they
934are identical-looking RTL expressions. But in a few special cases
935specific kinds of dissimilarity are allowed. For example, @code{*x}
936as an input operand will match @code{*x++} as an output operand.
937For proper results in such cases, the output template should always
938use the output-operand's number when printing the operand.
939@end ifset
940
941@cindex load address instruction
942@cindex push address instruction
943@cindex address constraints
944@cindex @samp{p} in constraint
945@item @samp{p}
946An operand that is a valid memory address is allowed. This is
947for ``load address'' and ``push address'' instructions.
948
949@findex address_operand
950@samp{p} in the constraint must be accompanied by @code{address_operand}
951as the predicate in the @code{match_operand}. This predicate interprets
952the mode specified in the @code{match_operand} as the mode of the memory
953reference for which the address would be valid.
954
c2cba7a9 955@cindex other register constraints
03dda8e3 956@cindex extensible constraints
630d3d5a 957@item @var{other-letters}
c2cba7a9
RH
958Other letters can be defined in machine-dependent fashion to stand for
959particular classes of registers or other arbitrary operand types.
960@samp{d}, @samp{a} and @samp{f} are defined on the 68000/68020 to stand
961for data, address and floating point registers.
03dda8e3 962
c2cba7a9
RH
963@ifset INTERNALS
964The machine description macro @code{REG_CLASS_FROM_LETTER} has first
965cut at the otherwise unused letters. If it evaluates to @code{NO_REGS},
966then @code{EXTRA_CONSTRAINT} is evaluated.
03dda8e3 967
c0478a66 968A typical use for @code{EXTRA_CONSTRAINT} would be to distinguish certain
c2cba7a9 969types of memory references that affect other insn operands.
03dda8e3
RK
970@end ifset
971@end table
972
973@ifset INTERNALS
974In order to have valid assembler code, each operand must satisfy
975its constraint. But a failure to do so does not prevent the pattern
976from applying to an insn. Instead, it directs the compiler to modify
977the code so that the constraint will be satisfied. Usually this is
978done by copying an operand into a register.
979
980Contrast, therefore, the two instruction patterns that follow:
981
982@smallexample
983(define_insn ""
984 [(set (match_operand:SI 0 "general_operand" "=r")
985 (plus:SI (match_dup 0)
986 (match_operand:SI 1 "general_operand" "r")))]
987 ""
988 "@dots{}")
989@end smallexample
990
991@noindent
992which has two operands, one of which must appear in two places, and
993
994@smallexample
995(define_insn ""
996 [(set (match_operand:SI 0 "general_operand" "=r")
997 (plus:SI (match_operand:SI 1 "general_operand" "0")
998 (match_operand:SI 2 "general_operand" "r")))]
999 ""
1000 "@dots{}")
1001@end smallexample
1002
1003@noindent
1004which has three operands, two of which are required by a constraint to be
1005identical. If we are considering an insn of the form
1006
1007@smallexample
1008(insn @var{n} @var{prev} @var{next}
1009 (set (reg:SI 3)
1010 (plus:SI (reg:SI 6) (reg:SI 109)))
1011 @dots{})
1012@end smallexample
1013
1014@noindent
1015the first pattern would not apply at all, because this insn does not
1016contain two identical subexpressions in the right place. The pattern would
1017say, ``That does not look like an add instruction; try other patterns.''
1018The second pattern would say, ``Yes, that's an add instruction, but there
1019is something wrong with it.'' It would direct the reload pass of the
1020compiler to generate additional insns to make the constraint true. The
1021results might look like this:
1022
1023@smallexample
1024(insn @var{n2} @var{prev} @var{n}
1025 (set (reg:SI 3) (reg:SI 6))
1026 @dots{})
1027
1028(insn @var{n} @var{n2} @var{next}
1029 (set (reg:SI 3)
1030 (plus:SI (reg:SI 3) (reg:SI 109)))
1031 @dots{})
1032@end smallexample
1033
1034It is up to you to make sure that each operand, in each pattern, has
1035constraints that can handle any RTL expression that could be present for
1036that operand. (When multiple alternatives are in use, each pattern must,
1037for each possible combination of operand expressions, have at least one
1038alternative which can handle that combination of operands.) The
1039constraints don't need to @emph{allow} any possible operand---when this is
1040the case, they do not constrain---but they must at least point the way to
1041reloading any possible operand so that it will fit.
1042
1043@itemize @bullet
1044@item
1045If the constraint accepts whatever operands the predicate permits,
1046there is no problem: reloading is never necessary for this operand.
1047
1048For example, an operand whose constraints permit everything except
1049registers is safe provided its predicate rejects registers.
1050
1051An operand whose predicate accepts only constant values is safe
1052provided its constraints include the letter @samp{i}. If any possible
1053constant value is accepted, then nothing less than @samp{i} will do;
1054if the predicate is more selective, then the constraints may also be
1055more selective.
1056
1057@item
1058Any operand expression can be reloaded by copying it into a register.
1059So if an operand's constraints allow some kind of register, it is
1060certain to be safe. It need not permit all classes of registers; the
1061compiler knows how to copy a register into another register of the
1062proper class in order to make an instruction valid.
1063
1064@cindex nonoffsettable memory reference
1065@cindex memory reference, nonoffsettable
1066@item
1067A nonoffsettable memory reference can be reloaded by copying the
1068address into a register. So if the constraint uses the letter
1069@samp{o}, all memory references are taken care of.
1070
1071@item
1072A constant operand can be reloaded by allocating space in memory to
1073hold it as preinitialized data. Then the memory reference can be used
1074in place of the constant. So if the constraint uses the letters
1075@samp{o} or @samp{m}, constant operands are not a problem.
1076
1077@item
1078If the constraint permits a constant and a pseudo register used in an insn
1079was not allocated to a hard register and is equivalent to a constant,
1080the register will be replaced with the constant. If the predicate does
1081not permit a constant and the insn is re-recognized for some reason, the
1082compiler will crash. Thus the predicate must always recognize any
1083objects allowed by the constraint.
1084@end itemize
1085
1086If the operand's predicate can recognize registers, but the constraint does
1087not permit them, it can make the compiler crash. When this operand happens
1088to be a register, the reload pass will be stymied, because it does not know
1089how to copy a register temporarily into memory.
1090
1091If the predicate accepts a unary operator, the constraint applies to the
1092operand. For example, the MIPS processor at ISA level 3 supports an
1093instruction which adds two registers in @code{SImode} to produce a
1094@code{DImode} result, but only if the registers are correctly sign
1095extended. This predicate for the input operands accepts a
1096@code{sign_extend} of an @code{SImode} register. Write the constraint
1097to indicate the type of register that is required for the operand of the
1098@code{sign_extend}.
1099@end ifset
1100
1101@node Multi-Alternative
1102@subsection Multiple Alternative Constraints
1103@cindex multiple alternative constraints
1104
1105Sometimes a single instruction has multiple alternative sets of possible
1106operands. For example, on the 68000, a logical-or instruction can combine
1107register or an immediate value into memory, or it can combine any kind of
1108operand into a register; but it cannot combine one memory location into
1109another.
1110
1111These constraints are represented as multiple alternatives. An alternative
1112can be described by a series of letters for each operand. The overall
1113constraint for an operand is made from the letters for this operand
1114from the first alternative, a comma, the letters for this operand from
1115the second alternative, a comma, and so on until the last alternative.
1116@ifset INTERNALS
1117Here is how it is done for fullword logical-or on the 68000:
1118
1119@smallexample
1120(define_insn "iorsi3"
1121 [(set (match_operand:SI 0 "general_operand" "=m,d")
1122 (ior:SI (match_operand:SI 1 "general_operand" "%0,0")
1123 (match_operand:SI 2 "general_operand" "dKs,dmKs")))]
1124 @dots{})
1125@end smallexample
1126
1127The first alternative has @samp{m} (memory) for operand 0, @samp{0} for
1128operand 1 (meaning it must match operand 0), and @samp{dKs} for operand
11292. The second alternative has @samp{d} (data register) for operand 0,
1130@samp{0} for operand 1, and @samp{dmKs} for operand 2. The @samp{=} and
1131@samp{%} in the constraints apply to all the alternatives; their
1132meaning is explained in the next section (@pxref{Class Preferences}).
1133@end ifset
1134
1135@c FIXME Is this ? and ! stuff of use in asm()? If not, hide unless INTERNAL
1136If all the operands fit any one alternative, the instruction is valid.
1137Otherwise, for each alternative, the compiler counts how many instructions
1138must be added to copy the operands so that that alternative applies.
1139The alternative requiring the least copying is chosen. If two alternatives
1140need the same amount of copying, the one that comes first is chosen.
1141These choices can be altered with the @samp{?} and @samp{!} characters:
1142
1143@table @code
1144@cindex @samp{?} in constraint
1145@cindex question mark
1146@item ?
1147Disparage slightly the alternative that the @samp{?} appears in,
1148as a choice when no alternative applies exactly. The compiler regards
1149this alternative as one unit more costly for each @samp{?} that appears
1150in it.
1151
1152@cindex @samp{!} in constraint
1153@cindex exclamation point
1154@item !
1155Disparage severely the alternative that the @samp{!} appears in.
1156This alternative can still be used if it fits without reloading,
1157but if reloading is needed, some other alternative will be used.
1158@end table
1159
1160@ifset INTERNALS
1161When an insn pattern has multiple alternatives in its constraints, often
1162the appearance of the assembler code is determined mostly by which
1163alternative was matched. When this is so, the C code for writing the
1164assembler code can use the variable @code{which_alternative}, which is
1165the ordinal number of the alternative that was actually satisfied (0 for
1166the first, 1 for the second alternative, etc.). @xref{Output Statement}.
1167@end ifset
1168
1169@ifset INTERNALS
1170@node Class Preferences
1171@subsection Register Class Preferences
1172@cindex class preference constraints
1173@cindex register class preference constraints
1174
1175@cindex voting between constraint alternatives
1176The operand constraints have another function: they enable the compiler
1177to decide which kind of hardware register a pseudo register is best
1178allocated to. The compiler examines the constraints that apply to the
1179insns that use the pseudo register, looking for the machine-dependent
1180letters such as @samp{d} and @samp{a} that specify classes of registers.
1181The pseudo register is put in whichever class gets the most ``votes''.
1182The constraint letters @samp{g} and @samp{r} also vote: they vote in
1183favor of a general register. The machine description says which registers
1184are considered general.
1185
1186Of course, on some machines all registers are equivalent, and no register
1187classes are defined. Then none of this complexity is relevant.
1188@end ifset
1189
1190@node Modifiers
1191@subsection Constraint Modifier Characters
1192@cindex modifiers in constraints
1193@cindex constraint modifier characters
1194
1195@c prevent bad page break with this line
1196Here are constraint modifier characters.
1197
1198@table @samp
1199@cindex @samp{=} in constraint
1200@item =
1201Means that this operand is write-only for this instruction: the previous
1202value is discarded and replaced by output data.
1203
1204@cindex @samp{+} in constraint
1205@item +
1206Means that this operand is both read and written by the instruction.
1207
1208When the compiler fixes up the operands to satisfy the constraints,
1209it needs to know which operands are inputs to the instruction and
1210which are outputs from it. @samp{=} identifies an output; @samp{+}
1211identifies an operand that is both input and output; all other operands
1212are assumed to be input only.
1213
c5c76735
JL
1214If you specify @samp{=} or @samp{+} in a constraint, you put it in the
1215first character of the constraint string.
1216
03dda8e3
RK
1217@cindex @samp{&} in constraint
1218@cindex earlyclobber operand
1219@item &
1220Means (in a particular alternative) that this operand is an
1221@dfn{earlyclobber} operand, which is modified before the instruction is
1222finished using the input operands. Therefore, this operand may not lie
1223in a register that is used as an input operand or as part of any memory
1224address.
1225
1226@samp{&} applies only to the alternative in which it is written. In
1227constraints with multiple alternatives, sometimes one alternative
1228requires @samp{&} while others do not. See, for example, the
1229@samp{movdf} insn of the 68000.
1230
ebb48a4d 1231An input operand can be tied to an earlyclobber operand if its only
03dda8e3
RK
1232use as an input occurs before the early result is written. Adding
1233alternatives of this form often allows GCC to produce better code
ebb48a4d 1234when only some of the inputs can be affected by the earlyclobber.
161d7b59 1235See, for example, the @samp{mulsi3} insn of the ARM@.
03dda8e3
RK
1236
1237@samp{&} does not obviate the need to write @samp{=}.
1238
1239@cindex @samp{%} in constraint
1240@item %
1241Declares the instruction to be commutative for this operand and the
1242following operand. This means that the compiler may interchange the
1243two operands if that is the cheapest way to make all operands fit the
1244constraints.
1245@ifset INTERNALS
1246This is often used in patterns for addition instructions
1247that really have only two operands: the result must go in one of the
1248arguments. Here for example, is how the 68000 halfword-add
1249instruction is defined:
1250
1251@smallexample
1252(define_insn "addhi3"
1253 [(set (match_operand:HI 0 "general_operand" "=m,r")
1254 (plus:HI (match_operand:HI 1 "general_operand" "%0,0")
1255 (match_operand:HI 2 "general_operand" "di,g")))]
1256 @dots{})
1257@end smallexample
1258@end ifset
9efb4cb6
NN
1259GCC can only handle one commutative pair in an asm; if you use more,
1260the compiler may fail.
03dda8e3
RK
1261
1262@cindex @samp{#} in constraint
1263@item #
1264Says that all following characters, up to the next comma, are to be
1265ignored as a constraint. They are significant only for choosing
1266register preferences.
1267
03dda8e3
RK
1268@cindex @samp{*} in constraint
1269@item *
1270Says that the following character should be ignored when choosing
1271register preferences. @samp{*} has no effect on the meaning of the
1272constraint as a constraint, and no effect on reloading.
1273
9f339dde 1274@ifset INTERNALS
03dda8e3
RK
1275Here is an example: the 68000 has an instruction to sign-extend a
1276halfword in a data register, and can also sign-extend a value by
1277copying it into an address register. While either kind of register is
1278acceptable, the constraints on an address-register destination are
1279less strict, so it is best if register allocation makes an address
1280register its goal. Therefore, @samp{*} is used so that the @samp{d}
1281constraint letter (for data register) is ignored when computing
1282register preferences.
1283
1284@smallexample
1285(define_insn "extendhisi2"
1286 [(set (match_operand:SI 0 "general_operand" "=*d,a")
1287 (sign_extend:SI
1288 (match_operand:HI 1 "general_operand" "0,g")))]
1289 @dots{})
1290@end smallexample
1291@end ifset
1292@end table
1293
1294@node Machine Constraints
1295@subsection Constraints for Particular Machines
1296@cindex machine specific constraints
1297@cindex constraints, machine specific
1298
1299Whenever possible, you should use the general-purpose constraint letters
1300in @code{asm} arguments, since they will convey meaning more readily to
1301people reading your code. Failing that, use the constraint letters
1302that usually have very similar meanings across architectures. The most
1303commonly used constraints are @samp{m} and @samp{r} (for memory and
1304general-purpose registers respectively; @pxref{Simple Constraints}), and
1305@samp{I}, usually the letter indicating the most common
1306immediate-constant format.
1307
9c34dbbf
ZW
1308For each machine architecture, the
1309@file{config/@var{machine}/@var{machine}.h} file defines additional
1310constraints. These constraints are used by the compiler itself for
1311instruction generation, as well as for @code{asm} statements; therefore,
1312some of the constraints are not particularly interesting for @code{asm}.
1313The constraints are defined through these macros:
03dda8e3
RK
1314
1315@table @code
1316@item REG_CLASS_FROM_LETTER
1317Register class constraints (usually lower case).
1318
1319@item CONST_OK_FOR_LETTER_P
1320Immediate constant constraints, for non-floating point constants of
1321word size or smaller precision (usually upper case).
1322
1323@item CONST_DOUBLE_OK_FOR_LETTER_P
1324Immediate constant constraints, for all floating point constants and for
1325constants of greater than word size precision (usually upper case).
1326
1327@item EXTRA_CONSTRAINT
1328Special cases of registers or memory. This macro is not required, and
1329is only defined for some machines.
1330@end table
1331
1332Inspecting these macro definitions in the compiler source for your
1333machine is the best way to be certain you have the right constraints.
1334However, here is a summary of the machine-dependent constraints
1335available on some particular machines.
1336
1337@table @emph
1338@item ARM family---@file{arm.h}
1339@table @code
1340@item f
1341Floating-point register
1342
1343@item F
1344One of the floating-point constants 0.0, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0
1345or 10.0
1346
1347@item G
1348Floating-point constant that would satisfy the constraint @samp{F} if it
1349were negated
1350
1351@item I
1352Integer that is valid as an immediate operand in a data processing
1353instruction. That is, an integer in the range 0 to 255 rotated by a
1354multiple of 2
1355
1356@item J
630d3d5a 1357Integer in the range @minus{}4095 to 4095
03dda8e3
RK
1358
1359@item K
1360Integer that satisfies constraint @samp{I} when inverted (ones complement)
1361
1362@item L
1363Integer that satisfies constraint @samp{I} when negated (twos complement)
1364
1365@item M
1366Integer in the range 0 to 32
1367
1368@item Q
1369A memory reference where the exact address is in a single register
1370(`@samp{m}' is preferable for @code{asm} statements)
1371
1372@item R
1373An item in the constant pool
1374
1375@item S
1376A symbol in the text segment of the current file
1377@end table
1378
052a4b28
DC
1379@item AVR family---@file{avr.h}
1380@table @code
1381@item l
1382Registers from r0 to r15
1383
1384@item a
1385Registers from r16 to r23
1386
1387@item d
1388Registers from r16 to r31
1389
1390@item w
3a69a7d5 1391Registers from r24 to r31. These registers can be used in @samp{adiw} command
052a4b28
DC
1392
1393@item e
d7d9c429 1394Pointer register (r26--r31)
052a4b28
DC
1395
1396@item b
d7d9c429 1397Base pointer register (r28--r31)
052a4b28 1398
3a69a7d5
MM
1399@item q
1400Stack pointer register (SPH:SPL)
1401
052a4b28
DC
1402@item t
1403Temporary register r0
1404
1405@item x
1406Register pair X (r27:r26)
1407
1408@item y
1409Register pair Y (r29:r28)
1410
1411@item z
1412Register pair Z (r31:r30)
1413
1414@item I
630d3d5a 1415Constant greater than @minus{}1, less than 64
052a4b28
DC
1416
1417@item J
630d3d5a 1418Constant greater than @minus{}64, less than 1
052a4b28
DC
1419
1420@item K
1421Constant integer 2
1422
1423@item L
1424Constant integer 0
1425
1426@item M
1427Constant that fits in 8 bits
1428
1429@item N
630d3d5a 1430Constant integer @minus{}1
052a4b28
DC
1431
1432@item O
3a69a7d5 1433Constant integer 8, 16, or 24
052a4b28
DC
1434
1435@item P
1436Constant integer 1
1437
1438@item G
1439A floating point constant 0.0
1440@end table
1441
03dda8e3
RK
1442@item IBM RS6000---@file{rs6000.h}
1443@table @code
1444@item b
1445Address base register
1446
1447@item f
1448Floating point register
1449
1450@item h
1451@samp{MQ}, @samp{CTR}, or @samp{LINK} register
1452
1453@item q
1454@samp{MQ} register
1455
1456@item c
1457@samp{CTR} register
1458
1459@item l
1460@samp{LINK} register
1461
1462@item x
1463@samp{CR} register (condition register) number 0
1464
1465@item y
1466@samp{CR} register (condition register)
1467
8f685459
DE
1468@item z
1469@samp{FPMEM} stack memory for FPR-GPR transfers
1470
03dda8e3 1471@item I
1e5f973d 1472Signed 16-bit constant
03dda8e3
RK
1473
1474@item J
ebb48a4d 1475Unsigned 16-bit constant shifted left 16 bits (use @samp{L} instead for
5f59ecb7 1476@code{SImode} constants)
03dda8e3
RK
1477
1478@item K
1e5f973d 1479Unsigned 16-bit constant
03dda8e3
RK
1480
1481@item L
1e5f973d 1482Signed 16-bit constant shifted left 16 bits
03dda8e3
RK
1483
1484@item M
1485Constant larger than 31
1486
1487@item N
1488Exact power of 2
1489
1490@item O
1491Zero
1492
1493@item P
1e5f973d 1494Constant whose negation is a signed 16-bit constant
03dda8e3
RK
1495
1496@item G
1497Floating point constant that can be loaded into a register with one
1498instruction per word
1499
1500@item Q
1501Memory operand that is an offset from a register (@samp{m} is preferable
1502for @code{asm} statements)
1503
1504@item R
1505AIX TOC entry
1506
1507@item S
8f685459 1508Constant suitable as a 64-bit mask operand
03dda8e3 1509
5f59ecb7
DE
1510@item T
1511Constant suitable as a 32-bit mask operand
1512
03dda8e3
RK
1513@item U
1514System V Release 4 small data area reference
1515@end table
1516
1517@item Intel 386---@file{i386.h}
1518@table @code
1519@item q
0c56474e 1520@samp{a}, @code{b}, @code{c}, or @code{d} register for the i386.
1e5f973d 1521For x86-64 it is equivalent to @samp{r} class. (for 8-bit instructions that
0c56474e
JH
1522do not use upper halves)
1523
1524@item Q
1e5f973d 1525@samp{a}, @code{b}, @code{c}, or @code{d} register. (for 8-bit instructions,
0c56474e
JH
1526that do use upper halves)
1527
1528@item R
d7d9c429 1529Legacy register---equivalent to @code{r} class in i386 mode.
1e5f973d 1530(for non-8-bit registers used together with 8-bit upper halves in a single
0c56474e 1531instruction)
03dda8e3
RK
1532
1533@item A
994682b9
AJ
1534Specifies the @samp{a} or @samp{d} registers. This is primarily useful
1535for 64-bit integer values (when in 32-bit mode) intended to be returned
1536with the @samp{d} register holding the most significant bits and the
1537@samp{a} register holding the least significant bits.
03dda8e3
RK
1538
1539@item f
1540Floating point register
1541
1542@item t
1543First (top of stack) floating point register
1544
1545@item u
1546Second floating point register
1547
1548@item a
1549@samp{a} register
1550
1551@item b
1552@samp{b} register
1553
1554@item c
1555@samp{c} register
1556
f8ca7923 1557@item C
c0478a66 1558Specifies constant that can be easily constructed in SSE register without
f8ca7923
JH
1559loading it from memory.
1560
03dda8e3
RK
1561@item d
1562@samp{d} register
1563
1564@item D
1565@samp{di} register
1566
1567@item S
1568@samp{si} register
1569
994682b9
AJ
1570@item x
1571@samp{xmm} SSE register
1572
1573@item y
1574MMX register
1575
03dda8e3 1576@item I
1e5f973d 1577Constant in range 0 to 31 (for 32-bit shifts)
03dda8e3
RK
1578
1579@item J
1e5f973d 1580Constant in range 0 to 63 (for 64-bit shifts)
03dda8e3
RK
1581
1582@item K
1583@samp{0xff}
1584
1585@item L
1586@samp{0xffff}
1587
1588@item M
15890, 1, 2, or 3 (shifts for @code{lea} instruction)
1590
1591@item N
1592Constant in range 0 to 255 (for @code{out} instruction)
1593
0c56474e 1594@item Z
aee96fe9 1595Constant in range 0 to @code{0xffffffff} or symbolic reference known to fit specified range.
1e5f973d 1596(for using immediates in zero extending 32-bit to 64-bit x86-64 instructions)
0c56474e
JH
1597
1598@item e
630d3d5a 1599Constant in range @minus{}2147483648 to 2147483647 or symbolic reference known to fit specified range.
1e5f973d 1600(for using immediates in 64-bit x86-64 instructions)
0c56474e 1601
03dda8e3
RK
1602@item G
1603Standard 80387 floating point constant
1604@end table
1605
1606@item Intel 960---@file{i960.h}
1607@table @code
1608@item f
1609Floating point register (@code{fp0} to @code{fp3})
1610
1611@item l
1612Local register (@code{r0} to @code{r15})
1613
1614@item b
1615Global register (@code{g0} to @code{g15})
1616
1617@item d
1618Any local or global register
1619
1620@item I
1621Integers from 0 to 31
1622
1623@item J
16240
1625
1626@item K
630d3d5a 1627Integers from @minus{}31 to 0
03dda8e3
RK
1628
1629@item G
1630Floating point 0
1631
1632@item H
1633Floating point 1
1634@end table
7a430e3b
SC
1635
1636@item Intel IA-64---@file{ia64.h}
1637@table @code
1638@item a
1639General register @code{r0} to @code{r3} for @code{addl} instruction
1640
1641@item b
1642Branch register
1643
1644@item c
1645Predicate register (@samp{c} as in ``conditional'')
1646
1647@item d
1648Application register residing in M-unit
1649
1650@item e
1651Application register residing in I-unit
1652
1653@item f
1654Floating-point register
1655
1656@item m
1657Memory operand.
1658Remember that @samp{m} allows postincrement and postdecrement which
1659require printing with @samp{%Pn} on IA-64.
1660Use @samp{S} to disallow postincrement and postdecrement.
1661
1662@item G
1663Floating-point constant 0.0 or 1.0
1664
1665@item I
166614-bit signed integer constant
1667
1668@item J
166922-bit signed integer constant
1670
1671@item K
16728-bit signed integer constant for logical instructions
1673
1674@item L
16758-bit adjusted signed integer constant for compare pseudo-ops
1676
1677@item M
16786-bit unsigned integer constant for shift counts
1679
1680@item N
16819-bit signed integer constant for load and store postincrements
1682
1683@item O
1684The constant zero
1685
1686@item P
16870 or -1 for @code{dep} instruction
1688
1689@item Q
1690Non-volatile memory for floating-point loads and stores
1691
1692@item R
1693Integer constant in the range 1 to 4 for @code{shladd} instruction
1694
1695@item S
1696Memory operand except postincrement and postdecrement
1697@end table
03dda8e3 1698
70899148
BS
1699@item FRV---@file{frv.h}
1700@table @code
1701@item a
840758d3 1702Register in the class @code{ACC_REGS} (@code{acc0} to @code{acc7}).
70899148
BS
1703
1704@item b
840758d3 1705Register in the class @code{EVEN_ACC_REGS} (@code{acc0} to @code{acc7}).
70899148
BS
1706
1707@item c
840758d3
BS
1708Register in the class @code{CC_REGS} (@code{fcc0} to @code{fcc3} and
1709@code{icc0} to @code{icc3}).
70899148
BS
1710
1711@item d
840758d3 1712Register in the class @code{GPR_REGS} (@code{gr0} to @code{gr63}).
70899148
BS
1713
1714@item e
840758d3 1715Register in the class @code{EVEN_REGS} (@code{gr0} to @code{gr63}).
70899148
BS
1716Odd registers are excluded not in the class but through the use of a machine
1717mode larger than 4 bytes.
1718
1719@item f
840758d3 1720Register in the class @code{FPR_REGS} (@code{fr0} to @code{fr63}).
70899148
BS
1721
1722@item h
840758d3 1723Register in the class @code{FEVEN_REGS} (@code{fr0} to @code{fr63}).
70899148
BS
1724Odd registers are excluded not in the class but through the use of a machine
1725mode larger than 4 bytes.
1726
1727@item l
840758d3 1728Register in the class @code{LR_REG} (the @code{lr} register).
70899148
BS
1729
1730@item q
840758d3 1731Register in the class @code{QUAD_REGS} (@code{gr2} to @code{gr63}).
70899148
BS
1732Register numbers not divisible by 4 are excluded not in the class but through
1733the use of a machine mode larger than 8 bytes.
1734
1735@item t
840758d3 1736Register in the class @code{ICC_REGS} (@code{icc0} to @code{icc3}).
70899148
BS
1737
1738@item u
840758d3 1739Register in the class @code{FCC_REGS} (@code{fcc0} to @code{fcc3}).
70899148
BS
1740
1741@item v
840758d3 1742Register in the class @code{ICR_REGS} (@code{cc4} to @code{cc7}).
70899148
BS
1743
1744@item w
840758d3 1745Register in the class @code{FCR_REGS} (@code{cc0} to @code{cc3}).
70899148
BS
1746
1747@item x
840758d3 1748Register in the class @code{QUAD_FPR_REGS} (@code{fr0} to @code{fr63}).
70899148
BS
1749Register numbers not divisible by 4 are excluded not in the class but through
1750the use of a machine mode larger than 8 bytes.
1751
1752@item z
840758d3 1753Register in the class @code{SPR_REGS} (@code{lcr} and @code{lr}).
70899148
BS
1754
1755@item A
840758d3 1756Register in the class @code{QUAD_ACC_REGS} (@code{acc0} to @code{acc7}).
70899148
BS
1757
1758@item B
840758d3 1759Register in the class @code{ACCG_REGS} (@code{accg0} to @code{accg7}).
70899148
BS
1760
1761@item C
840758d3 1762Register in the class @code{CR_REGS} (@code{cc0} to @code{cc7}).
70899148
BS
1763
1764@item G
1765Floating point constant zero
1766
1767@item I
17686-bit signed integer constant
1769
1770@item J
177110-bit signed integer constant
1772
1773@item L
177416-bit signed integer constant
1775
1776@item M
177716-bit unsigned integer constant
1778
1779@item N
840758d3
BS
178012-bit signed integer constant that is negative---i.e.@: in the
1781range of @minus{}2048 to @minus{}1
70899148
BS
1782
1783@item O
1784Constant zero
1785
1786@item P
840758d3 178712-bit signed integer constant that is greater than zero---i.e.@: in the
70899148
BS
1788range of 1 to 2047.
1789
1790@end table
1791
e3223ea2
DC
1792@item IP2K---@file{ip2k.h}
1793@table @code
1794@item a
1795@samp{DP} or @samp{IP} registers (general address)
1796
1797@item f
1798@samp{IP} register
1799
1800@item j
1801@samp{IPL} register
1802
1803@item k
1804@samp{IPH} register
1805
1806@item b
1807@samp{DP} register
1808
1809@item y
1810@samp{DPH} register
1811
1812@item z
1813@samp{DPL} register
1814
1815@item q
1816@samp{SP} register
1817
1818@item c
1819@samp{DP} or @samp{SP} registers (offsettable address)
1820
1821@item d
1822Non-pointer registers (not @samp{SP}, @samp{DP}, @samp{IP})
1823
1824@item u
1825Non-SP registers (everything except @samp{SP})
1826
1827@item R
1828Indirect thru @samp{IP} - Avoid this except for @code{QImode}, since we
1829can't access extra bytes
1830
1831@item S
1832Indirect thru @samp{SP} or @samp{DP} with short displacement (0..127)
1833
1834@item T
1835Data-section immediate value
1836
1837@item I
1838Integers from @minus{}255 to @minus{}1
1839
1840@item J
1841Integers from 0 to 7---valid bit number in a register
1842
1843@item K
1844Integers from 0 to 127---valid displacement for addressing mode
1845
1846@item L
1847Integers from 1 to 127
1848
1849@item M
1850Integer @minus{}1
1851
1852@item N
1853Integer 1
1854
1855@item O
1856Zero
1857
1858@item P
1859Integers from 0 to 255
1860@end table
1861
4226378a
PK
1862@item MIPS---@file{mips.h}
1863@table @code
1864@item d
1865General-purpose integer register
1866
1867@item f
1868Floating-point register (if available)
1869
1870@item h
1871@samp{Hi} register
1872
1873@item l
1874@samp{Lo} register
1875
1876@item x
1877@samp{Hi} or @samp{Lo} register
1878
1879@item y
1880General-purpose integer register
1881
1882@item z
1883Floating-point status register
1884
1885@item I
1886Signed 16-bit constant (for arithmetic instructions)
1887
1888@item J
1889Zero
1890
1891@item K
1892Zero-extended 16-bit constant (for logic instructions)
1893
1894@item L
1895Constant with low 16 bits zero (can be loaded with @code{lui})
1896
1897@item M
189832-bit constant which requires two instructions to load (a constant
1899which is not @samp{I}, @samp{K}, or @samp{L})
1900
1901@item N
1902Negative 16-bit constant
1903
1904@item O
1905Exact power of two
1906
1907@item P
1908Positive 16-bit constant
1909
1910@item G
1911Floating point zero
1912
1913@item Q
1914Memory reference that can be loaded with more than one instruction
1915(@samp{m} is preferable for @code{asm} statements)
1916
1917@item R
1918Memory reference that can be loaded with one instruction
1919(@samp{m} is preferable for @code{asm} statements)
1920
1921@item S
1922Memory reference in external OSF/rose PIC format
1923(@samp{m} is preferable for @code{asm} statements)
1924@end table
1925
03dda8e3
RK
1926@item Motorola 680x0---@file{m68k.h}
1927@table @code
1928@item a
1929Address register
1930
1931@item d
1932Data register
1933
1934@item f
193568881 floating-point register, if available
1936
03dda8e3
RK
1937@item I
1938Integer in the range 1 to 8
1939
1940@item J
1e5f973d 194116-bit signed number
03dda8e3
RK
1942
1943@item K
1944Signed number whose magnitude is greater than 0x80
1945
1946@item L
630d3d5a 1947Integer in the range @minus{}8 to @minus{}1
03dda8e3
RK
1948
1949@item M
1950Signed number whose magnitude is greater than 0x100
1951
1952@item G
1953Floating point constant that is not a 68881 constant
03dda8e3
RK
1954@end table
1955
2856c3e3
SC
1956@item Motorola 68HC11 & 68HC12 families---@file{m68hc11.h}
1957@table @code
1958@item a
1959Register 'a'
1960
1961@item b
1962Register 'b'
1963
1964@item d
1965Register 'd'
1966
1967@item q
1968An 8-bit register
1969
1970@item t
1971Temporary soft register _.tmp
1972
1973@item u
1974A soft register _.d1 to _.d31
1975
1976@item w
1977Stack pointer register
1978
1979@item x
1980Register 'x'
1981
1982@item y
1983Register 'y'
1984
1985@item z
1986Pseudo register 'z' (replaced by 'x' or 'y' at the end)
1987
1988@item A
1989An address register: x, y or z
1990
1991@item B
1992An address register: x or y
1993
1994@item D
1995Register pair (x:d) to form a 32-bit value
1996
1997@item L
630d3d5a 1998Constants in the range @minus{}65536 to 65535
2856c3e3
SC
1999
2000@item M
2001Constants whose 16-bit low part is zero
2002
2003@item N
630d3d5a 2004Constant integer 1 or @minus{}1
2856c3e3
SC
2005
2006@item O
2007Constant integer 16
2008
2009@item P
630d3d5a 2010Constants in the range @minus{}8 to 2
2856c3e3
SC
2011
2012@end table
2013
03dda8e3
RK
2014@need 1000
2015@item SPARC---@file{sparc.h}
2016@table @code
2017@item f
53e5f173
EB
2018Floating-point register on the SPARC-V8 architecture and
2019lower floating-point register on the SPARC-V9 architecture.
03dda8e3
RK
2020
2021@item e
53e5f173
EB
2022Floating-point register. It is equivalent to @samp{f} on the
2023SPARC-V8 architecture and contains both lower and upper
2024floating-point registers on the SPARC-V9 architecture.
03dda8e3 2025
8a69f99f
EB
2026@item c
2027Floating-point condition code register.
2028
2029@item d
53e5f173
EB
2030Lower floating-point register. It is only valid on the SPARC-V9
2031architecture when the Visual Instruction Set is available.
8a69f99f
EB
2032
2033@item b
53e5f173
EB
2034Floating-point register. It is only valid on the SPARC-V9 architecture
2035when the Visual Instruction Set is available.
8a69f99f
EB
2036
2037@item h
203864-bit global or out register for the SPARC-V8+ architecture.
2039
03dda8e3 2040@item I
1e5f973d 2041Signed 13-bit constant
03dda8e3
RK
2042
2043@item J
2044Zero
2045
2046@item K
1e5f973d 204732-bit constant with the low 12 bits clear (a constant that can be
03dda8e3
RK
2048loaded with the @code{sethi} instruction)
2049
7d6040e8
AO
2050@item L
2051A constant in the range supported by @code{movcc} instructions
2052
2053@item M
2054A constant in the range supported by @code{movrcc} instructions
2055
2056@item N
2057Same as @samp{K}, except that it verifies that bits that are not in the
57694e40 2058lower 32-bit range are all zero. Must be used instead of @samp{K} for
7d6040e8
AO
2059modes wider than @code{SImode}
2060
ef0139b1
EB
2061@item O
2062The constant 4096
2063
03dda8e3
RK
2064@item G
2065Floating-point zero
2066
2067@item H
1e5f973d 2068Signed 13-bit constant, sign-extended to 32 or 64 bits
03dda8e3
RK
2069
2070@item Q
62190128
DM
2071Floating-point constant whose integral representation can
2072be moved into an integer register using a single sethi
2073instruction
2074
2075@item R
2076Floating-point constant whose integral representation can
2077be moved into an integer register using a single mov
2078instruction
03dda8e3
RK
2079
2080@item S
62190128
DM
2081Floating-point constant whose integral representation can
2082be moved into an integer register using a high/lo_sum
2083instruction sequence
03dda8e3
RK
2084
2085@item T
2086Memory address aligned to an 8-byte boundary
2087
2088@item U
2089Even register
6ca30df6 2090
7a31a340
DM
2091@item W
2092Memory address for @samp{e} constraint registers.
2093
6ca30df6
MH
2094@end table
2095
2096@item TMS320C3x/C4x---@file{c4x.h}
2097@table @code
2098@item a
2099Auxiliary (address) register (ar0-ar7)
2100
2101@item b
2102Stack pointer register (sp)
2103
2104@item c
1e5f973d 2105Standard (32-bit) precision integer register
6ca30df6
MH
2106
2107@item f
1e5f973d 2108Extended (40-bit) precision register (r0-r11)
6ca30df6
MH
2109
2110@item k
2111Block count register (bk)
2112
2113@item q
1e5f973d 2114Extended (40-bit) precision low register (r0-r7)
6ca30df6
MH
2115
2116@item t
1e5f973d 2117Extended (40-bit) precision register (r0-r1)
6ca30df6
MH
2118
2119@item u
1e5f973d 2120Extended (40-bit) precision register (r2-r3)
6ca30df6
MH
2121
2122@item v
2123Repeat count register (rc)
2124
2125@item x
2126Index register (ir0-ir1)
2127
2128@item y
2129Status (condition code) register (st)
2130
2131@item z
2132Data page register (dp)
2133
2134@item G
2135Floating-point zero
2136
2137@item H
1e5f973d 2138Immediate 16-bit floating-point constant
6ca30df6
MH
2139
2140@item I
1e5f973d 2141Signed 16-bit constant
6ca30df6
MH
2142
2143@item J
1e5f973d 2144Signed 8-bit constant
6ca30df6
MH
2145
2146@item K
1e5f973d 2147Signed 5-bit constant
6ca30df6
MH
2148
2149@item L
1e5f973d 2150Unsigned 16-bit constant
6ca30df6
MH
2151
2152@item M
1e5f973d 2153Unsigned 8-bit constant
6ca30df6
MH
2154
2155@item N
1e5f973d 2156Ones complement of unsigned 16-bit constant
6ca30df6
MH
2157
2158@item O
1e5f973d 2159High 16-bit constant (32-bit constant with 16 LSBs zero)
6ca30df6
MH
2160
2161@item Q
ebb48a4d 2162Indirect memory reference with signed 8-bit or index register displacement
6ca30df6
MH
2163
2164@item R
1e5f973d 2165Indirect memory reference with unsigned 5-bit displacement
6ca30df6
MH
2166
2167@item S
ebb48a4d 2168Indirect memory reference with 1 bit or index register displacement
6ca30df6
MH
2169
2170@item T
2171Direct memory reference
2172
2173@item U
2174Symbolic address
2175
03dda8e3 2176@end table
91abf72d
HP
2177
2178@item S/390 and zSeries---@file{s390.h}
2179@table @code
2180@item a
2181Address register (general purpose register except r0)
2182
2183@item d
2184Data register (arbitrary general purpose register)
2185
2186@item f
2187Floating-point register
2188
2189@item I
2190Unsigned 8-bit constant (0--255)
2191
2192@item J
2193Unsigned 12-bit constant (0--4095)
2194
2195@item K
2196Signed 16-bit constant (@minus{}32768--32767)
2197
2198@item L
2199Unsigned 16-bit constant (0--65535)
2200
2201@item Q
2202Memory reference without index register
2203
2204@item S
2205Symbolic constant suitable for use with the @code{larl} instruction
2206
2207@end table
2208
9f339dde
GK
2209@item Xstormy16---@file{stormy16.h}
2210@table @code
2211@item a
2212Register r0.
2213
2214@item b
2215Register r1.
2216
2217@item c
2218Register r2.
2219
2220@item d
2221Register r8.
2222
2223@item e
2224Registers r0 through r7.
2225
2226@item t
2227Registers r0 and r1.
2228
2229@item y
2230The carry register.
2231
2232@item z
2233Registers r8 and r9.
2234
2235@item I
2236A constant between 0 and 3 inclusive.
2237
2238@item J
2239A constant that has exactly one bit set.
2240
2241@item K
2242A constant that has exactly one bit clear.
2243
2244@item L
2245A constant between 0 and 255 inclusive.
2246
2247@item M
69a0611f 2248A constant between @minus{}255 and 0 inclusive.
9f339dde
GK
2249
2250@item N
69a0611f 2251A constant between @minus{}3 and 0 inclusive.
9f339dde
GK
2252
2253@item O
2254A constant between 1 and 4 inclusive.
2255
2256@item P
69a0611f 2257A constant between @minus{}4 and @minus{}1 inclusive.
9f339dde
GK
2258
2259@item Q
2260A memory reference that is a stack push.
2261
2262@item R
2263A memory reference that is a stack pop.
2264
2265@item S
2266A memory reference that refers to an constant address of known value.
2267
2268@item T
2269The register indicated by Rx (not implemented yet).
2270
2271@item U
2272A constant that is not between 2 and 15 inclusive.
2273
e2ce66a9
DD
2274@item Z
2275The constant 0.
2276
9f339dde
GK
2277@end table
2278
03984308
BW
2279@item Xtensa---@file{xtensa.h}
2280@table @code
2281@item a
2282General-purpose 32-bit register
2283
2284@item b
2285One-bit boolean register
2286
2287@item A
2288MAC16 40-bit accumulator register
2289
2290@item I
2291Signed 12-bit integer constant, for use in MOVI instructions
2292
2293@item J
2294Signed 8-bit integer constant, for use in ADDI instructions
2295
2296@item K
2297Integer constant valid for BccI instructions
2298
2299@item L
2300Unsigned constant valid for BccUI instructions
2301
2302@end table
2303
03dda8e3
RK
2304@end table
2305
03dda8e3
RK
2306@ifset INTERNALS
2307@node Standard Names
2308@section Standard Pattern Names For Generation
2309@cindex standard pattern names
2310@cindex pattern names
2311@cindex names, pattern
2312
2313Here is a table of the instruction names that are meaningful in the RTL
2314generation pass of the compiler. Giving one of these names to an
2315instruction pattern tells the RTL generation pass that it can use the
556e0f21 2316pattern to accomplish a certain task.
03dda8e3
RK
2317
2318@table @asis
2319@cindex @code{mov@var{m}} instruction pattern
2320@item @samp{mov@var{m}}
2321Here @var{m} stands for a two-letter machine mode name, in lower case.
2322This instruction pattern moves data with that machine mode from operand
23231 to operand 0. For example, @samp{movsi} moves full-word data.
2324
2325If operand 0 is a @code{subreg} with mode @var{m} of a register whose
2326own mode is wider than @var{m}, the effect of this instruction is
2327to store the specified value in the part of the register that corresponds
8feb4e28
JL
2328to mode @var{m}. Bits outside of @var{m}, but which are within the
2329same target word as the @code{subreg} are undefined. Bits which are
2330outside the target word are left unchanged.
03dda8e3
RK
2331
2332This class of patterns is special in several ways. First of all, each
65945ec1
HPN
2333of these names up to and including full word size @emph{must} be defined,
2334because there is no other way to copy a datum from one place to another.
2335If there are patterns accepting operands in larger modes,
2336@samp{mov@var{m}} must be defined for integer modes of those sizes.
03dda8e3
RK
2337
2338Second, these patterns are not used solely in the RTL generation pass.
2339Even the reload pass can generate move insns to copy values from stack
2340slots into temporary registers. When it does so, one of the operands is
2341a hard register and the other is an operand that can need to be reloaded
2342into a register.
2343
2344@findex force_reg
2345Therefore, when given such a pair of operands, the pattern must generate
2346RTL which needs no reloading and needs no temporary registers---no
2347registers other than the operands. For example, if you support the
2348pattern with a @code{define_expand}, then in such a case the
2349@code{define_expand} mustn't call @code{force_reg} or any other such
2350function which might generate new pseudo registers.
2351
2352This requirement exists even for subword modes on a RISC machine where
2353fetching those modes from memory normally requires several insns and
39ed8974 2354some temporary registers.
03dda8e3
RK
2355
2356@findex change_address
2357During reload a memory reference with an invalid address may be passed
2358as an operand. Such an address will be replaced with a valid address
2359later in the reload pass. In this case, nothing may be done with the
2360address except to use it as it stands. If it is copied, it will not be
2361replaced with a valid address. No attempt should be made to make such
2362an address into a valid address and no routine (such as
2363@code{change_address}) that will do so may be called. Note that
2364@code{general_operand} will fail when applied to such an address.
2365
2366@findex reload_in_progress
2367The global variable @code{reload_in_progress} (which must be explicitly
2368declared if required) can be used to determine whether such special
2369handling is required.
2370
2371The variety of operands that have reloads depends on the rest of the
2372machine description, but typically on a RISC machine these can only be
2373pseudo registers that did not get hard registers, while on other
2374machines explicit memory references will get optional reloads.
2375
2376If a scratch register is required to move an object to or from memory,
f1db3576
JL
2377it can be allocated using @code{gen_reg_rtx} prior to life analysis.
2378
9c34dbbf
ZW
2379If there are cases which need scratch registers during or after reload,
2380you must define @code{SECONDARY_INPUT_RELOAD_CLASS} and/or
03dda8e3
RK
2381@code{SECONDARY_OUTPUT_RELOAD_CLASS} to detect them, and provide
2382patterns @samp{reload_in@var{m}} or @samp{reload_out@var{m}} to handle
2383them. @xref{Register Classes}.
2384
f1db3576
JL
2385@findex no_new_pseudos
2386The global variable @code{no_new_pseudos} can be used to determine if it
2387is unsafe to create new pseudo registers. If this variable is nonzero, then
2388it is unsafe to call @code{gen_reg_rtx} to allocate a new pseudo.
2389
956d6950 2390The constraints on a @samp{mov@var{m}} must permit moving any hard
03dda8e3
RK
2391register to any other hard register provided that
2392@code{HARD_REGNO_MODE_OK} permits mode @var{m} in both registers and
2393@code{REGISTER_MOVE_COST} applied to their classes returns a value of 2.
2394
956d6950 2395It is obligatory to support floating point @samp{mov@var{m}}
03dda8e3
RK
2396instructions into and out of any registers that can hold fixed point
2397values, because unions and structures (which have modes @code{SImode} or
2398@code{DImode}) can be in those registers and they may have floating
2399point members.
2400
956d6950 2401There may also be a need to support fixed point @samp{mov@var{m}}
03dda8e3
RK
2402instructions in and out of floating point registers. Unfortunately, I
2403have forgotten why this was so, and I don't know whether it is still
2404true. If @code{HARD_REGNO_MODE_OK} rejects fixed point values in
2405floating point registers, then the constraints of the fixed point
956d6950 2406@samp{mov@var{m}} instructions must be designed to avoid ever trying to
03dda8e3
RK
2407reload into a floating point register.
2408
2409@cindex @code{reload_in} instruction pattern
2410@cindex @code{reload_out} instruction pattern
2411@item @samp{reload_in@var{m}}
2412@itemx @samp{reload_out@var{m}}
2413Like @samp{mov@var{m}}, but used when a scratch register is required to
2414move between operand 0 and operand 1. Operand 2 describes the scratch
2415register. See the discussion of the @code{SECONDARY_RELOAD_CLASS}
2416macro in @pxref{Register Classes}.
2417
d989f648 2418There are special restrictions on the form of the @code{match_operand}s
f282ffb3 2419used in these patterns. First, only the predicate for the reload
560dbedd
RH
2420operand is examined, i.e., @code{reload_in} examines operand 1, but not
2421the predicates for operand 0 or 2. Second, there may be only one
d989f648
RH
2422alternative in the constraints. Third, only a single register class
2423letter may be used for the constraint; subsequent constraint letters
2424are ignored. As a special exception, an empty constraint string
2425matches the @code{ALL_REGS} register class. This may relieve ports
2426of the burden of defining an @code{ALL_REGS} constraint letter just
2427for these patterns.
2428
03dda8e3
RK
2429@cindex @code{movstrict@var{m}} instruction pattern
2430@item @samp{movstrict@var{m}}
2431Like @samp{mov@var{m}} except that if operand 0 is a @code{subreg}
2432with mode @var{m} of a register whose natural mode is wider,
2433the @samp{movstrict@var{m}} instruction is guaranteed not to alter
2434any of the register except the part which belongs to mode @var{m}.
2435
2436@cindex @code{load_multiple} instruction pattern
2437@item @samp{load_multiple}
2438Load several consecutive memory locations into consecutive registers.
2439Operand 0 is the first of the consecutive registers, operand 1
2440is the first memory location, and operand 2 is a constant: the
2441number of consecutive registers.
2442
2443Define this only if the target machine really has such an instruction;
2444do not define this if the most efficient way of loading consecutive
2445registers from memory is to do them one at a time.
2446
2447On some machines, there are restrictions as to which consecutive
2448registers can be stored into memory, such as particular starting or
2449ending register numbers or only a range of valid counts. For those
2450machines, use a @code{define_expand} (@pxref{Expander Definitions})
2451and make the pattern fail if the restrictions are not met.
2452
2453Write the generated insn as a @code{parallel} with elements being a
2454@code{set} of one register from the appropriate memory location (you may
2455also need @code{use} or @code{clobber} elements). Use a
2456@code{match_parallel} (@pxref{RTL Template}) to recognize the insn. See
c9693e96 2457@file{rs6000.md} for examples of the use of this insn pattern.
03dda8e3
RK
2458
2459@cindex @samp{store_multiple} instruction pattern
2460@item @samp{store_multiple}
2461Similar to @samp{load_multiple}, but store several consecutive registers
2462into consecutive memory locations. Operand 0 is the first of the
2463consecutive memory locations, operand 1 is the first register, and
2464operand 2 is a constant: the number of consecutive registers.
2465
38f4324c
JH
2466@cindex @code{push@var{m}} instruction pattern
2467@item @samp{push@var{m}}
299c5111 2468Output a push instruction. Operand 0 is value to push. Used only when
38f4324c
JH
2469@code{PUSH_ROUNDING} is defined. For historical reason, this pattern may be
2470missing and in such case an @code{mov} expander is used instead, with a
6e9aac46 2471@code{MEM} expression forming the push operation. The @code{mov} expander
38f4324c
JH
2472method is deprecated.
2473
03dda8e3
RK
2474@cindex @code{add@var{m}3} instruction pattern
2475@item @samp{add@var{m}3}
2476Add operand 2 and operand 1, storing the result in operand 0. All operands
2477must have mode @var{m}. This can be used even on two-address machines, by
2478means of constraints requiring operands 1 and 0 to be the same location.
2479
2480@cindex @code{sub@var{m}3} instruction pattern
2481@cindex @code{mul@var{m}3} instruction pattern
2482@cindex @code{div@var{m}3} instruction pattern
2483@cindex @code{udiv@var{m}3} instruction pattern
2484@cindex @code{mod@var{m}3} instruction pattern
2485@cindex @code{umod@var{m}3} instruction pattern
2486@cindex @code{smin@var{m}3} instruction pattern
2487@cindex @code{smax@var{m}3} instruction pattern
2488@cindex @code{umin@var{m}3} instruction pattern
2489@cindex @code{umax@var{m}3} instruction pattern
2490@cindex @code{and@var{m}3} instruction pattern
2491@cindex @code{ior@var{m}3} instruction pattern
2492@cindex @code{xor@var{m}3} instruction pattern
2493@item @samp{sub@var{m}3}, @samp{mul@var{m}3}
2494@itemx @samp{div@var{m}3}, @samp{udiv@var{m}3}, @samp{mod@var{m}3}, @samp{umod@var{m}3}
2495@itemx @samp{smin@var{m}3}, @samp{smax@var{m}3}, @samp{umin@var{m}3}, @samp{umax@var{m}3}
2496@itemx @samp{and@var{m}3}, @samp{ior@var{m}3}, @samp{xor@var{m}3}
2497Similar, for other arithmetic operations.
b71b019a
JH
2498@cindex @code{min@var{m}3} instruction pattern
2499@cindex @code{max@var{m}3} instruction pattern
2500@itemx @samp{min@var{m}3}, @samp{max@var{m}3}
2501Floating point min and max operations. If both operands are zeros,
2502or if either operand is NaN, then it is unspecified which of the two
2503operands is returned as the result.
2504
03dda8e3
RK
2505
2506@cindex @code{mulhisi3} instruction pattern
2507@item @samp{mulhisi3}
2508Multiply operands 1 and 2, which have mode @code{HImode}, and store
2509a @code{SImode} product in operand 0.
2510
2511@cindex @code{mulqihi3} instruction pattern
2512@cindex @code{mulsidi3} instruction pattern
2513@item @samp{mulqihi3}, @samp{mulsidi3}
2514Similar widening-multiplication instructions of other widths.
2515
2516@cindex @code{umulqihi3} instruction pattern
2517@cindex @code{umulhisi3} instruction pattern
2518@cindex @code{umulsidi3} instruction pattern
2519@item @samp{umulqihi3}, @samp{umulhisi3}, @samp{umulsidi3}
2520Similar widening-multiplication instructions that do unsigned
2521multiplication.
2522
2523@cindex @code{smul@var{m}3_highpart} instruction pattern
759c58af 2524@item @samp{smul@var{m}3_highpart}
03dda8e3
RK
2525Perform a signed multiplication of operands 1 and 2, which have mode
2526@var{m}, and store the most significant half of the product in operand 0.
2527The least significant half of the product is discarded.
2528
2529@cindex @code{umul@var{m}3_highpart} instruction pattern
2530@item @samp{umul@var{m}3_highpart}
2531Similar, but the multiplication is unsigned.
2532
2533@cindex @code{divmod@var{m}4} instruction pattern
2534@item @samp{divmod@var{m}4}
2535Signed division that produces both a quotient and a remainder.
2536Operand 1 is divided by operand 2 to produce a quotient stored
2537in operand 0 and a remainder stored in operand 3.
2538
2539For machines with an instruction that produces both a quotient and a
2540remainder, provide a pattern for @samp{divmod@var{m}4} but do not
2541provide patterns for @samp{div@var{m}3} and @samp{mod@var{m}3}. This
2542allows optimization in the relatively common case when both the quotient
2543and remainder are computed.
2544
2545If an instruction that just produces a quotient or just a remainder
2546exists and is more efficient than the instruction that produces both,
2547write the output routine of @samp{divmod@var{m}4} to call
2548@code{find_reg_note} and look for a @code{REG_UNUSED} note on the
2549quotient or remainder and generate the appropriate instruction.
2550
2551@cindex @code{udivmod@var{m}4} instruction pattern
2552@item @samp{udivmod@var{m}4}
2553Similar, but does unsigned division.
2554
2555@cindex @code{ashl@var{m}3} instruction pattern
2556@item @samp{ashl@var{m}3}
2557Arithmetic-shift operand 1 left by a number of bits specified by operand
25582, and store the result in operand 0. Here @var{m} is the mode of
2559operand 0 and operand 1; operand 2's mode is specified by the
2560instruction pattern, and the compiler will convert the operand to that
2561mode before generating the instruction.
2562
2563@cindex @code{ashr@var{m}3} instruction pattern
2564@cindex @code{lshr@var{m}3} instruction pattern
2565@cindex @code{rotl@var{m}3} instruction pattern
2566@cindex @code{rotr@var{m}3} instruction pattern
2567@item @samp{ashr@var{m}3}, @samp{lshr@var{m}3}, @samp{rotl@var{m}3}, @samp{rotr@var{m}3}
2568Other shift and rotate instructions, analogous to the
2569@code{ashl@var{m}3} instructions.
2570
2571@cindex @code{neg@var{m}2} instruction pattern
2572@item @samp{neg@var{m}2}
2573Negate operand 1 and store the result in operand 0.
2574
2575@cindex @code{abs@var{m}2} instruction pattern
2576@item @samp{abs@var{m}2}
2577Store the absolute value of operand 1 into operand 0.
2578
2579@cindex @code{sqrt@var{m}2} instruction pattern
2580@item @samp{sqrt@var{m}2}
2581Store the square root of operand 1 into operand 0.
2582
2583The @code{sqrt} built-in function of C always uses the mode which
e7b489c8
RS
2584corresponds to the C data type @code{double} and the @code{sqrtf}
2585built-in function uses the mode which corresponds to the C data
2586type @code{float}.
2587
2588@cindex @code{cos@var{m}2} instruction pattern
2589@item @samp{cos@var{m}2}
2590Store the cosine of operand 1 into operand 0.
2591
2592The @code{cos} built-in function of C always uses the mode which
2593corresponds to the C data type @code{double} and the @code{cosf}
2594built-in function uses the mode which corresponds to the C data
2595type @code{float}.
2596
2597@cindex @code{sin@var{m}2} instruction pattern
2598@item @samp{sin@var{m}2}
2599Store the sine of operand 1 into operand 0.
2600
2601The @code{sin} built-in function of C always uses the mode which
2602corresponds to the C data type @code{double} and the @code{sinf}
2603built-in function uses the mode which corresponds to the C data
2604type @code{float}.
2605
2606@cindex @code{exp@var{m}2} instruction pattern
2607@item @samp{exp@var{m}2}
2608Store the exponential of operand 1 into operand 0.
2609
2610The @code{exp} built-in function of C always uses the mode which
2611corresponds to the C data type @code{double} and the @code{expf}
2612built-in function uses the mode which corresponds to the C data
2613type @code{float}.
2614
2615@cindex @code{log@var{m}2} instruction pattern
2616@item @samp{log@var{m}2}
2617Store the natural logarithm of operand 1 into operand 0.
2618
2619The @code{log} built-in function of C always uses the mode which
2620corresponds to the C data type @code{double} and the @code{logf}
2621built-in function uses the mode which corresponds to the C data
2622type @code{float}.
03dda8e3 2623
b5e01d4b
RS
2624@cindex @code{pow@var{m}3} instruction pattern
2625@item @samp{pow@var{m}3}
2626Store the value of operand 1 raised to the exponent operand 2
2627into operand 0.
2628
2629The @code{pow} built-in function of C always uses the mode which
2630corresponds to the C data type @code{double} and the @code{powf}
2631built-in function uses the mode which corresponds to the C data
2632type @code{float}.
2633
2634@cindex @code{atan2@var{m}3} instruction pattern
2635@item @samp{atan2@var{m}3}
2636Store the arc tangent (inverse tangent) of operand 1 divided by
2637operand 2 into operand 0, using the signs of both arguments to
2638determine the quadrant of the result.
2639
2640The @code{atan2} built-in function of C always uses the mode which
2641corresponds to the C data type @code{double} and the @code{atan2f}
2642built-in function uses the mode which corresponds to the C data
2643type @code{float}.
2644
4977bab6
ZW
2645@cindex @code{floor@var{m}2} instruction pattern
2646@item @samp{floor@var{m}2}
2647Store the largest integral value not greater than argument.
2648
2649The @code{floor} built-in function of C always uses the mode which
2650corresponds to the C data type @code{double} and the @code{floorf}
2651built-in function uses the mode which corresponds to the C data
2652type @code{float}.
2653
2654@cindex @code{trunc@var{m}2} instruction pattern
2655@item @samp{trunc@var{m}2}
2656Store the argument rounded to integer towards zero.
2657
2658The @code{trunc} built-in function of C always uses the mode which
2659corresponds to the C data type @code{double} and the @code{truncf}
2660built-in function uses the mode which corresponds to the C data
2661type @code{float}.
2662
2663@cindex @code{round@var{m}2} instruction pattern
2664@item @samp{round@var{m}2}
2665Store the argument rounded to integer away from zero.
2666
2667The @code{round} built-in function of C always uses the mode which
2668corresponds to the C data type @code{double} and the @code{roundf}
2669built-in function uses the mode which corresponds to the C data
2670type @code{float}.
2671
2672@cindex @code{ceil@var{m}2} instruction pattern
2673@item @samp{ceil@var{m}2}
2674Store the argument rounded to integer away from zero.
2675
2676The @code{ceil} built-in function of C always uses the mode which
2677corresponds to the C data type @code{double} and the @code{ceilf}
2678built-in function uses the mode which corresponds to the C data
2679type @code{float}.
2680
2681@cindex @code{nearbyint@var{m}2} instruction pattern
2682@item @samp{nearbyint@var{m}2}
2683Store the argument rounded according to the default rounding mode
2684
2685The @code{nearbyint} built-in function of C always uses the mode which
2686corresponds to the C data type @code{double} and the @code{nearbyintf}
2687built-in function uses the mode which corresponds to the C data
2688type @code{float}.
2689
03dda8e3
RK
2690@cindex @code{ffs@var{m}2} instruction pattern
2691@item @samp{ffs@var{m}2}
2692Store into operand 0 one plus the index of the least significant 1-bit
2693of operand 1. If operand 1 is zero, store zero. @var{m} is the mode
2694of operand 0; operand 1's mode is specified by the instruction
2695pattern, and the compiler will convert the operand to that mode before
2696generating the instruction.
2697
2698The @code{ffs} built-in function of C always uses the mode which
2699corresponds to the C data type @code{int}.
2700
2928cd7a
RH
2701@cindex @code{clz@var{m}2} instruction pattern
2702@item @samp{clz@var{m}2}
2703Store into operand 0 the number of leading 0-bits in @var{x}, starting
2704at the most significant bit position. If @var{x} is 0, the result is
2705undefined. @var{m} is the mode of operand 0; operand 1's mode is
2706specified by the instruction pattern, and the compiler will convert the
2707operand to that mode before generating the instruction.
2708
2709@cindex @code{ctz@var{m}2} instruction pattern
2710@item @samp{ctz@var{m}2}
2711Store into operand 0 the number of trailing 0-bits in @var{x}, starting
2712at the least significant bit position. If @var{x} is 0, the result is
2713undefined. @var{m} is the mode of operand 0; operand 1's mode is
2714specified by the instruction pattern, and the compiler will convert the
2715operand to that mode before generating the instruction.
2716
2717@cindex @code{popcount@var{m}2} instruction pattern
2718@item @samp{popcount@var{m}2}
2719Store into operand 0 the number of 1-bits in @var{x}. @var{m} is the
2720mode of operand 0; operand 1's mode is specified by the instruction
2721pattern, and the compiler will convert the operand to that mode before
2722generating the instruction.
2723
2724@cindex @code{parity@var{m}2} instruction pattern
2725@item @samp{parity@var{m}2}
2726Store into operand 0 the parity of @var{x}, i.@:e. the number of 1-bits
2727in @var{x} modulo 2. @var{m} is the mode of operand 0; operand 1's mode
2728is specified by the instruction pattern, and the compiler will convert
2729the operand to that mode before generating the instruction.
2730
03dda8e3
RK
2731@cindex @code{one_cmpl@var{m}2} instruction pattern
2732@item @samp{one_cmpl@var{m}2}
2733Store the bitwise-complement of operand 1 into operand 0.
2734
2735@cindex @code{cmp@var{m}} instruction pattern
2736@item @samp{cmp@var{m}}
2737Compare operand 0 and operand 1, and set the condition codes.
2738The RTL pattern should look like this:
2739
2740@smallexample
2741(set (cc0) (compare (match_operand:@var{m} 0 @dots{})
2742 (match_operand:@var{m} 1 @dots{})))
2743@end smallexample
2744
2745@cindex @code{tst@var{m}} instruction pattern
2746@item @samp{tst@var{m}}
2747Compare operand 0 against zero, and set the condition codes.
2748The RTL pattern should look like this:
2749
2750@smallexample
2751(set (cc0) (match_operand:@var{m} 0 @dots{}))
2752@end smallexample
2753
2754@samp{tst@var{m}} patterns should not be defined for machines that do
2755not use @code{(cc0)}. Doing so would confuse the optimizer since it
2756would no longer be clear which @code{set} operations were comparisons.
2757The @samp{cmp@var{m}} patterns should be used instead.
2758
2759@cindex @code{movstr@var{m}} instruction pattern
2760@item @samp{movstr@var{m}}
2761Block move instruction. The addresses of the destination and source
2762strings are the first two operands, and both are in mode @code{Pmode}.
e5e809f4 2763
03dda8e3 2764The number of bytes to move is the third operand, in mode @var{m}.
e5e809f4
JL
2765Usually, you specify @code{word_mode} for @var{m}. However, if you can
2766generate better code knowing the range of valid lengths is smaller than
2767those representable in a full word, you should provide a pattern with a
2768mode corresponding to the range of values you can handle efficiently
2769(e.g., @code{QImode} for values in the range 0--127; note we avoid numbers
2770that appear negative) and also a pattern with @code{word_mode}.
03dda8e3
RK
2771
2772The fourth operand is the known shared alignment of the source and
2773destination, in the form of a @code{const_int} rtx. Thus, if the
2774compiler knows that both source and destination are word-aligned,
2775it may provide the value 4 for this operand.
2776
8c01d9b6 2777Descriptions of multiple @code{movstr@var{m}} patterns can only be
4693911f 2778beneficial if the patterns for smaller modes have fewer restrictions
8c01d9b6
JL
2779on their first, second and fourth operands. Note that the mode @var{m}
2780in @code{movstr@var{m}} does not impose any restriction on the mode of
2781individually moved data units in the block.
2782
03dda8e3
RK
2783These patterns need not give special consideration to the possibility
2784that the source and destination strings might overlap.
2785
2786@cindex @code{clrstr@var{m}} instruction pattern
2787@item @samp{clrstr@var{m}}
2788Block clear instruction. The addresses of the destination string is the
2789first operand, in mode @code{Pmode}. The number of bytes to clear is
e5e809f4
JL
2790the second operand, in mode @var{m}. See @samp{movstr@var{m}} for
2791a discussion of the choice of mode.
03dda8e3
RK
2792
2793The third operand is the known alignment of the destination, in the form
2794of a @code{const_int} rtx. Thus, if the compiler knows that the
2795destination is word-aligned, it may provide the value 4 for this
2796operand.
2797
8c01d9b6
JL
2798The use for multiple @code{clrstr@var{m}} is as for @code{movstr@var{m}}.
2799
03dda8e3
RK
2800@cindex @code{cmpstr@var{m}} instruction pattern
2801@item @samp{cmpstr@var{m}}
2802Block compare instruction, with five operands. Operand 0 is the output;
2803it has mode @var{m}. The remaining four operands are like the operands
2804of @samp{movstr@var{m}}. The two memory blocks specified are compared
5cc2f4f3
KG
2805byte by byte in lexicographic order starting at the beginning of each
2806string. The instruction is not allowed to prefetch more than one byte
2807at a time since either string may end in the first byte and reading past
2808that may access an invalid page or segment and cause a fault. The
2809effect of the instruction is to store a value in operand 0 whose sign
2810indicates the result of the comparison.
03dda8e3
RK
2811
2812@cindex @code{strlen@var{m}} instruction pattern
2813@item @samp{strlen@var{m}}
2814Compute the length of a string, with three operands.
2815Operand 0 is the result (of mode @var{m}), operand 1 is
2816a @code{mem} referring to the first character of the string,
2817operand 2 is the character to search for (normally zero),
2818and operand 3 is a constant describing the known alignment
2819of the beginning of the string.
2820
2821@cindex @code{float@var{mn}2} instruction pattern
2822@item @samp{float@var{m}@var{n}2}
2823Convert signed integer operand 1 (valid for fixed point mode @var{m}) to
2824floating point mode @var{n} and store in operand 0 (which has mode
2825@var{n}).
2826
2827@cindex @code{floatuns@var{mn}2} instruction pattern
2828@item @samp{floatuns@var{m}@var{n}2}
2829Convert unsigned integer operand 1 (valid for fixed point mode @var{m})
2830to floating point mode @var{n} and store in operand 0 (which has mode
2831@var{n}).
2832
2833@cindex @code{fix@var{mn}2} instruction pattern
2834@item @samp{fix@var{m}@var{n}2}
2835Convert operand 1 (valid for floating point mode @var{m}) to fixed
2836point mode @var{n} as a signed number and store in operand 0 (which
2837has mode @var{n}). This instruction's result is defined only when
2838the value of operand 1 is an integer.
2839
2840@cindex @code{fixuns@var{mn}2} instruction pattern
2841@item @samp{fixuns@var{m}@var{n}2}
2842Convert operand 1 (valid for floating point mode @var{m}) to fixed
2843point mode @var{n} as an unsigned number and store in operand 0 (which
2844has mode @var{n}). This instruction's result is defined only when the
2845value of operand 1 is an integer.
2846
2847@cindex @code{ftrunc@var{m}2} instruction pattern
2848@item @samp{ftrunc@var{m}2}
2849Convert operand 1 (valid for floating point mode @var{m}) to an
2850integer value, still represented in floating point mode @var{m}, and
2851store it in operand 0 (valid for floating point mode @var{m}).
2852
2853@cindex @code{fix_trunc@var{mn}2} instruction pattern
2854@item @samp{fix_trunc@var{m}@var{n}2}
2855Like @samp{fix@var{m}@var{n}2} but works for any floating point value
2856of mode @var{m} by converting the value to an integer.
2857
2858@cindex @code{fixuns_trunc@var{mn}2} instruction pattern
2859@item @samp{fixuns_trunc@var{m}@var{n}2}
2860Like @samp{fixuns@var{m}@var{n}2} but works for any floating point
2861value of mode @var{m} by converting the value to an integer.
2862
2863@cindex @code{trunc@var{mn}2} instruction pattern
2864@item @samp{trunc@var{m}@var{n}2}
2865Truncate operand 1 (valid for mode @var{m}) to mode @var{n} and
2866store in operand 0 (which has mode @var{n}). Both modes must be fixed
2867point or both floating point.
2868
2869@cindex @code{extend@var{mn}2} instruction pattern
2870@item @samp{extend@var{m}@var{n}2}
2871Sign-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
2872store in operand 0 (which has mode @var{n}). Both modes must be fixed
2873point or both floating point.
2874
2875@cindex @code{zero_extend@var{mn}2} instruction pattern
2876@item @samp{zero_extend@var{m}@var{n}2}
2877Zero-extend operand 1 (valid for mode @var{m}) to mode @var{n} and
2878store in operand 0 (which has mode @var{n}). Both modes must be fixed
2879point.
2880
2881@cindex @code{extv} instruction pattern
2882@item @samp{extv}
c771326b 2883Extract a bit-field from operand 1 (a register or memory operand), where
03dda8e3
RK
2884operand 2 specifies the width in bits and operand 3 the starting bit,
2885and store it in operand 0. Operand 0 must have mode @code{word_mode}.
2886Operand 1 may have mode @code{byte_mode} or @code{word_mode}; often
2887@code{word_mode} is allowed only for registers. Operands 2 and 3 must
2888be valid for @code{word_mode}.
2889
2890The RTL generation pass generates this instruction only with constants
2891for operands 2 and 3.
2892
2893The bit-field value is sign-extended to a full word integer
2894before it is stored in operand 0.
2895
2896@cindex @code{extzv} instruction pattern
2897@item @samp{extzv}
2898Like @samp{extv} except that the bit-field value is zero-extended.
2899
2900@cindex @code{insv} instruction pattern
2901@item @samp{insv}
c771326b
JM
2902Store operand 3 (which must be valid for @code{word_mode}) into a
2903bit-field in operand 0, where operand 1 specifies the width in bits and
03dda8e3
RK
2904operand 2 the starting bit. Operand 0 may have mode @code{byte_mode} or
2905@code{word_mode}; often @code{word_mode} is allowed only for registers.
2906Operands 1 and 2 must be valid for @code{word_mode}.
2907
2908The RTL generation pass generates this instruction only with constants
2909for operands 1 and 2.
2910
2911@cindex @code{mov@var{mode}cc} instruction pattern
2912@item @samp{mov@var{mode}cc}
2913Conditionally move operand 2 or operand 3 into operand 0 according to the
2914comparison in operand 1. If the comparison is true, operand 2 is moved
2915into operand 0, otherwise operand 3 is moved.
2916
2917The mode of the operands being compared need not be the same as the operands
2918being moved. Some machines, sparc64 for example, have instructions that
2919conditionally move an integer value based on the floating point condition
2920codes and vice versa.
2921
2922If the machine does not have conditional move instructions, do not
2923define these patterns.
2924
068f5dea
JH
2925@cindex @code{add@var{mode}cc} instruction pattern
2926@item @samp{mov@var{mode}cc}
2927Similar to @samp{mov@var{mode}cc} but for conditional addition. Conditionally
2928move operand 2 or (operands 2 + operand 3) into operand 0 according to the
2929comparison in operand 1. If the comparison is true, operand 2 is moved into
2930operand 0, otherwise operand 3 is moved.
2931
03dda8e3
RK
2932@cindex @code{s@var{cond}} instruction pattern
2933@item @samp{s@var{cond}}
2934Store zero or nonzero in the operand according to the condition codes.
2935Value stored is nonzero iff the condition @var{cond} is true.
2936@var{cond} is the name of a comparison operation expression code, such
2937as @code{eq}, @code{lt} or @code{leu}.
2938
2939You specify the mode that the operand must have when you write the
2940@code{match_operand} expression. The compiler automatically sees
2941which mode you have used and supplies an operand of that mode.
2942
2943The value stored for a true condition must have 1 as its low bit, or
2944else must be negative. Otherwise the instruction is not suitable and
2945you should omit it from the machine description. You describe to the
2946compiler exactly which value is stored by defining the macro
2947@code{STORE_FLAG_VALUE} (@pxref{Misc}). If a description cannot be
2948found that can be used for all the @samp{s@var{cond}} patterns, you
2949should omit those operations from the machine description.
2950
2951These operations may fail, but should do so only in relatively
2952uncommon cases; if they would fail for common cases involving
2953integer comparisons, it is best to omit these patterns.
2954
2955If these operations are omitted, the compiler will usually generate code
2956that copies the constant one to the target and branches around an
2957assignment of zero to the target. If this code is more efficient than
2958the potential instructions used for the @samp{s@var{cond}} pattern
2959followed by those required to convert the result into a 1 or a zero in
2960@code{SImode}, you should omit the @samp{s@var{cond}} operations from
2961the machine description.
2962
2963@cindex @code{b@var{cond}} instruction pattern
2964@item @samp{b@var{cond}}
2965Conditional branch instruction. Operand 0 is a @code{label_ref} that
2966refers to the label to jump to. Jump if the condition codes meet
2967condition @var{cond}.
2968
2969Some machines do not follow the model assumed here where a comparison
2970instruction is followed by a conditional branch instruction. In that
2971case, the @samp{cmp@var{m}} (and @samp{tst@var{m}}) patterns should
2972simply store the operands away and generate all the required insns in a
2973@code{define_expand} (@pxref{Expander Definitions}) for the conditional
2974branch operations. All calls to expand @samp{b@var{cond}} patterns are
2975immediately preceded by calls to expand either a @samp{cmp@var{m}}
2976pattern or a @samp{tst@var{m}} pattern.
2977
2978Machines that use a pseudo register for the condition code value, or
2979where the mode used for the comparison depends on the condition being
0b433de6 2980tested, should also use the above mechanism. @xref{Jump Patterns}.
03dda8e3
RK
2981
2982The above discussion also applies to the @samp{mov@var{mode}cc} and
2983@samp{s@var{cond}} patterns.
2984
d26eedb6
HPN
2985@cindex @code{jump} instruction pattern
2986@item @samp{jump}
2987A jump inside a function; an unconditional branch. Operand 0 is the
2988@code{label_ref} of the label to jump to. This pattern name is mandatory
2989on all machines.
2990
03dda8e3
RK
2991@cindex @code{call} instruction pattern
2992@item @samp{call}
2993Subroutine call instruction returning no value. Operand 0 is the
2994function to call; operand 1 is the number of bytes of arguments pushed
f5963e61
JL
2995as a @code{const_int}; operand 2 is the number of registers used as
2996operands.
03dda8e3
RK
2997
2998On most machines, operand 2 is not actually stored into the RTL
2999pattern. It is supplied for the sake of some RISC machines which need
3000to put this information into the assembler code; they can put it in
3001the RTL instead of operand 1.
3002
3003Operand 0 should be a @code{mem} RTX whose address is the address of the
3004function. Note, however, that this address can be a @code{symbol_ref}
3005expression even if it would not be a legitimate memory address on the
3006target machine. If it is also not a valid argument for a call
3007instruction, the pattern for this operation should be a
3008@code{define_expand} (@pxref{Expander Definitions}) that places the
3009address into a register and uses that register in the call instruction.
3010
3011@cindex @code{call_value} instruction pattern
3012@item @samp{call_value}
3013Subroutine call instruction returning a value. Operand 0 is the hard
3014register in which the value is returned. There are three more
3015operands, the same as the three operands of the @samp{call}
3016instruction (but with numbers increased by one).
3017
3018Subroutines that return @code{BLKmode} objects use the @samp{call}
3019insn.
3020
3021@cindex @code{call_pop} instruction pattern
3022@cindex @code{call_value_pop} instruction pattern
3023@item @samp{call_pop}, @samp{call_value_pop}
3024Similar to @samp{call} and @samp{call_value}, except used if defined and
df2a54e9 3025if @code{RETURN_POPS_ARGS} is nonzero. They should emit a @code{parallel}
03dda8e3
RK
3026that contains both the function call and a @code{set} to indicate the
3027adjustment made to the frame pointer.
3028
df2a54e9 3029For machines where @code{RETURN_POPS_ARGS} can be nonzero, the use of these
03dda8e3
RK
3030patterns increases the number of functions for which the frame pointer
3031can be eliminated, if desired.
3032
3033@cindex @code{untyped_call} instruction pattern
3034@item @samp{untyped_call}
3035Subroutine call instruction returning a value of any type. Operand 0 is
3036the function to call; operand 1 is a memory location where the result of
3037calling the function is to be stored; operand 2 is a @code{parallel}
3038expression where each element is a @code{set} expression that indicates
3039the saving of a function return value into the result block.
3040
3041This instruction pattern should be defined to support
3042@code{__builtin_apply} on machines where special instructions are needed
3043to call a subroutine with arbitrary arguments or to save the value
3044returned. This instruction pattern is required on machines that have
e979f9e8
JM
3045multiple registers that can hold a return value
3046(i.e.@: @code{FUNCTION_VALUE_REGNO_P} is true for more than one register).
03dda8e3
RK
3047
3048@cindex @code{return} instruction pattern
3049@item @samp{return}
3050Subroutine return instruction. This instruction pattern name should be
3051defined only if a single instruction can do all the work of returning
3052from a function.
3053
3054Like the @samp{mov@var{m}} patterns, this pattern is also used after the
3055RTL generation phase. In this case it is to support machines where
3056multiple instructions are usually needed to return from a function, but
3057some class of functions only requires one instruction to implement a
3058return. Normally, the applicable functions are those which do not need
3059to save any registers or allocate stack space.
3060
3061@findex reload_completed
3062@findex leaf_function_p
3063For such machines, the condition specified in this pattern should only
df2a54e9 3064be true when @code{reload_completed} is nonzero and the function's
03dda8e3
RK
3065epilogue would only be a single instruction. For machines with register
3066windows, the routine @code{leaf_function_p} may be used to determine if
3067a register window push is required.
3068
3069Machines that have conditional return instructions should define patterns
3070such as
3071
3072@smallexample
3073(define_insn ""
3074 [(set (pc)
3075 (if_then_else (match_operator
3076 0 "comparison_operator"
3077 [(cc0) (const_int 0)])
3078 (return)
3079 (pc)))]
3080 "@var{condition}"
3081 "@dots{}")
3082@end smallexample
3083
3084where @var{condition} would normally be the same condition specified on the
3085named @samp{return} pattern.
3086
3087@cindex @code{untyped_return} instruction pattern
3088@item @samp{untyped_return}
3089Untyped subroutine return instruction. This instruction pattern should
3090be defined to support @code{__builtin_return} on machines where special
3091instructions are needed to return a value of any type.
3092
3093Operand 0 is a memory location where the result of calling a function
3094with @code{__builtin_apply} is stored; operand 1 is a @code{parallel}
3095expression where each element is a @code{set} expression that indicates
3096the restoring of a function return value from the result block.
3097
3098@cindex @code{nop} instruction pattern
3099@item @samp{nop}
3100No-op instruction. This instruction pattern name should always be defined
3101to output a no-op in assembler code. @code{(const_int 0)} will do as an
3102RTL pattern.
3103
3104@cindex @code{indirect_jump} instruction pattern
3105@item @samp{indirect_jump}
3106An instruction to jump to an address which is operand zero.
3107This pattern name is mandatory on all machines.
3108
3109@cindex @code{casesi} instruction pattern
3110@item @samp{casesi}
3111Instruction to jump through a dispatch table, including bounds checking.
3112This instruction takes five operands:
3113
3114@enumerate
3115@item
3116The index to dispatch on, which has mode @code{SImode}.
3117
3118@item
3119The lower bound for indices in the table, an integer constant.
3120
3121@item
3122The total range of indices in the table---the largest index
3123minus the smallest one (both inclusive).
3124
3125@item
3126A label that precedes the table itself.
3127
3128@item
3129A label to jump to if the index has a value outside the bounds.
3130(If the machine-description macro @code{CASE_DROPS_THROUGH} is defined,
3131then an out-of-bounds index drops through to the code following
3132the jump table instead of jumping to this label. In that case,
3133this label is not actually used by the @samp{casesi} instruction,
3134but it is always provided as an operand.)
3135@end enumerate
3136
3137The table is a @code{addr_vec} or @code{addr_diff_vec} inside of a
3138@code{jump_insn}. The number of elements in the table is one plus the
3139difference between the upper bound and the lower bound.
3140
3141@cindex @code{tablejump} instruction pattern
3142@item @samp{tablejump}
3143Instruction to jump to a variable address. This is a low-level
3144capability which can be used to implement a dispatch table when there
3145is no @samp{casesi} pattern.
3146
3147This pattern requires two operands: the address or offset, and a label
3148which should immediately precede the jump table. If the macro
f1f5f142
JL
3149@code{CASE_VECTOR_PC_RELATIVE} evaluates to a nonzero value then the first
3150operand is an offset which counts from the address of the table; otherwise,
3151it is an absolute address to jump to. In either case, the first operand has
03dda8e3
RK
3152mode @code{Pmode}.
3153
3154The @samp{tablejump} insn is always the last insn before the jump
3155table it uses. Its assembler code normally has no need to use the
3156second operand, but you should incorporate it in the RTL pattern so
3157that the jump optimizer will not delete the table as unreachable code.
3158
6e4fcc95
MH
3159
3160@cindex @code{decrement_and_branch_until_zero} instruction pattern
3161@item @samp{decrement_and_branch_until_zero}
3162Conditional branch instruction that decrements a register and
df2a54e9 3163jumps if the register is nonzero. Operand 0 is the register to
6e4fcc95 3164decrement and test; operand 1 is the label to jump to if the
df2a54e9 3165register is nonzero. @xref{Looping Patterns}.
6e4fcc95
MH
3166
3167This optional instruction pattern is only used by the combiner,
3168typically for loops reversed by the loop optimizer when strength
3169reduction is enabled.
3170
3171@cindex @code{doloop_end} instruction pattern
3172@item @samp{doloop_end}
3173Conditional branch instruction that decrements a register and jumps if
df2a54e9 3174the register is nonzero. This instruction takes five operands: Operand
6e4fcc95
MH
31750 is the register to decrement and test; operand 1 is the number of loop
3176iterations as a @code{const_int} or @code{const0_rtx} if this cannot be
3177determined until run-time; operand 2 is the actual or estimated maximum
3178number of iterations as a @code{const_int}; operand 3 is the number of
3179enclosed loops as a @code{const_int} (an innermost loop has a value of
df2a54e9 31801); operand 4 is the label to jump to if the register is nonzero.
5c25e11d 3181@xref{Looping Patterns}.
6e4fcc95
MH
3182
3183This optional instruction pattern should be defined for machines with
3184low-overhead looping instructions as the loop optimizer will try to
3185modify suitable loops to utilize it. If nested low-overhead looping is
3186not supported, use a @code{define_expand} (@pxref{Expander Definitions})
3187and make the pattern fail if operand 3 is not @code{const1_rtx}.
3188Similarly, if the actual or estimated maximum number of iterations is
3189too large for this instruction, make it fail.
3190
3191@cindex @code{doloop_begin} instruction pattern
3192@item @samp{doloop_begin}
3193Companion instruction to @code{doloop_end} required for machines that
c21cd8b1
JM
3194need to perform some initialization, such as loading special registers
3195used by a low-overhead looping instruction. If initialization insns do
6e4fcc95
MH
3196not always need to be emitted, use a @code{define_expand}
3197(@pxref{Expander Definitions}) and make it fail.
3198
3199
03dda8e3
RK
3200@cindex @code{canonicalize_funcptr_for_compare} instruction pattern
3201@item @samp{canonicalize_funcptr_for_compare}
3202Canonicalize the function pointer in operand 1 and store the result
3203into operand 0.
3204
3205Operand 0 is always a @code{reg} and has mode @code{Pmode}; operand 1
3206may be a @code{reg}, @code{mem}, @code{symbol_ref}, @code{const_int}, etc
3207and also has mode @code{Pmode}.
3208
3209Canonicalization of a function pointer usually involves computing
3210the address of the function which would be called if the function
3211pointer were used in an indirect call.
3212
3213Only define this pattern if function pointers on the target machine
3214can have different values but still call the same function when
3215used in an indirect call.
3216
3217@cindex @code{save_stack_block} instruction pattern
3218@cindex @code{save_stack_function} instruction pattern
3219@cindex @code{save_stack_nonlocal} instruction pattern
3220@cindex @code{restore_stack_block} instruction pattern
3221@cindex @code{restore_stack_function} instruction pattern
3222@cindex @code{restore_stack_nonlocal} instruction pattern
3223@item @samp{save_stack_block}
3224@itemx @samp{save_stack_function}
3225@itemx @samp{save_stack_nonlocal}
3226@itemx @samp{restore_stack_block}
3227@itemx @samp{restore_stack_function}
3228@itemx @samp{restore_stack_nonlocal}
3229Most machines save and restore the stack pointer by copying it to or
3230from an object of mode @code{Pmode}. Do not define these patterns on
3231such machines.
3232
3233Some machines require special handling for stack pointer saves and
3234restores. On those machines, define the patterns corresponding to the
3235non-standard cases by using a @code{define_expand} (@pxref{Expander
3236Definitions}) that produces the required insns. The three types of
3237saves and restores are:
3238
3239@enumerate
3240@item
3241@samp{save_stack_block} saves the stack pointer at the start of a block
3242that allocates a variable-sized object, and @samp{restore_stack_block}
3243restores the stack pointer when the block is exited.
3244
3245@item
3246@samp{save_stack_function} and @samp{restore_stack_function} do a
3247similar job for the outermost block of a function and are used when the
3248function allocates variable-sized objects or calls @code{alloca}. Only
3249the epilogue uses the restored stack pointer, allowing a simpler save or
3250restore sequence on some machines.
3251
3252@item
3253@samp{save_stack_nonlocal} is used in functions that contain labels
3254branched to by nested functions. It saves the stack pointer in such a
3255way that the inner function can use @samp{restore_stack_nonlocal} to
3256restore the stack pointer. The compiler generates code to restore the
3257frame and argument pointer registers, but some machines require saving
3258and restoring additional data such as register window information or
3259stack backchains. Place insns in these patterns to save and restore any
3260such required data.
3261@end enumerate
3262
3263When saving the stack pointer, operand 0 is the save area and operand 1
73c8090f
DE
3264is the stack pointer. The mode used to allocate the save area defaults
3265to @code{Pmode} but you can override that choice by defining the
7e390c9d 3266@code{STACK_SAVEAREA_MODE} macro (@pxref{Storage Layout}). You must
73c8090f
DE
3267specify an integral mode, or @code{VOIDmode} if no save area is needed
3268for a particular type of save (either because no save is needed or
3269because a machine-specific save area can be used). Operand 0 is the
3270stack pointer and operand 1 is the save area for restore operations. If
3271@samp{save_stack_block} is defined, operand 0 must not be
3272@code{VOIDmode} since these saves can be arbitrarily nested.
03dda8e3
RK
3273
3274A save area is a @code{mem} that is at a constant offset from
3275@code{virtual_stack_vars_rtx} when the stack pointer is saved for use by
3276nonlocal gotos and a @code{reg} in the other two cases.
3277
3278@cindex @code{allocate_stack} instruction pattern
3279@item @samp{allocate_stack}
72938a4c 3280Subtract (or add if @code{STACK_GROWS_DOWNWARD} is undefined) operand 1 from
03dda8e3
RK
3281the stack pointer to create space for dynamically allocated data.
3282
72938a4c
MM
3283Store the resultant pointer to this space into operand 0. If you
3284are allocating space from the main stack, do this by emitting a
3285move insn to copy @code{virtual_stack_dynamic_rtx} to operand 0.
3286If you are allocating the space elsewhere, generate code to copy the
3287location of the space to operand 0. In the latter case, you must
956d6950 3288ensure this space gets freed when the corresponding space on the main
72938a4c
MM
3289stack is free.
3290
03dda8e3
RK
3291Do not define this pattern if all that must be done is the subtraction.
3292Some machines require other operations such as stack probes or
3293maintaining the back chain. Define this pattern to emit those
3294operations in addition to updating the stack pointer.
3295
861bb6c1
JL
3296@cindex @code{check_stack} instruction pattern
3297@item @samp{check_stack}
3298If stack checking cannot be done on your system by probing the stack with
3299a load or store instruction (@pxref{Stack Checking}), define this pattern
3300to perform the needed check and signaling an error if the stack
3301has overflowed. The single operand is the location in the stack furthest
3302from the current stack pointer that you need to validate. Normally,
3303on machines where this pattern is needed, you would obtain the stack
3304limit from a global or thread-specific variable or register.
3305
03dda8e3
RK
3306@cindex @code{nonlocal_goto} instruction pattern
3307@item @samp{nonlocal_goto}
3308Emit code to generate a non-local goto, e.g., a jump from one function
3309to a label in an outer function. This pattern has four arguments,
3310each representing a value to be used in the jump. The first
45bb86fd 3311argument is to be loaded into the frame pointer, the second is
03dda8e3
RK
3312the address to branch to (code to dispatch to the actual label),
3313the third is the address of a location where the stack is saved,
3314and the last is the address of the label, to be placed in the
3315location for the incoming static chain.
3316
f0523f02 3317On most machines you need not define this pattern, since GCC will
03dda8e3
RK
3318already generate the correct code, which is to load the frame pointer
3319and static chain, restore the stack (using the
3320@samp{restore_stack_nonlocal} pattern, if defined), and jump indirectly
3321to the dispatcher. You need only define this pattern if this code will
3322not work on your machine.
3323
3324@cindex @code{nonlocal_goto_receiver} instruction pattern
3325@item @samp{nonlocal_goto_receiver}
3326This pattern, if defined, contains code needed at the target of a
161d7b59 3327nonlocal goto after the code already generated by GCC@. You will not
03dda8e3
RK
3328normally need to define this pattern. A typical reason why you might
3329need this pattern is if some value, such as a pointer to a global table,
c30ddbc9 3330must be restored when the frame pointer is restored. Note that a nonlocal
89bcce1b 3331goto only occurs within a unit-of-translation, so a global table pointer
c30ddbc9
RH
3332that is shared by all functions of a given module need not be restored.
3333There are no arguments.
861bb6c1
JL
3334
3335@cindex @code{exception_receiver} instruction pattern
3336@item @samp{exception_receiver}
3337This pattern, if defined, contains code needed at the site of an
3338exception handler that isn't needed at the site of a nonlocal goto. You
3339will not normally need to define this pattern. A typical reason why you
3340might need this pattern is if some value, such as a pointer to a global
3341table, must be restored after control flow is branched to the handler of
3342an exception. There are no arguments.
c85f7c16 3343
c30ddbc9
RH
3344@cindex @code{builtin_setjmp_setup} instruction pattern
3345@item @samp{builtin_setjmp_setup}
3346This pattern, if defined, contains additional code needed to initialize
3347the @code{jmp_buf}. You will not normally need to define this pattern.
3348A typical reason why you might need this pattern is if some value, such
3349as a pointer to a global table, must be restored. Though it is
3350preferred that the pointer value be recalculated if possible (given the
3351address of a label for instance). The single argument is a pointer to
3352the @code{jmp_buf}. Note that the buffer is five words long and that
3353the first three are normally used by the generic mechanism.
3354
c85f7c16
JL
3355@cindex @code{builtin_setjmp_receiver} instruction pattern
3356@item @samp{builtin_setjmp_receiver}
3357This pattern, if defined, contains code needed at the site of an
c771326b 3358built-in setjmp that isn't needed at the site of a nonlocal goto. You
c85f7c16
JL
3359will not normally need to define this pattern. A typical reason why you
3360might need this pattern is if some value, such as a pointer to a global
c30ddbc9
RH
3361table, must be restored. It takes one argument, which is the label
3362to which builtin_longjmp transfered control; this pattern may be emitted
3363at a small offset from that label.
3364
3365@cindex @code{builtin_longjmp} instruction pattern
3366@item @samp{builtin_longjmp}
3367This pattern, if defined, performs the entire action of the longjmp.
3368You will not normally need to define this pattern unless you also define
3369@code{builtin_setjmp_setup}. The single argument is a pointer to the
3370@code{jmp_buf}.
f69864aa 3371
52a11cbf
RH
3372@cindex @code{eh_return} instruction pattern
3373@item @samp{eh_return}
f69864aa 3374This pattern, if defined, affects the way @code{__builtin_eh_return},
52a11cbf
RH
3375and thence the call frame exception handling library routines, are
3376built. It is intended to handle non-trivial actions needed along
3377the abnormal return path.
3378
34dc173c
UW
3379The address of the exception handler to which the function should return
3380is passed as operand to this pattern. It will normally need to copied by
3381the pattern to some special register or memory location.
3382If the pattern needs to determine the location of the target call
3383frame in order to do so, it may use @code{EH_RETURN_STACKADJ_RTX},
3384if defined; it will have already been assigned.
3385
3386If this pattern is not defined, the default action will be to simply
3387copy the return address to @code{EH_RETURN_HANDLER_RTX}. Either
3388that macro or this pattern needs to be defined if call frame exception
3389handling is to be used.
0b433de6
JL
3390
3391@cindex @code{prologue} instruction pattern
17b53c33 3392@anchor{prologue instruction pattern}
0b433de6
JL
3393@item @samp{prologue}
3394This pattern, if defined, emits RTL for entry to a function. The function
b192711e 3395entry is responsible for setting up the stack frame, initializing the frame
0b433de6
JL
3396pointer register, saving callee saved registers, etc.
3397
3398Using a prologue pattern is generally preferred over defining
17b53c33 3399@code{TARGET_ASM_FUNCTION_PROLOGUE} to emit assembly code for the prologue.
0b433de6
JL
3400
3401The @code{prologue} pattern is particularly useful for targets which perform
3402instruction scheduling.
3403
3404@cindex @code{epilogue} instruction pattern
17b53c33 3405@anchor{epilogue instruction pattern}
0b433de6 3406@item @samp{epilogue}
396ad517 3407This pattern emits RTL for exit from a function. The function
b192711e 3408exit is responsible for deallocating the stack frame, restoring callee saved
0b433de6
JL
3409registers and emitting the return instruction.
3410
3411Using an epilogue pattern is generally preferred over defining
17b53c33 3412@code{TARGET_ASM_FUNCTION_EPILOGUE} to emit assembly code for the epilogue.
0b433de6
JL
3413
3414The @code{epilogue} pattern is particularly useful for targets which perform
3415instruction scheduling or which have delay slots for their return instruction.
3416
3417@cindex @code{sibcall_epilogue} instruction pattern
3418@item @samp{sibcall_epilogue}
3419This pattern, if defined, emits RTL for exit from a function without the final
3420branch back to the calling function. This pattern will be emitted before any
3421sibling call (aka tail call) sites.
3422
3423The @code{sibcall_epilogue} pattern must not clobber any arguments used for
3424parameter passing or any stack slots for arguments passed to the current
ebb48a4d 3425function.
a157febd
GK
3426
3427@cindex @code{trap} instruction pattern
3428@item @samp{trap}
3429This pattern, if defined, signals an error, typically by causing some
3430kind of signal to be raised. Among other places, it is used by the Java
c771326b 3431front end to signal `invalid array index' exceptions.
a157febd
GK
3432
3433@cindex @code{conditional_trap} instruction pattern
3434@item @samp{conditional_trap}
3435Conditional trap instruction. Operand 0 is a piece of RTL which
3436performs a comparison. Operand 1 is the trap code, an integer.
3437
3438A typical @code{conditional_trap} pattern looks like
3439
3440@smallexample
3441(define_insn "conditional_trap"
ebb48a4d 3442 [(trap_if (match_operator 0 "trap_operator"
a157febd
GK
3443 [(cc0) (const_int 0)])
3444 (match_operand 1 "const_int_operand" "i"))]
3445 ""
3446 "@dots{}")
3447@end smallexample
3448
e83d297b
JJ
3449@cindex @code{prefetch} instruction pattern
3450@item @samp{prefetch}
3451
3452This pattern, if defined, emits code for a non-faulting data prefetch
3453instruction. Operand 0 is the address of the memory to prefetch. Operand 1
3454is a constant 1 if the prefetch is preparing for a write to the memory
3455address, or a constant 0 otherwise. Operand 2 is the expected degree of
3456temporal locality of the data and is a value between 0 and 3, inclusive; 0
3457means that the data has no temporal locality, so it need not be left in the
3458cache after the access; 3 means that the data has a high degree of temporal
3459locality and should be left in all levels of cache possible; 1 and 2 mean,
3460respectively, a low or moderate degree of temporal locality.
3461
3462Targets that do not support write prefetches or locality hints can ignore
3463the values of operands 1 and 2.
3464
03dda8e3
RK
3465@end table
3466
3467@node Pattern Ordering
3468@section When the Order of Patterns Matters
3469@cindex Pattern Ordering
3470@cindex Ordering of Patterns
3471
3472Sometimes an insn can match more than one instruction pattern. Then the
3473pattern that appears first in the machine description is the one used.
3474Therefore, more specific patterns (patterns that will match fewer things)
3475and faster instructions (those that will produce better code when they
3476do match) should usually go first in the description.
3477
3478In some cases the effect of ordering the patterns can be used to hide
3479a pattern when it is not valid. For example, the 68000 has an
3480instruction for converting a fullword to floating point and another
3481for converting a byte to floating point. An instruction converting
3482an integer to floating point could match either one. We put the
3483pattern to convert the fullword first to make sure that one will
3484be used rather than the other. (Otherwise a large integer might
3485be generated as a single-byte immediate quantity, which would not work.)
3486Instead of using this pattern ordering it would be possible to make the
3487pattern for convert-a-byte smart enough to deal properly with any
3488constant value.
3489
3490@node Dependent Patterns
3491@section Interdependence of Patterns
3492@cindex Dependent Patterns
3493@cindex Interdependence of Patterns
3494
3495Every machine description must have a named pattern for each of the
3496conditional branch names @samp{b@var{cond}}. The recognition template
3497must always have the form
3498
3499@example
3500(set (pc)
3501 (if_then_else (@var{cond} (cc0) (const_int 0))
3502 (label_ref (match_operand 0 "" ""))
3503 (pc)))
3504@end example
3505
3506@noindent
3507In addition, every machine description must have an anonymous pattern
3508for each of the possible reverse-conditional branches. Their templates
3509look like
3510
3511@example
3512(set (pc)
3513 (if_then_else (@var{cond} (cc0) (const_int 0))
3514 (pc)
3515 (label_ref (match_operand 0 "" ""))))
3516@end example
3517
3518@noindent
3519They are necessary because jump optimization can turn direct-conditional
3520branches into reverse-conditional branches.
3521
3522It is often convenient to use the @code{match_operator} construct to
3523reduce the number of patterns that must be specified for branches. For
3524example,
3525
3526@example
3527(define_insn ""
3528 [(set (pc)
3529 (if_then_else (match_operator 0 "comparison_operator"
3530 [(cc0) (const_int 0)])
3531 (pc)
3532 (label_ref (match_operand 1 "" ""))))]
3533 "@var{condition}"
3534 "@dots{}")
3535@end example
3536
3537In some cases machines support instructions identical except for the
3538machine mode of one or more operands. For example, there may be
3539``sign-extend halfword'' and ``sign-extend byte'' instructions whose
3540patterns are
3541
3542@example
3543(set (match_operand:SI 0 @dots{})
3544 (extend:SI (match_operand:HI 1 @dots{})))
3545
3546(set (match_operand:SI 0 @dots{})
3547 (extend:SI (match_operand:QI 1 @dots{})))
3548@end example
3549
3550@noindent
3551Constant integers do not specify a machine mode, so an instruction to
3552extend a constant value could match either pattern. The pattern it
3553actually will match is the one that appears first in the file. For correct
3554results, this must be the one for the widest possible mode (@code{HImode},
3555here). If the pattern matches the @code{QImode} instruction, the results
3556will be incorrect if the constant value does not actually fit that mode.
3557
3558Such instructions to extend constants are rarely generated because they are
3559optimized away, but they do occasionally happen in nonoptimized
3560compilations.
3561
3562If a constraint in a pattern allows a constant, the reload pass may
3563replace a register with a constant permitted by the constraint in some
3564cases. Similarly for memory references. Because of this substitution,
3565you should not provide separate patterns for increment and decrement
3566instructions. Instead, they should be generated from the same pattern
3567that supports register-register add insns by examining the operands and
3568generating the appropriate machine instruction.
3569
3570@node Jump Patterns
3571@section Defining Jump Instruction Patterns
3572@cindex jump instruction patterns
3573@cindex defining jump instruction patterns
3574
f0523f02 3575For most machines, GCC assumes that the machine has a condition code.
03dda8e3
RK
3576A comparison insn sets the condition code, recording the results of both
3577signed and unsigned comparison of the given operands. A separate branch
3578insn tests the condition code and branches or not according its value.
3579The branch insns come in distinct signed and unsigned flavors. Many
8aeea6e6 3580common machines, such as the VAX, the 68000 and the 32000, work this
03dda8e3
RK
3581way.
3582
3583Some machines have distinct signed and unsigned compare instructions, and
3584only one set of conditional branch instructions. The easiest way to handle
3585these machines is to treat them just like the others until the final stage
3586where assembly code is written. At this time, when outputting code for the
3587compare instruction, peek ahead at the following branch using
3588@code{next_cc0_user (insn)}. (The variable @code{insn} refers to the insn
3589being output, in the output-writing code in an instruction pattern.) If
3590the RTL says that is an unsigned branch, output an unsigned compare;
3591otherwise output a signed compare. When the branch itself is output, you
3592can treat signed and unsigned branches identically.
3593
f0523f02 3594The reason you can do this is that GCC always generates a pair of
03dda8e3
RK
3595consecutive RTL insns, possibly separated by @code{note} insns, one to
3596set the condition code and one to test it, and keeps the pair inviolate
3597until the end.
3598
3599To go with this technique, you must define the machine-description macro
3600@code{NOTICE_UPDATE_CC} to do @code{CC_STATUS_INIT}; in other words, no
3601compare instruction is superfluous.
3602
3603Some machines have compare-and-branch instructions and no condition code.
3604A similar technique works for them. When it is time to ``output'' a
3605compare instruction, record its operands in two static variables. When
3606outputting the branch-on-condition-code instruction that follows, actually
3607output a compare-and-branch instruction that uses the remembered operands.
3608
3609It also works to define patterns for compare-and-branch instructions.
3610In optimizing compilation, the pair of compare and branch instructions
3611will be combined according to these patterns. But this does not happen
3612if optimization is not requested. So you must use one of the solutions
3613above in addition to any special patterns you define.
3614
3615In many RISC machines, most instructions do not affect the condition
3616code and there may not even be a separate condition code register. On
3617these machines, the restriction that the definition and use of the
3618condition code be adjacent insns is not necessary and can prevent
3619important optimizations. For example, on the IBM RS/6000, there is a
3620delay for taken branches unless the condition code register is set three
3621instructions earlier than the conditional branch. The instruction
3622scheduler cannot perform this optimization if it is not permitted to
3623separate the definition and use of the condition code register.
3624
3625On these machines, do not use @code{(cc0)}, but instead use a register
3626to represent the condition code. If there is a specific condition code
3627register in the machine, use a hard register. If the condition code or
3628comparison result can be placed in any general register, or if there are
3629multiple condition registers, use a pseudo register.
3630
3631@findex prev_cc0_setter
3632@findex next_cc0_user
3633On some machines, the type of branch instruction generated may depend on
3634the way the condition code was produced; for example, on the 68k and
981f6289 3635SPARC, setting the condition code directly from an add or subtract
03dda8e3
RK
3636instruction does not clear the overflow bit the way that a test
3637instruction does, so a different branch instruction must be used for
3638some conditional branches. For machines that use @code{(cc0)}, the set
3639and use of the condition code must be adjacent (separated only by
3640@code{note} insns) allowing flags in @code{cc_status} to be used.
3641(@xref{Condition Code}.) Also, the comparison and branch insns can be
3642located from each other by using the functions @code{prev_cc0_setter}
3643and @code{next_cc0_user}.
3644
3645However, this is not true on machines that do not use @code{(cc0)}. On
3646those machines, no assumptions can be made about the adjacency of the
3647compare and branch insns and the above methods cannot be used. Instead,
3648we use the machine mode of the condition code register to record
3649different formats of the condition code register.
3650
3651Registers used to store the condition code value should have a mode that
3652is in class @code{MODE_CC}. Normally, it will be @code{CCmode}. If
3653additional modes are required (as for the add example mentioned above in
981f6289 3654the SPARC), define the macro @code{EXTRA_CC_MODES} to list the
03dda8e3 3655additional modes required (@pxref{Condition Code}). Also define
03dda8e3
RK
3656@code{SELECT_CC_MODE} to choose a mode given an operand of a compare.
3657
3658If it is known during RTL generation that a different mode will be
3659required (for example, if the machine has separate compare instructions
3660for signed and unsigned quantities, like most IBM processors), they can
3661be specified at that time.
3662
3663If the cases that require different modes would be made by instruction
3664combination, the macro @code{SELECT_CC_MODE} determines which machine
3665mode should be used for the comparison result. The patterns should be
981f6289 3666written using that mode. To support the case of the add on the SPARC
03dda8e3
RK
3667discussed above, we have the pattern
3668
3669@smallexample
3670(define_insn ""
3671 [(set (reg:CC_NOOV 0)
3672 (compare:CC_NOOV
3673 (plus:SI (match_operand:SI 0 "register_operand" "%r")
3674 (match_operand:SI 1 "arith_operand" "rI"))
3675 (const_int 0)))]
3676 ""
3677 "@dots{}")
3678@end smallexample
3679
981f6289 3680The @code{SELECT_CC_MODE} macro on the SPARC returns @code{CC_NOOVmode}
03dda8e3
RK
3681for comparisons whose argument is a @code{plus}.
3682
6e4fcc95
MH
3683@node Looping Patterns
3684@section Defining Looping Instruction Patterns
3685@cindex looping instruction patterns
3686@cindex defining looping instruction patterns
3687
05713b80 3688Some machines have special jump instructions that can be utilized to
6e4fcc95
MH
3689make loops more efficient. A common example is the 68000 @samp{dbra}
3690instruction which performs a decrement of a register and a branch if the
3691result was greater than zero. Other machines, in particular digital
3692signal processors (DSPs), have special block repeat instructions to
3693provide low-overhead loop support. For example, the TI TMS320C3x/C4x
3694DSPs have a block repeat instruction that loads special registers to
3695mark the top and end of a loop and to count the number of loop
3696iterations. This avoids the need for fetching and executing a
c771326b 3697@samp{dbra}-like instruction and avoids pipeline stalls associated with
6e4fcc95
MH
3698the jump.
3699
9c34dbbf
ZW
3700GCC has three special named patterns to support low overhead looping.
3701They are @samp{decrement_and_branch_until_zero}, @samp{doloop_begin},
3702and @samp{doloop_end}. The first pattern,
6e4fcc95
MH
3703@samp{decrement_and_branch_until_zero}, is not emitted during RTL
3704generation but may be emitted during the instruction combination phase.
3705This requires the assistance of the loop optimizer, using information
3706collected during strength reduction, to reverse a loop to count down to
3707zero. Some targets also require the loop optimizer to add a
3708@code{REG_NONNEG} note to indicate that the iteration count is always
3709positive. This is needed if the target performs a signed loop
3710termination test. For example, the 68000 uses a pattern similar to the
3711following for its @code{dbra} instruction:
3712
3713@smallexample
3714@group
3715(define_insn "decrement_and_branch_until_zero"
3716 [(set (pc)
3717 (if_then_else
3718 (ge (plus:SI (match_operand:SI 0 "general_operand" "+d*am")
3719 (const_int -1))
3720 (const_int 0))
3721 (label_ref (match_operand 1 "" ""))
3722 (pc)))
3723 (set (match_dup 0)
3724 (plus:SI (match_dup 0)
3725 (const_int -1)))]
3726 "find_reg_note (insn, REG_NONNEG, 0)"
630d3d5a 3727 "@dots{}")
6e4fcc95
MH
3728@end group
3729@end smallexample
3730
3731Note that since the insn is both a jump insn and has an output, it must
3732deal with its own reloads, hence the `m' constraints. Also note that
3733since this insn is generated by the instruction combination phase
3734combining two sequential insns together into an implicit parallel insn,
3735the iteration counter needs to be biased by the same amount as the
630d3d5a 3736decrement operation, in this case @minus{}1. Note that the following similar
6e4fcc95
MH
3737pattern will not be matched by the combiner.
3738
3739@smallexample
3740@group
3741(define_insn "decrement_and_branch_until_zero"
3742 [(set (pc)
3743 (if_then_else
3744 (ge (match_operand:SI 0 "general_operand" "+d*am")
3745 (const_int 1))
3746 (label_ref (match_operand 1 "" ""))
3747 (pc)))
3748 (set (match_dup 0)
3749 (plus:SI (match_dup 0)
3750 (const_int -1)))]
3751 "find_reg_note (insn, REG_NONNEG, 0)"
630d3d5a 3752 "@dots{}")
6e4fcc95
MH
3753@end group
3754@end smallexample
3755
3756The other two special looping patterns, @samp{doloop_begin} and
c21cd8b1 3757@samp{doloop_end}, are emitted by the loop optimizer for certain
6e4fcc95 3758well-behaved loops with a finite number of loop iterations using
ebb48a4d 3759information collected during strength reduction.
6e4fcc95
MH
3760
3761The @samp{doloop_end} pattern describes the actual looping instruction
3762(or the implicit looping operation) and the @samp{doloop_begin} pattern
c21cd8b1 3763is an optional companion pattern that can be used for initialization
6e4fcc95
MH
3764needed for some low-overhead looping instructions.
3765
3766Note that some machines require the actual looping instruction to be
3767emitted at the top of the loop (e.g., the TMS320C3x/C4x DSPs). Emitting
3768the true RTL for a looping instruction at the top of the loop can cause
3769problems with flow analysis. So instead, a dummy @code{doloop} insn is
3770emitted at the end of the loop. The machine dependent reorg pass checks
3771for the presence of this @code{doloop} insn and then searches back to
3772the top of the loop, where it inserts the true looping insn (provided
3773there are no instructions in the loop which would cause problems). Any
3774additional labels can be emitted at this point. In addition, if the
3775desired special iteration counter register was not allocated, this
3776machine dependent reorg pass could emit a traditional compare and jump
3777instruction pair.
3778
3779The essential difference between the
3780@samp{decrement_and_branch_until_zero} and the @samp{doloop_end}
3781patterns is that the loop optimizer allocates an additional pseudo
3782register for the latter as an iteration counter. This pseudo register
3783cannot be used within the loop (i.e., general induction variables cannot
3784be derived from it), however, in many cases the loop induction variable
3785may become redundant and removed by the flow pass.
3786
3787
03dda8e3
RK
3788@node Insn Canonicalizations
3789@section Canonicalization of Instructions
3790@cindex canonicalization of instructions
3791@cindex insn canonicalization
3792
3793There are often cases where multiple RTL expressions could represent an
3794operation performed by a single machine instruction. This situation is
3795most commonly encountered with logical, branch, and multiply-accumulate
3796instructions. In such cases, the compiler attempts to convert these
3797multiple RTL expressions into a single canonical form to reduce the
3798number of insn patterns required.
3799
3800In addition to algebraic simplifications, following canonicalizations
3801are performed:
3802
3803@itemize @bullet
3804@item
3805For commutative and comparison operators, a constant is always made the
3806second operand. If a machine only supports a constant as the second
3807operand, only patterns that match a constant in the second operand need
3808be supplied.
3809
3810@cindex @code{neg}, canonicalization of
3811@cindex @code{not}, canonicalization of
3812@cindex @code{mult}, canonicalization of
3813@cindex @code{plus}, canonicalization of
3814@cindex @code{minus}, canonicalization of
3815For these operators, if only one operand is a @code{neg}, @code{not},
3816@code{mult}, @code{plus}, or @code{minus} expression, it will be the
3817first operand.
3818
16823694
GK
3819@item
3820In combinations of @code{neg}, @code{mult}, @code{plus}, and
3821@code{minus}, the @code{neg} operations (if any) will be moved inside
3822the operations as far as possible. For instance,
3823@code{(neg (mult A B))} is canonicalized as @code{(mult (neg A) B)}, but
3824@code{(plus (mult (neg A) B) C)} is canonicalized as
3825@code{(minus A (mult B C))}.
3826
03dda8e3
RK
3827@cindex @code{compare}, canonicalization of
3828@item
3829For the @code{compare} operator, a constant is always the second operand
3830on machines where @code{cc0} is used (@pxref{Jump Patterns}). On other
3831machines, there are rare cases where the compiler might want to construct
3832a @code{compare} with a constant as the first operand. However, these
3833cases are not common enough for it to be worthwhile to provide a pattern
3834matching a constant as the first operand unless the machine actually has
3835such an instruction.
3836
3837An operand of @code{neg}, @code{not}, @code{mult}, @code{plus}, or
3838@code{minus} is made the first operand under the same conditions as
3839above.
3840
3841@item
3842@code{(minus @var{x} (const_int @var{n}))} is converted to
3843@code{(plus @var{x} (const_int @var{-n}))}.
3844
3845@item
3846Within address computations (i.e., inside @code{mem}), a left shift is
3847converted into the appropriate multiplication by a power of two.
3848
3849@cindex @code{ior}, canonicalization of
3850@cindex @code{and}, canonicalization of
3851@cindex De Morgan's law
72938a4c 3852@item
03dda8e3
RK
3853De`Morgan's Law is used to move bitwise negation inside a bitwise
3854logical-and or logical-or operation. If this results in only one
3855operand being a @code{not} expression, it will be the first one.
3856
3857A machine that has an instruction that performs a bitwise logical-and of one
3858operand with the bitwise negation of the other should specify the pattern
3859for that instruction as
3860
3861@example
3862(define_insn ""
3863 [(set (match_operand:@var{m} 0 @dots{})
3864 (and:@var{m} (not:@var{m} (match_operand:@var{m} 1 @dots{}))
3865 (match_operand:@var{m} 2 @dots{})))]
3866 "@dots{}"
3867 "@dots{}")
3868@end example
3869
3870@noindent
3871Similarly, a pattern for a ``NAND'' instruction should be written
3872
3873@example
3874(define_insn ""
3875 [(set (match_operand:@var{m} 0 @dots{})
3876 (ior:@var{m} (not:@var{m} (match_operand:@var{m} 1 @dots{}))
3877 (not:@var{m} (match_operand:@var{m} 2 @dots{}))))]
3878 "@dots{}"
3879 "@dots{}")
3880@end example
3881
3882In both cases, it is not necessary to include patterns for the many
3883logically equivalent RTL expressions.
3884
3885@cindex @code{xor}, canonicalization of
3886@item
3887The only possible RTL expressions involving both bitwise exclusive-or
3888and bitwise negation are @code{(xor:@var{m} @var{x} @var{y})}
bd819a4a 3889and @code{(not:@var{m} (xor:@var{m} @var{x} @var{y}))}.
03dda8e3
RK
3890
3891@item
3892The sum of three items, one of which is a constant, will only appear in
3893the form
3894
3895@example
3896(plus:@var{m} (plus:@var{m} @var{x} @var{y}) @var{constant})
3897@end example
3898
3899@item
3900On machines that do not use @code{cc0},
3901@code{(compare @var{x} (const_int 0))} will be converted to
bd819a4a 3902@var{x}.
03dda8e3
RK
3903
3904@cindex @code{zero_extract}, canonicalization of
3905@cindex @code{sign_extract}, canonicalization of
3906@item
3907Equality comparisons of a group of bits (usually a single bit) with zero
3908will be written using @code{zero_extract} rather than the equivalent
3909@code{and} or @code{sign_extract} operations.
3910
3911@end itemize
3912
03dda8e3
RK
3913@node Expander Definitions
3914@section Defining RTL Sequences for Code Generation
3915@cindex expander definitions
3916@cindex code generation RTL sequences
3917@cindex defining RTL sequences for code generation
3918
3919On some target machines, some standard pattern names for RTL generation
3920cannot be handled with single insn, but a sequence of RTL insns can
3921represent them. For these target machines, you can write a
161d7b59 3922@code{define_expand} to specify how to generate the sequence of RTL@.
03dda8e3
RK
3923
3924@findex define_expand
3925A @code{define_expand} is an RTL expression that looks almost like a
3926@code{define_insn}; but, unlike the latter, a @code{define_expand} is used
3927only for RTL generation and it can produce more than one RTL insn.
3928
3929A @code{define_expand} RTX has four operands:
3930
3931@itemize @bullet
3932@item
3933The name. Each @code{define_expand} must have a name, since the only
3934use for it is to refer to it by name.
3935
03dda8e3 3936@item
f3a3d0d3
RH
3937The RTL template. This is a vector of RTL expressions representing
3938a sequence of separate instructions. Unlike @code{define_insn}, there
3939is no implicit surrounding @code{PARALLEL}.
03dda8e3
RK
3940
3941@item
3942The condition, a string containing a C expression. This expression is
3943used to express how the availability of this pattern depends on
f0523f02
JM
3944subclasses of target machine, selected by command-line options when GCC
3945is run. This is just like the condition of a @code{define_insn} that
03dda8e3
RK
3946has a standard name. Therefore, the condition (if present) may not
3947depend on the data in the insn being matched, but only the
3948target-machine-type flags. The compiler needs to test these conditions
3949during initialization in order to learn exactly which named instructions
3950are available in a particular run.
3951
3952@item
3953The preparation statements, a string containing zero or more C
3954statements which are to be executed before RTL code is generated from
3955the RTL template.
3956
3957Usually these statements prepare temporary registers for use as
3958internal operands in the RTL template, but they can also generate RTL
3959insns directly by calling routines such as @code{emit_insn}, etc.
3960Any such insns precede the ones that come from the RTL template.
3961@end itemize
3962
3963Every RTL insn emitted by a @code{define_expand} must match some
3964@code{define_insn} in the machine description. Otherwise, the compiler
3965will crash when trying to generate code for the insn or trying to optimize
3966it.
3967
3968The RTL template, in addition to controlling generation of RTL insns,
3969also describes the operands that need to be specified when this pattern
3970is used. In particular, it gives a predicate for each operand.
3971
3972A true operand, which needs to be specified in order to generate RTL from
3973the pattern, should be described with a @code{match_operand} in its first
3974occurrence in the RTL template. This enters information on the operand's
f0523f02 3975predicate into the tables that record such things. GCC uses the
03dda8e3
RK
3976information to preload the operand into a register if that is required for
3977valid RTL code. If the operand is referred to more than once, subsequent
3978references should use @code{match_dup}.
3979
3980The RTL template may also refer to internal ``operands'' which are
3981temporary registers or labels used only within the sequence made by the
3982@code{define_expand}. Internal operands are substituted into the RTL
3983template with @code{match_dup}, never with @code{match_operand}. The
3984values of the internal operands are not passed in as arguments by the
3985compiler when it requests use of this pattern. Instead, they are computed
3986within the pattern, in the preparation statements. These statements
3987compute the values and store them into the appropriate elements of
3988@code{operands} so that @code{match_dup} can find them.
3989
3990There are two special macros defined for use in the preparation statements:
3991@code{DONE} and @code{FAIL}. Use them with a following semicolon,
3992as a statement.
3993
3994@table @code
3995
3996@findex DONE
3997@item DONE
3998Use the @code{DONE} macro to end RTL generation for the pattern. The
3999only RTL insns resulting from the pattern on this occasion will be
4000those already emitted by explicit calls to @code{emit_insn} within the
4001preparation statements; the RTL template will not be generated.
4002
4003@findex FAIL
4004@item FAIL
4005Make the pattern fail on this occasion. When a pattern fails, it means
4006that the pattern was not truly available. The calling routines in the
4007compiler will try other strategies for code generation using other patterns.
4008
4009Failure is currently supported only for binary (addition, multiplication,
c771326b 4010shifting, etc.) and bit-field (@code{extv}, @code{extzv}, and @code{insv})
03dda8e3
RK
4011operations.
4012@end table
4013
55e4756f
DD
4014If the preparation falls through (invokes neither @code{DONE} nor
4015@code{FAIL}), then the @code{define_expand} acts like a
4016@code{define_insn} in that the RTL template is used to generate the
4017insn.
4018
4019The RTL template is not used for matching, only for generating the
4020initial insn list. If the preparation statement always invokes
4021@code{DONE} or @code{FAIL}, the RTL template may be reduced to a simple
4022list of operands, such as this example:
4023
4024@smallexample
4025@group
4026(define_expand "addsi3"
4027 [(match_operand:SI 0 "register_operand" "")
4028 (match_operand:SI 1 "register_operand" "")
4029 (match_operand:SI 2 "register_operand" "")]
4030@end group
4031@group
4032 ""
4033 "
58097133 4034@{
55e4756f
DD
4035 handle_add (operands[0], operands[1], operands[2]);
4036 DONE;
58097133 4037@}")
55e4756f
DD
4038@end group
4039@end smallexample
4040
03dda8e3
RK
4041Here is an example, the definition of left-shift for the SPUR chip:
4042
4043@smallexample
4044@group
4045(define_expand "ashlsi3"
4046 [(set (match_operand:SI 0 "register_operand" "")
4047 (ashift:SI
4048@end group
4049@group
4050 (match_operand:SI 1 "register_operand" "")
4051 (match_operand:SI 2 "nonmemory_operand" "")))]
4052 ""
4053 "
4054@end group
4055@end smallexample
4056
4057@smallexample
4058@group
4059@{
4060 if (GET_CODE (operands[2]) != CONST_INT
4061 || (unsigned) INTVAL (operands[2]) > 3)
4062 FAIL;
4063@}")
4064@end group
4065@end smallexample
4066
4067@noindent
4068This example uses @code{define_expand} so that it can generate an RTL insn
4069for shifting when the shift-count is in the supported range of 0 to 3 but
4070fail in other cases where machine insns aren't available. When it fails,
4071the compiler tries another strategy using different patterns (such as, a
4072library call).
4073
4074If the compiler were able to handle nontrivial condition-strings in
4075patterns with names, then it would be possible to use a
4076@code{define_insn} in that case. Here is another case (zero-extension
4077on the 68000) which makes more use of the power of @code{define_expand}:
4078
4079@smallexample
4080(define_expand "zero_extendhisi2"
4081 [(set (match_operand:SI 0 "general_operand" "")
4082 (const_int 0))
4083 (set (strict_low_part
4084 (subreg:HI
4085 (match_dup 0)
4086 0))
4087 (match_operand:HI 1 "general_operand" ""))]
4088 ""
4089 "operands[1] = make_safe_from (operands[1], operands[0]);")
4090@end smallexample
4091
4092@noindent
4093@findex make_safe_from
4094Here two RTL insns are generated, one to clear the entire output operand
4095and the other to copy the input operand into its low half. This sequence
4096is incorrect if the input operand refers to [the old value of] the output
4097operand, so the preparation statement makes sure this isn't so. The
4098function @code{make_safe_from} copies the @code{operands[1]} into a
4099temporary register if it refers to @code{operands[0]}. It does this
4100by emitting another RTL insn.
4101
4102Finally, a third example shows the use of an internal operand.
4103Zero-extension on the SPUR chip is done by @code{and}-ing the result
4104against a halfword mask. But this mask cannot be represented by a
4105@code{const_int} because the constant value is too large to be legitimate
4106on this machine. So it must be copied into a register with
4107@code{force_reg} and then the register used in the @code{and}.
4108
4109@smallexample
4110(define_expand "zero_extendhisi2"
4111 [(set (match_operand:SI 0 "register_operand" "")
4112 (and:SI (subreg:SI
4113 (match_operand:HI 1 "register_operand" "")
4114 0)
4115 (match_dup 2)))]
4116 ""
4117 "operands[2]
3a598fbe 4118 = force_reg (SImode, GEN_INT (65535)); ")
03dda8e3
RK
4119@end smallexample
4120
4121@strong{Note:} If the @code{define_expand} is used to serve a
c771326b 4122standard binary or unary arithmetic operation or a bit-field operation,
03dda8e3
RK
4123then the last insn it generates must not be a @code{code_label},
4124@code{barrier} or @code{note}. It must be an @code{insn},
4125@code{jump_insn} or @code{call_insn}. If you don't need a real insn
4126at the end, emit an insn to copy the result of the operation into
4127itself. Such an insn will generate no code, but it can avoid problems
bd819a4a 4128in the compiler.
03dda8e3
RK
4129
4130@node Insn Splitting
4131@section Defining How to Split Instructions
4132@cindex insn splitting
4133@cindex instruction splitting
4134@cindex splitting instructions
4135
fae15c93
VM
4136There are two cases where you should specify how to split a pattern
4137into multiple insns. On machines that have instructions requiring
4138delay slots (@pxref{Delay Slots}) or that have instructions whose
4139output is not available for multiple cycles (@pxref{Processor pipeline
4140description}), the compiler phases that optimize these cases need to
4141be able to move insns into one-instruction delay slots. However, some
4142insns may generate more than one machine instruction. These insns
4143cannot be placed into a delay slot.
03dda8e3
RK
4144
4145Often you can rewrite the single insn as a list of individual insns,
4146each corresponding to one machine instruction. The disadvantage of
4147doing so is that it will cause the compilation to be slower and require
4148more space. If the resulting insns are too complex, it may also
4149suppress some optimizations. The compiler splits the insn if there is a
4150reason to believe that it might improve instruction or delay slot
4151scheduling.
4152
4153The insn combiner phase also splits putative insns. If three insns are
4154merged into one insn with a complex expression that cannot be matched by
4155some @code{define_insn} pattern, the combiner phase attempts to split
4156the complex pattern into two insns that are recognized. Usually it can
4157break the complex pattern into two patterns by splitting out some
4158subexpression. However, in some other cases, such as performing an
4159addition of a large constant in two insns on a RISC machine, the way to
4160split the addition into two insns is machine-dependent.
4161
f3a3d0d3 4162@findex define_split
03dda8e3
RK
4163The @code{define_split} definition tells the compiler how to split a
4164complex insn into several simpler insns. It looks like this:
4165
4166@smallexample
4167(define_split
4168 [@var{insn-pattern}]
4169 "@var{condition}"
4170 [@var{new-insn-pattern-1}
4171 @var{new-insn-pattern-2}
4172 @dots{}]
630d3d5a 4173 "@var{preparation-statements}")
03dda8e3
RK
4174@end smallexample
4175
4176@var{insn-pattern} is a pattern that needs to be split and
4177@var{condition} is the final condition to be tested, as in a
4178@code{define_insn}. When an insn matching @var{insn-pattern} and
4179satisfying @var{condition} is found, it is replaced in the insn list
4180with the insns given by @var{new-insn-pattern-1},
4181@var{new-insn-pattern-2}, etc.
4182
630d3d5a 4183The @var{preparation-statements} are similar to those statements that
03dda8e3
RK
4184are specified for @code{define_expand} (@pxref{Expander Definitions})
4185and are executed before the new RTL is generated to prepare for the
4186generated code or emit some insns whose pattern is not fixed. Unlike
4187those in @code{define_expand}, however, these statements must not
4188generate any new pseudo-registers. Once reload has completed, they also
4189must not allocate any space in the stack frame.
4190
4191Patterns are matched against @var{insn-pattern} in two different
4192circumstances. If an insn needs to be split for delay slot scheduling
4193or insn scheduling, the insn is already known to be valid, which means
4194that it must have been matched by some @code{define_insn} and, if
df2a54e9 4195@code{reload_completed} is nonzero, is known to satisfy the constraints
03dda8e3
RK
4196of that @code{define_insn}. In that case, the new insn patterns must
4197also be insns that are matched by some @code{define_insn} and, if
df2a54e9 4198@code{reload_completed} is nonzero, must also satisfy the constraints
03dda8e3
RK
4199of those definitions.
4200
4201As an example of this usage of @code{define_split}, consider the following
4202example from @file{a29k.md}, which splits a @code{sign_extend} from
4203@code{HImode} to @code{SImode} into a pair of shift insns:
4204
4205@smallexample
4206(define_split
4207 [(set (match_operand:SI 0 "gen_reg_operand" "")
4208 (sign_extend:SI (match_operand:HI 1 "gen_reg_operand" "")))]
4209 ""
4210 [(set (match_dup 0)
4211 (ashift:SI (match_dup 1)
4212 (const_int 16)))
4213 (set (match_dup 0)
4214 (ashiftrt:SI (match_dup 0)
4215 (const_int 16)))]
4216 "
4217@{ operands[1] = gen_lowpart (SImode, operands[1]); @}")
4218@end smallexample
4219
4220When the combiner phase tries to split an insn pattern, it is always the
4221case that the pattern is @emph{not} matched by any @code{define_insn}.
4222The combiner pass first tries to split a single @code{set} expression
4223and then the same @code{set} expression inside a @code{parallel}, but
4224followed by a @code{clobber} of a pseudo-reg to use as a scratch
4225register. In these cases, the combiner expects exactly two new insn
4226patterns to be generated. It will verify that these patterns match some
4227@code{define_insn} definitions, so you need not do this test in the
4228@code{define_split} (of course, there is no point in writing a
4229@code{define_split} that will never produce insns that match).
4230
4231Here is an example of this use of @code{define_split}, taken from
4232@file{rs6000.md}:
4233
4234@smallexample
4235(define_split
4236 [(set (match_operand:SI 0 "gen_reg_operand" "")
4237 (plus:SI (match_operand:SI 1 "gen_reg_operand" "")
4238 (match_operand:SI 2 "non_add_cint_operand" "")))]
4239 ""
4240 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
4241 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
4242"
4243@{
4244 int low = INTVAL (operands[2]) & 0xffff;
4245 int high = (unsigned) INTVAL (operands[2]) >> 16;
4246
4247 if (low & 0x8000)
4248 high++, low |= 0xffff0000;
4249
3a598fbe
JL
4250 operands[3] = GEN_INT (high << 16);
4251 operands[4] = GEN_INT (low);
03dda8e3
RK
4252@}")
4253@end smallexample
4254
4255Here the predicate @code{non_add_cint_operand} matches any
4256@code{const_int} that is @emph{not} a valid operand of a single add
4257insn. The add with the smaller displacement is written so that it
4258can be substituted into the address of a subsequent operation.
4259
4260An example that uses a scratch register, from the same file, generates
4261an equality comparison of a register and a large constant:
4262
4263@smallexample
4264(define_split
4265 [(set (match_operand:CC 0 "cc_reg_operand" "")
4266 (compare:CC (match_operand:SI 1 "gen_reg_operand" "")
4267 (match_operand:SI 2 "non_short_cint_operand" "")))
4268 (clobber (match_operand:SI 3 "gen_reg_operand" ""))]
4269 "find_single_use (operands[0], insn, 0)
4270 && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
4271 || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
4272 [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
4273 (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
4274 "
4275@{
4276 /* Get the constant we are comparing against, C, and see what it
4277 looks like sign-extended to 16 bits. Then see what constant
4278 could be XOR'ed with C to get the sign-extended value. */
4279
4280 int c = INTVAL (operands[2]);
4281 int sextc = (c << 16) >> 16;
4282 int xorv = c ^ sextc;
4283
3a598fbe
JL
4284 operands[4] = GEN_INT (xorv);
4285 operands[5] = GEN_INT (sextc);
03dda8e3
RK
4286@}")
4287@end smallexample
4288
4289To avoid confusion, don't write a single @code{define_split} that
4290accepts some insns that match some @code{define_insn} as well as some
4291insns that don't. Instead, write two separate @code{define_split}
4292definitions, one for the insns that are valid and one for the insns that
4293are not valid.
4294
6b24c259
JH
4295The splitter is allowed to split jump instructions into sequence of
4296jumps or create new jumps in while splitting non-jump instructions. As
4297the central flowgraph and branch prediction information needs to be updated,
f282ffb3 4298several restriction apply.
6b24c259
JH
4299
4300Splitting of jump instruction into sequence that over by another jump
c21cd8b1 4301instruction is always valid, as compiler expect identical behavior of new
6b24c259
JH
4302jump. When new sequence contains multiple jump instructions or new labels,
4303more assistance is needed. Splitter is required to create only unconditional
4304jumps, or simple conditional jump instructions. Additionally it must attach a
4305@code{REG_BR_PROB} note to each conditional jump. An global variable
4306@code{split_branch_probability} hold the probability of original branch in case
4307it was an simple conditional jump, @minus{}1 otherwise. To simplify
4308recomputing of edge frequencies, new sequence is required to have only
4309forward jumps to the newly created labels.
4310
fae81b38 4311@findex define_insn_and_split
c88c0d42
CP
4312For the common case where the pattern of a define_split exactly matches the
4313pattern of a define_insn, use @code{define_insn_and_split}. It looks like
4314this:
4315
4316@smallexample
4317(define_insn_and_split
4318 [@var{insn-pattern}]
4319 "@var{condition}"
4320 "@var{output-template}"
4321 "@var{split-condition}"
4322 [@var{new-insn-pattern-1}
4323 @var{new-insn-pattern-2}
4324 @dots{}]
630d3d5a 4325 "@var{preparation-statements}"
c88c0d42
CP
4326 [@var{insn-attributes}])
4327
4328@end smallexample
4329
4330@var{insn-pattern}, @var{condition}, @var{output-template}, and
4331@var{insn-attributes} are used as in @code{define_insn}. The
4332@var{new-insn-pattern} vector and the @var{preparation-statements} are used as
4333in a @code{define_split}. The @var{split-condition} is also used as in
4334@code{define_split}, with the additional behavior that if the condition starts
4335with @samp{&&}, the condition used for the split will be the constructed as a
d7d9c429 4336logical ``and'' of the split condition with the insn condition. For example,
c88c0d42
CP
4337from i386.md:
4338
4339@smallexample
4340(define_insn_and_split "zero_extendhisi2_and"
4341 [(set (match_operand:SI 0 "register_operand" "=r")
4342 (zero_extend:SI (match_operand:HI 1 "register_operand" "0")))
4343 (clobber (reg:CC 17))]
4344 "TARGET_ZERO_EXTEND_WITH_AND && !optimize_size"
4345 "#"
4346 "&& reload_completed"
f282ffb3 4347 [(parallel [(set (match_dup 0)
9c34dbbf 4348 (and:SI (match_dup 0) (const_int 65535)))
c88c0d42
CP
4349 (clobber (reg:CC 17))])]
4350 ""
4351 [(set_attr "type" "alu1")])
4352
4353@end smallexample
4354
ebb48a4d 4355In this case, the actual split condition will be
aee96fe9 4356@samp{TARGET_ZERO_EXTEND_WITH_AND && !optimize_size && reload_completed}.
c88c0d42
CP
4357
4358The @code{define_insn_and_split} construction provides exactly the same
4359functionality as two separate @code{define_insn} and @code{define_split}
4360patterns. It exists for compactness, and as a maintenance tool to prevent
4361having to ensure the two patterns' templates match.
4362
04d8aa70
AM
4363@node Including Patterns
4364@section Including Patterns in Machine Descriptions.
4365@cindex insn includes
4366
4367@findex include
4368The @code{include} pattern tells the compiler tools where to
4369look for patterns that are in files other than in the file
4370@file{.md}. This is used only at build time and there is no preprocessing allowed.
4371
4372It looks like:
4373
4374@smallexample
4375
4376(include
4377 @var{pathname})
4378@end smallexample
4379
4380For example:
4381
4382@smallexample
4383
f282ffb3 4384(include "filestuff")
04d8aa70
AM
4385
4386@end smallexample
4387
27d30956 4388Where @var{pathname} is a string that specifies the location of the file,
04d8aa70
AM
4389specifies the include file to be in @file{gcc/config/target/filestuff}. The
4390directory @file{gcc/config/target} is regarded as the default directory.
4391
4392
f282ffb3
JM
4393Machine descriptions may be split up into smaller more manageable subsections
4394and placed into subdirectories.
04d8aa70
AM
4395
4396By specifying:
4397
4398@smallexample
4399
f282ffb3 4400(include "BOGUS/filestuff")
04d8aa70
AM
4401
4402@end smallexample
4403
4404the include file is specified to be in @file{gcc/config/@var{target}/BOGUS/filestuff}.
4405
4406Specifying an absolute path for the include file such as;
4407@smallexample
4408
f282ffb3 4409(include "/u2/BOGUS/filestuff")
04d8aa70
AM
4410
4411@end smallexample
f282ffb3 4412is permitted but is not encouraged.
04d8aa70
AM
4413
4414@subsection RTL Generation Tool Options for Directory Search
4415@cindex directory options .md
4416@cindex options, directory search
4417@cindex search options
4418
4419The @option{-I@var{dir}} option specifies directories to search for machine descriptions.
4420For example:
4421
4422@smallexample
4423
4424genrecog -I/p1/abc/proc1 -I/p2/abcd/pro2 target.md
4425
4426@end smallexample
4427
4428
4429Add the directory @var{dir} to the head of the list of directories to be
4430searched for header files. This can be used to override a system machine definition
4431file, substituting your own version, since these directories are
4432searched before the default machine description file directories. If you use more than
4433one @option{-I} option, the directories are scanned in left-to-right
4434order; the standard default directory come after.
4435
4436
f3a3d0d3
RH
4437@node Peephole Definitions
4438@section Machine-Specific Peephole Optimizers
4439@cindex peephole optimizer definitions
4440@cindex defining peephole optimizers
4441
4442In addition to instruction patterns the @file{md} file may contain
4443definitions of machine-specific peephole optimizations.
4444
4445The combiner does not notice certain peephole optimizations when the data
4446flow in the program does not suggest that it should try them. For example,
4447sometimes two consecutive insns related in purpose can be combined even
4448though the second one does not appear to use a register computed in the
4449first one. A machine-specific peephole optimizer can detect such
4450opportunities.
4451
4452There are two forms of peephole definitions that may be used. The
4453original @code{define_peephole} is run at assembly output time to
4454match insns and substitute assembly text. Use of @code{define_peephole}
4455is deprecated.
4456
4457A newer @code{define_peephole2} matches insns and substitutes new
4458insns. The @code{peephole2} pass is run after register allocation
ebb48a4d 4459but before scheduling, which may result in much better code for
f3a3d0d3
RH
4460targets that do scheduling.
4461
4462@menu
4463* define_peephole:: RTL to Text Peephole Optimizers
4464* define_peephole2:: RTL to RTL Peephole Optimizers
4465@end menu
4466
4467@node define_peephole
4468@subsection RTL to Text Peephole Optimizers
4469@findex define_peephole
4470
4471@need 1000
4472A definition looks like this:
4473
4474@smallexample
4475(define_peephole
4476 [@var{insn-pattern-1}
4477 @var{insn-pattern-2}
4478 @dots{}]
4479 "@var{condition}"
4480 "@var{template}"
630d3d5a 4481 "@var{optional-insn-attributes}")
f3a3d0d3
RH
4482@end smallexample
4483
4484@noindent
4485The last string operand may be omitted if you are not using any
4486machine-specific information in this machine description. If present,
4487it must obey the same rules as in a @code{define_insn}.
4488
4489In this skeleton, @var{insn-pattern-1} and so on are patterns to match
4490consecutive insns. The optimization applies to a sequence of insns when
4491@var{insn-pattern-1} matches the first one, @var{insn-pattern-2} matches
bd819a4a 4492the next, and so on.
f3a3d0d3
RH
4493
4494Each of the insns matched by a peephole must also match a
4495@code{define_insn}. Peepholes are checked only at the last stage just
4496before code generation, and only optionally. Therefore, any insn which
4497would match a peephole but no @code{define_insn} will cause a crash in code
4498generation in an unoptimized compilation, or at various optimization
4499stages.
4500
4501The operands of the insns are matched with @code{match_operands},
4502@code{match_operator}, and @code{match_dup}, as usual. What is not
4503usual is that the operand numbers apply to all the insn patterns in the
4504definition. So, you can check for identical operands in two insns by
4505using @code{match_operand} in one insn and @code{match_dup} in the
4506other.
4507
4508The operand constraints used in @code{match_operand} patterns do not have
4509any direct effect on the applicability of the peephole, but they will
4510be validated afterward, so make sure your constraints are general enough
4511to apply whenever the peephole matches. If the peephole matches
4512but the constraints are not satisfied, the compiler will crash.
4513
4514It is safe to omit constraints in all the operands of the peephole; or
4515you can write constraints which serve as a double-check on the criteria
4516previously tested.
4517
4518Once a sequence of insns matches the patterns, the @var{condition} is
4519checked. This is a C expression which makes the final decision whether to
4520perform the optimization (we do so if the expression is nonzero). If
4521@var{condition} is omitted (in other words, the string is empty) then the
4522optimization is applied to every sequence of insns that matches the
4523patterns.
4524
4525The defined peephole optimizations are applied after register allocation
4526is complete. Therefore, the peephole definition can check which
4527operands have ended up in which kinds of registers, just by looking at
4528the operands.
4529
4530@findex prev_active_insn
4531The way to refer to the operands in @var{condition} is to write
4532@code{operands[@var{i}]} for operand number @var{i} (as matched by
4533@code{(match_operand @var{i} @dots{})}). Use the variable @code{insn}
4534to refer to the last of the insns being matched; use
4535@code{prev_active_insn} to find the preceding insns.
4536
4537@findex dead_or_set_p
4538When optimizing computations with intermediate results, you can use
4539@var{condition} to match only when the intermediate results are not used
4540elsewhere. Use the C expression @code{dead_or_set_p (@var{insn},
4541@var{op})}, where @var{insn} is the insn in which you expect the value
4542to be used for the last time (from the value of @code{insn}, together
4543with use of @code{prev_nonnote_insn}), and @var{op} is the intermediate
bd819a4a 4544value (from @code{operands[@var{i}]}).
f3a3d0d3
RH
4545
4546Applying the optimization means replacing the sequence of insns with one
4547new insn. The @var{template} controls ultimate output of assembler code
4548for this combined insn. It works exactly like the template of a
4549@code{define_insn}. Operand numbers in this template are the same ones
4550used in matching the original sequence of insns.
4551
4552The result of a defined peephole optimizer does not need to match any of
4553the insn patterns in the machine description; it does not even have an
4554opportunity to match them. The peephole optimizer definition itself serves
4555as the insn pattern to control how the insn is output.
4556
4557Defined peephole optimizers are run as assembler code is being output,
4558so the insns they produce are never combined or rearranged in any way.
4559
4560Here is an example, taken from the 68000 machine description:
4561
4562@smallexample
4563(define_peephole
4564 [(set (reg:SI 15) (plus:SI (reg:SI 15) (const_int 4)))
4565 (set (match_operand:DF 0 "register_operand" "=f")
4566 (match_operand:DF 1 "register_operand" "ad"))]
4567 "FP_REG_P (operands[0]) && ! FP_REG_P (operands[1])"
f3a3d0d3
RH
4568@{
4569 rtx xoperands[2];
4570 xoperands[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
4571#ifdef MOTOROLA
0f40f9f7
ZW
4572 output_asm_insn ("move.l %1,(sp)", xoperands);
4573 output_asm_insn ("move.l %1,-(sp)", operands);
4574 return "fmove.d (sp)+,%0";
f3a3d0d3 4575#else
0f40f9f7
ZW
4576 output_asm_insn ("movel %1,sp@@", xoperands);
4577 output_asm_insn ("movel %1,sp@@-", operands);
4578 return "fmoved sp@@+,%0";
f3a3d0d3 4579#endif
0f40f9f7 4580@})
f3a3d0d3
RH
4581@end smallexample
4582
4583@need 1000
4584The effect of this optimization is to change
4585
4586@smallexample
4587@group
4588jbsr _foobar
4589addql #4,sp
4590movel d1,sp@@-
4591movel d0,sp@@-
4592fmoved sp@@+,fp0
4593@end group
4594@end smallexample
4595
4596@noindent
4597into
4598
4599@smallexample
4600@group
4601jbsr _foobar
4602movel d1,sp@@
4603movel d0,sp@@-
4604fmoved sp@@+,fp0
4605@end group
4606@end smallexample
4607
4608@ignore
4609@findex CC_REVERSED
4610If a peephole matches a sequence including one or more jump insns, you must
4611take account of the flags such as @code{CC_REVERSED} which specify that the
4612condition codes are represented in an unusual manner. The compiler
4613automatically alters any ordinary conditional jumps which occur in such
4614situations, but the compiler cannot alter jumps which have been replaced by
4615peephole optimizations. So it is up to you to alter the assembler code
4616that the peephole produces. Supply C code to write the assembler output,
4617and in this C code check the condition code status flags and change the
4618assembler code as appropriate.
4619@end ignore
4620
4621@var{insn-pattern-1} and so on look @emph{almost} like the second
4622operand of @code{define_insn}. There is one important difference: the
4623second operand of @code{define_insn} consists of one or more RTX's
4624enclosed in square brackets. Usually, there is only one: then the same
4625action can be written as an element of a @code{define_peephole}. But
4626when there are multiple actions in a @code{define_insn}, they are
4627implicitly enclosed in a @code{parallel}. Then you must explicitly
4628write the @code{parallel}, and the square brackets within it, in the
4629@code{define_peephole}. Thus, if an insn pattern looks like this,
4630
4631@smallexample
4632(define_insn "divmodsi4"
4633 [(set (match_operand:SI 0 "general_operand" "=d")
4634 (div:SI (match_operand:SI 1 "general_operand" "0")
4635 (match_operand:SI 2 "general_operand" "dmsK")))
4636 (set (match_operand:SI 3 "general_operand" "=d")
4637 (mod:SI (match_dup 1) (match_dup 2)))]
4638 "TARGET_68020"
4639 "divsl%.l %2,%3:%0")
4640@end smallexample
4641
4642@noindent
4643then the way to mention this insn in a peephole is as follows:
4644
4645@smallexample
4646(define_peephole
4647 [@dots{}
4648 (parallel
4649 [(set (match_operand:SI 0 "general_operand" "=d")
4650 (div:SI (match_operand:SI 1 "general_operand" "0")
4651 (match_operand:SI 2 "general_operand" "dmsK")))
4652 (set (match_operand:SI 3 "general_operand" "=d")
4653 (mod:SI (match_dup 1) (match_dup 2)))])
4654 @dots{}]
4655 @dots{})
4656@end smallexample
4657
4658@node define_peephole2
4659@subsection RTL to RTL Peephole Optimizers
4660@findex define_peephole2
4661
4662The @code{define_peephole2} definition tells the compiler how to
ebb48a4d 4663substitute one sequence of instructions for another sequence,
f3a3d0d3
RH
4664what additional scratch registers may be needed and what their
4665lifetimes must be.
4666
4667@smallexample
4668(define_peephole2
4669 [@var{insn-pattern-1}
4670 @var{insn-pattern-2}
4671 @dots{}]
4672 "@var{condition}"
4673 [@var{new-insn-pattern-1}
4674 @var{new-insn-pattern-2}
4675 @dots{}]
630d3d5a 4676 "@var{preparation-statements}")
f3a3d0d3
RH
4677@end smallexample
4678
4679The definition is almost identical to @code{define_split}
4680(@pxref{Insn Splitting}) except that the pattern to match is not a
4681single instruction, but a sequence of instructions.
4682
4683It is possible to request additional scratch registers for use in the
4684output template. If appropriate registers are not free, the pattern
4685will simply not match.
4686
4687@findex match_scratch
4688@findex match_dup
4689Scratch registers are requested with a @code{match_scratch} pattern at
4690the top level of the input pattern. The allocated register (initially) will
4691be dead at the point requested within the original sequence. If the scratch
4692is used at more than a single point, a @code{match_dup} pattern at the
4693top level of the input pattern marks the last position in the input sequence
4694at which the register must be available.
4695
4696Here is an example from the IA-32 machine description:
4697
4698@smallexample
4699(define_peephole2
4700 [(match_scratch:SI 2 "r")
4701 (parallel [(set (match_operand:SI 0 "register_operand" "")
4702 (match_operator:SI 3 "arith_or_logical_operator"
4703 [(match_dup 0)
4704 (match_operand:SI 1 "memory_operand" "")]))
4705 (clobber (reg:CC 17))])]
4706 "! optimize_size && ! TARGET_READ_MODIFY"
4707 [(set (match_dup 2) (match_dup 1))
4708 (parallel [(set (match_dup 0)
4709 (match_op_dup 3 [(match_dup 0) (match_dup 2)]))
4710 (clobber (reg:CC 17))])]
4711 "")
4712@end smallexample
4713
4714@noindent
4715This pattern tries to split a load from its use in the hopes that we'll be
4716able to schedule around the memory load latency. It allocates a single
4717@code{SImode} register of class @code{GENERAL_REGS} (@code{"r"}) that needs
4718to be live only at the point just before the arithmetic.
4719
b192711e 4720A real example requiring extended scratch lifetimes is harder to come by,
f3a3d0d3
RH
4721so here's a silly made-up example:
4722
4723@smallexample
4724(define_peephole2
4725 [(match_scratch:SI 4 "r")
4726 (set (match_operand:SI 0 "" "") (match_operand:SI 1 "" ""))
4727 (set (match_operand:SI 2 "" "") (match_dup 1))
4728 (match_dup 4)
4729 (set (match_operand:SI 3 "" "") (match_dup 1))]
630d3d5a 4730 "/* @r{determine 1 does not overlap 0 and 2} */"
f3a3d0d3
RH
4731 [(set (match_dup 4) (match_dup 1))
4732 (set (match_dup 0) (match_dup 4))
4733 (set (match_dup 2) (match_dup 4))]
4734 (set (match_dup 3) (match_dup 4))]
4735 "")
4736@end smallexample
4737
4738@noindent
a628d195
RH
4739If we had not added the @code{(match_dup 4)} in the middle of the input
4740sequence, it might have been the case that the register we chose at the
4741beginning of the sequence is killed by the first or second @code{set}.
f3a3d0d3 4742
03dda8e3
RK
4743@node Insn Attributes
4744@section Instruction Attributes
4745@cindex insn attributes
4746@cindex instruction attributes
4747
4748In addition to describing the instruction supported by the target machine,
4749the @file{md} file also defines a group of @dfn{attributes} and a set of
4750values for each. Every generated insn is assigned a value for each attribute.
4751One possible attribute would be the effect that the insn has on the machine's
4752condition code. This attribute can then be used by @code{NOTICE_UPDATE_CC}
4753to track the condition codes.
4754
4755@menu
4756* Defining Attributes:: Specifying attributes and their values.
4757* Expressions:: Valid expressions for attribute values.
4758* Tagging Insns:: Assigning attribute values to insns.
4759* Attr Example:: An example of assigning attributes.
4760* Insn Lengths:: Computing the length of insns.
4761* Constant Attributes:: Defining attributes that are constant.
4762* Delay Slots:: Defining delay slots required for a machine.
fae15c93 4763* Processor pipeline description:: Specifying information for insn scheduling.
03dda8e3
RK
4764@end menu
4765
4766@node Defining Attributes
4767@subsection Defining Attributes and their Values
4768@cindex defining attributes and their values
4769@cindex attributes, defining
4770
4771@findex define_attr
4772The @code{define_attr} expression is used to define each attribute required
4773by the target machine. It looks like:
4774
4775@smallexample
4776(define_attr @var{name} @var{list-of-values} @var{default})
4777@end smallexample
4778
4779@var{name} is a string specifying the name of the attribute being defined.
4780
4781@var{list-of-values} is either a string that specifies a comma-separated
4782list of values that can be assigned to the attribute, or a null string to
4783indicate that the attribute takes numeric values.
4784
4785@var{default} is an attribute expression that gives the value of this
4786attribute for insns that match patterns whose definition does not include
4787an explicit value for this attribute. @xref{Attr Example}, for more
4788information on the handling of defaults. @xref{Constant Attributes},
4789for information on attributes that do not depend on any particular insn.
4790
4791@findex insn-attr.h
4792For each defined attribute, a number of definitions are written to the
4793@file{insn-attr.h} file. For cases where an explicit set of values is
4794specified for an attribute, the following are defined:
4795
4796@itemize @bullet
4797@item
4798A @samp{#define} is written for the symbol @samp{HAVE_ATTR_@var{name}}.
4799
4800@item
4801An enumeral class is defined for @samp{attr_@var{name}} with
4802elements of the form @samp{@var{upper-name}_@var{upper-value}} where
4803the attribute name and value are first converted to upper case.
4804
4805@item
4806A function @samp{get_attr_@var{name}} is defined that is passed an insn and
4807returns the attribute value for that insn.
4808@end itemize
4809
4810For example, if the following is present in the @file{md} file:
4811
4812@smallexample
4813(define_attr "type" "branch,fp,load,store,arith" @dots{})
4814@end smallexample
4815
4816@noindent
4817the following lines will be written to the file @file{insn-attr.h}.
4818
4819@smallexample
4820#define HAVE_ATTR_type
4821enum attr_type @{TYPE_BRANCH, TYPE_FP, TYPE_LOAD,
4822 TYPE_STORE, TYPE_ARITH@};
4823extern enum attr_type get_attr_type ();
4824@end smallexample
4825
4826If the attribute takes numeric values, no @code{enum} type will be
4827defined and the function to obtain the attribute's value will return
4828@code{int}.
4829
4830@node Expressions
4831@subsection Attribute Expressions
4832@cindex attribute expressions
4833
4834RTL expressions used to define attributes use the codes described above
4835plus a few specific to attribute definitions, to be discussed below.
4836Attribute value expressions must have one of the following forms:
4837
4838@table @code
4839@cindex @code{const_int} and attributes
4840@item (const_int @var{i})
4841The integer @var{i} specifies the value of a numeric attribute. @var{i}
4842must be non-negative.
4843
4844The value of a numeric attribute can be specified either with a
00bc45c1
RH
4845@code{const_int}, or as an integer represented as a string in
4846@code{const_string}, @code{eq_attr} (see below), @code{attr},
4847@code{symbol_ref}, simple arithmetic expressions, and @code{set_attr}
4848overrides on specific instructions (@pxref{Tagging Insns}).
03dda8e3
RK
4849
4850@cindex @code{const_string} and attributes
4851@item (const_string @var{value})
4852The string @var{value} specifies a constant attribute value.
4853If @var{value} is specified as @samp{"*"}, it means that the default value of
4854the attribute is to be used for the insn containing this expression.
4855@samp{"*"} obviously cannot be used in the @var{default} expression
bd819a4a 4856of a @code{define_attr}.
03dda8e3
RK
4857
4858If the attribute whose value is being specified is numeric, @var{value}
4859must be a string containing a non-negative integer (normally
4860@code{const_int} would be used in this case). Otherwise, it must
4861contain one of the valid values for the attribute.
4862
4863@cindex @code{if_then_else} and attributes
4864@item (if_then_else @var{test} @var{true-value} @var{false-value})
4865@var{test} specifies an attribute test, whose format is defined below.
4866The value of this expression is @var{true-value} if @var{test} is true,
4867otherwise it is @var{false-value}.
4868
4869@cindex @code{cond} and attributes
4870@item (cond [@var{test1} @var{value1} @dots{}] @var{default})
4871The first operand of this expression is a vector containing an even
4872number of expressions and consisting of pairs of @var{test} and @var{value}
4873expressions. The value of the @code{cond} expression is that of the
4874@var{value} corresponding to the first true @var{test} expression. If
4875none of the @var{test} expressions are true, the value of the @code{cond}
4876expression is that of the @var{default} expression.
4877@end table
4878
4879@var{test} expressions can have one of the following forms:
4880
4881@table @code
4882@cindex @code{const_int} and attribute tests
4883@item (const_int @var{i})
df2a54e9 4884This test is true if @var{i} is nonzero and false otherwise.
03dda8e3
RK
4885
4886@cindex @code{not} and attributes
4887@cindex @code{ior} and attributes
4888@cindex @code{and} and attributes
4889@item (not @var{test})
4890@itemx (ior @var{test1} @var{test2})
4891@itemx (and @var{test1} @var{test2})
4892These tests are true if the indicated logical function is true.
4893
4894@cindex @code{match_operand} and attributes
4895@item (match_operand:@var{m} @var{n} @var{pred} @var{constraints})
4896This test is true if operand @var{n} of the insn whose attribute value
4897is being determined has mode @var{m} (this part of the test is ignored
4898if @var{m} is @code{VOIDmode}) and the function specified by the string
df2a54e9 4899@var{pred} returns a nonzero value when passed operand @var{n} and mode
03dda8e3
RK
4900@var{m} (this part of the test is ignored if @var{pred} is the null
4901string).
4902
4903The @var{constraints} operand is ignored and should be the null string.
4904
4905@cindex @code{le} and attributes
4906@cindex @code{leu} and attributes
4907@cindex @code{lt} and attributes
4908@cindex @code{gt} and attributes
4909@cindex @code{gtu} and attributes
4910@cindex @code{ge} and attributes
4911@cindex @code{geu} and attributes
4912@cindex @code{ne} and attributes
4913@cindex @code{eq} and attributes
4914@cindex @code{plus} and attributes
4915@cindex @code{minus} and attributes
4916@cindex @code{mult} and attributes
4917@cindex @code{div} and attributes
4918@cindex @code{mod} and attributes
4919@cindex @code{abs} and attributes
4920@cindex @code{neg} and attributes
4921@cindex @code{ashift} and attributes
4922@cindex @code{lshiftrt} and attributes
4923@cindex @code{ashiftrt} and attributes
4924@item (le @var{arith1} @var{arith2})
4925@itemx (leu @var{arith1} @var{arith2})
4926@itemx (lt @var{arith1} @var{arith2})
4927@itemx (ltu @var{arith1} @var{arith2})
4928@itemx (gt @var{arith1} @var{arith2})
4929@itemx (gtu @var{arith1} @var{arith2})
4930@itemx (ge @var{arith1} @var{arith2})
4931@itemx (geu @var{arith1} @var{arith2})
4932@itemx (ne @var{arith1} @var{arith2})
4933@itemx (eq @var{arith1} @var{arith2})
4934These tests are true if the indicated comparison of the two arithmetic
4935expressions is true. Arithmetic expressions are formed with
4936@code{plus}, @code{minus}, @code{mult}, @code{div}, @code{mod},
4937@code{abs}, @code{neg}, @code{and}, @code{ior}, @code{xor}, @code{not},
bd819a4a 4938@code{ashift}, @code{lshiftrt}, and @code{ashiftrt} expressions.
03dda8e3
RK
4939
4940@findex get_attr
4941@code{const_int} and @code{symbol_ref} are always valid terms (@pxref{Insn
4942Lengths},for additional forms). @code{symbol_ref} is a string
4943denoting a C expression that yields an @code{int} when evaluated by the
4944@samp{get_attr_@dots{}} routine. It should normally be a global
bd819a4a 4945variable.
03dda8e3
RK
4946
4947@findex eq_attr
4948@item (eq_attr @var{name} @var{value})
4949@var{name} is a string specifying the name of an attribute.
4950
4951@var{value} is a string that is either a valid value for attribute
4952@var{name}, a comma-separated list of values, or @samp{!} followed by a
4953value or list. If @var{value} does not begin with a @samp{!}, this
4954test is true if the value of the @var{name} attribute of the current
4955insn is in the list specified by @var{value}. If @var{value} begins
4956with a @samp{!}, this test is true if the attribute's value is
4957@emph{not} in the specified list.
4958
4959For example,
4960
4961@smallexample
4962(eq_attr "type" "load,store")
4963@end smallexample
4964
4965@noindent
4966is equivalent to
4967
4968@smallexample
4969(ior (eq_attr "type" "load") (eq_attr "type" "store"))
4970@end smallexample
4971
4972If @var{name} specifies an attribute of @samp{alternative}, it refers to the
4973value of the compiler variable @code{which_alternative}
4974(@pxref{Output Statement}) and the values must be small integers. For
bd819a4a 4975example,
03dda8e3
RK
4976
4977@smallexample
4978(eq_attr "alternative" "2,3")
4979@end smallexample
4980
4981@noindent
4982is equivalent to
4983
4984@smallexample
4985(ior (eq (symbol_ref "which_alternative") (const_int 2))
4986 (eq (symbol_ref "which_alternative") (const_int 3)))
4987@end smallexample
4988
4989Note that, for most attributes, an @code{eq_attr} test is simplified in cases
4990where the value of the attribute being tested is known for all insns matching
bd819a4a 4991a particular pattern. This is by far the most common case.
03dda8e3
RK
4992
4993@findex attr_flag
4994@item (attr_flag @var{name})
4995The value of an @code{attr_flag} expression is true if the flag
4996specified by @var{name} is true for the @code{insn} currently being
4997scheduled.
4998
4999@var{name} is a string specifying one of a fixed set of flags to test.
5000Test the flags @code{forward} and @code{backward} to determine the
5001direction of a conditional branch. Test the flags @code{very_likely},
5002@code{likely}, @code{very_unlikely}, and @code{unlikely} to determine
5003if a conditional branch is expected to be taken.
5004
5005If the @code{very_likely} flag is true, then the @code{likely} flag is also
5006true. Likewise for the @code{very_unlikely} and @code{unlikely} flags.
5007
5008This example describes a conditional branch delay slot which
5009can be nullified for forward branches that are taken (annul-true) or
5010for backward branches which are not taken (annul-false).
5011
5012@smallexample
5013(define_delay (eq_attr "type" "cbranch")
5014 [(eq_attr "in_branch_delay" "true")
5015 (and (eq_attr "in_branch_delay" "true")
5016 (attr_flag "forward"))
5017 (and (eq_attr "in_branch_delay" "true")
5018 (attr_flag "backward"))])
5019@end smallexample
5020
5021The @code{forward} and @code{backward} flags are false if the current
5022@code{insn} being scheduled is not a conditional branch.
5023
5024The @code{very_likely} and @code{likely} flags are true if the
5025@code{insn} being scheduled is not a conditional branch.
5026The @code{very_unlikely} and @code{unlikely} flags are false if the
5027@code{insn} being scheduled is not a conditional branch.
5028
5029@code{attr_flag} is only used during delay slot scheduling and has no
5030meaning to other passes of the compiler.
00bc45c1
RH
5031
5032@findex attr
5033@item (attr @var{name})
5034The value of another attribute is returned. This is most useful
5035for numeric attributes, as @code{eq_attr} and @code{attr_flag}
5036produce more efficient code for non-numeric attributes.
03dda8e3
RK
5037@end table
5038
5039@node Tagging Insns
5040@subsection Assigning Attribute Values to Insns
5041@cindex tagging insns
5042@cindex assigning attribute values to insns
5043
5044The value assigned to an attribute of an insn is primarily determined by
5045which pattern is matched by that insn (or which @code{define_peephole}
5046generated it). Every @code{define_insn} and @code{define_peephole} can
5047have an optional last argument to specify the values of attributes for
5048matching insns. The value of any attribute not specified in a particular
5049insn is set to the default value for that attribute, as specified in its
5050@code{define_attr}. Extensive use of default values for attributes
5051permits the specification of the values for only one or two attributes
5052in the definition of most insn patterns, as seen in the example in the
bd819a4a 5053next section.
03dda8e3
RK
5054
5055The optional last argument of @code{define_insn} and
5056@code{define_peephole} is a vector of expressions, each of which defines
5057the value for a single attribute. The most general way of assigning an
5058attribute's value is to use a @code{set} expression whose first operand is an
5059@code{attr} expression giving the name of the attribute being set. The
5060second operand of the @code{set} is an attribute expression
bd819a4a 5061(@pxref{Expressions}) giving the value of the attribute.
03dda8e3
RK
5062
5063When the attribute value depends on the @samp{alternative} attribute
5064(i.e., which is the applicable alternative in the constraint of the
5065insn), the @code{set_attr_alternative} expression can be used. It
5066allows the specification of a vector of attribute expressions, one for
5067each alternative.
5068
5069@findex set_attr
5070When the generality of arbitrary attribute expressions is not required,
5071the simpler @code{set_attr} expression can be used, which allows
5072specifying a string giving either a single attribute value or a list
5073of attribute values, one for each alternative.
5074
5075The form of each of the above specifications is shown below. In each case,
5076@var{name} is a string specifying the attribute to be set.
5077
5078@table @code
5079@item (set_attr @var{name} @var{value-string})
5080@var{value-string} is either a string giving the desired attribute value,
5081or a string containing a comma-separated list giving the values for
5082succeeding alternatives. The number of elements must match the number
5083of alternatives in the constraint of the insn pattern.
5084
5085Note that it may be useful to specify @samp{*} for some alternative, in
5086which case the attribute will assume its default value for insns matching
5087that alternative.
5088
5089@findex set_attr_alternative
5090@item (set_attr_alternative @var{name} [@var{value1} @var{value2} @dots{}])
5091Depending on the alternative of the insn, the value will be one of the
5092specified values. This is a shorthand for using a @code{cond} with
5093tests on the @samp{alternative} attribute.
5094
5095@findex attr
5096@item (set (attr @var{name}) @var{value})
5097The first operand of this @code{set} must be the special RTL expression
5098@code{attr}, whose sole operand is a string giving the name of the
5099attribute being set. @var{value} is the value of the attribute.
5100@end table
5101
5102The following shows three different ways of representing the same
5103attribute value specification:
5104
5105@smallexample
5106(set_attr "type" "load,store,arith")
5107
5108(set_attr_alternative "type"
5109 [(const_string "load") (const_string "store")
5110 (const_string "arith")])
5111
5112(set (attr "type")
5113 (cond [(eq_attr "alternative" "1") (const_string "load")
5114 (eq_attr "alternative" "2") (const_string "store")]
5115 (const_string "arith")))
5116@end smallexample
5117
5118@need 1000
5119@findex define_asm_attributes
5120The @code{define_asm_attributes} expression provides a mechanism to
5121specify the attributes assigned to insns produced from an @code{asm}
5122statement. It has the form:
5123
5124@smallexample
5125(define_asm_attributes [@var{attr-sets}])
5126@end smallexample
5127
5128@noindent
5129where @var{attr-sets} is specified the same as for both the
5130@code{define_insn} and the @code{define_peephole} expressions.
5131
5132These values will typically be the ``worst case'' attribute values. For
5133example, they might indicate that the condition code will be clobbered.
5134
5135A specification for a @code{length} attribute is handled specially. The
5136way to compute the length of an @code{asm} insn is to multiply the
5137length specified in the expression @code{define_asm_attributes} by the
5138number of machine instructions specified in the @code{asm} statement,
5139determined by counting the number of semicolons and newlines in the
5140string. Therefore, the value of the @code{length} attribute specified
5141in a @code{define_asm_attributes} should be the maximum possible length
5142of a single machine instruction.
5143
5144@node Attr Example
5145@subsection Example of Attribute Specifications
5146@cindex attribute specifications example
5147@cindex attribute specifications
5148
5149The judicious use of defaulting is important in the efficient use of
5150insn attributes. Typically, insns are divided into @dfn{types} and an
5151attribute, customarily called @code{type}, is used to represent this
5152value. This attribute is normally used only to define the default value
5153for other attributes. An example will clarify this usage.
5154
5155Assume we have a RISC machine with a condition code and in which only
5156full-word operations are performed in registers. Let us assume that we
5157can divide all insns into loads, stores, (integer) arithmetic
5158operations, floating point operations, and branches.
5159
5160Here we will concern ourselves with determining the effect of an insn on
5161the condition code and will limit ourselves to the following possible
5162effects: The condition code can be set unpredictably (clobbered), not
5163be changed, be set to agree with the results of the operation, or only
5164changed if the item previously set into the condition code has been
5165modified.
5166
5167Here is part of a sample @file{md} file for such a machine:
5168
5169@smallexample
5170(define_attr "type" "load,store,arith,fp,branch" (const_string "arith"))
5171
5172(define_attr "cc" "clobber,unchanged,set,change0"
5173 (cond [(eq_attr "type" "load")
5174 (const_string "change0")
5175 (eq_attr "type" "store,branch")
5176 (const_string "unchanged")
5177 (eq_attr "type" "arith")
5178 (if_then_else (match_operand:SI 0 "" "")
5179 (const_string "set")
5180 (const_string "clobber"))]
5181 (const_string "clobber")))
5182
5183(define_insn ""
5184 [(set (match_operand:SI 0 "general_operand" "=r,r,m")
5185 (match_operand:SI 1 "general_operand" "r,m,r"))]
5186 ""
5187 "@@
5188 move %0,%1
5189 load %0,%1
5190 store %0,%1"
5191 [(set_attr "type" "arith,load,store")])
5192@end smallexample
5193
5194Note that we assume in the above example that arithmetic operations
5195performed on quantities smaller than a machine word clobber the condition
5196code since they will set the condition code to a value corresponding to the
5197full-word result.
5198
5199@node Insn Lengths
5200@subsection Computing the Length of an Insn
5201@cindex insn lengths, computing
5202@cindex computing the length of an insn
5203
5204For many machines, multiple types of branch instructions are provided, each
5205for different length branch displacements. In most cases, the assembler
5206will choose the correct instruction to use. However, when the assembler
5207cannot do so, GCC can when a special attribute, the @samp{length}
5208attribute, is defined. This attribute must be defined to have numeric
5209values by specifying a null string in its @code{define_attr}.
5210
5211In the case of the @samp{length} attribute, two additional forms of
5212arithmetic terms are allowed in test expressions:
5213
5214@table @code
5215@cindex @code{match_dup} and attributes
5216@item (match_dup @var{n})
5217This refers to the address of operand @var{n} of the current insn, which
5218must be a @code{label_ref}.
5219
5220@cindex @code{pc} and attributes
5221@item (pc)
5222This refers to the address of the @emph{current} insn. It might have
5223been more consistent with other usage to make this the address of the
5224@emph{next} insn but this would be confusing because the length of the
5225current insn is to be computed.
5226@end table
5227
5228@cindex @code{addr_vec}, length of
5229@cindex @code{addr_diff_vec}, length of
5230For normal insns, the length will be determined by value of the
5231@samp{length} attribute. In the case of @code{addr_vec} and
5232@code{addr_diff_vec} insn patterns, the length is computed as
5233the number of vectors multiplied by the size of each vector.
5234
5235Lengths are measured in addressable storage units (bytes).
5236
5237The following macros can be used to refine the length computation:
5238
5239@table @code
5240@findex FIRST_INSN_ADDRESS
5241@item FIRST_INSN_ADDRESS
5242When the @code{length} insn attribute is used, this macro specifies the
5243value to be assigned to the address of the first insn in a function. If
5244not specified, 0 is used.
5245
5246@findex ADJUST_INSN_LENGTH
5247@item ADJUST_INSN_LENGTH (@var{insn}, @var{length})
5248If defined, modifies the length assigned to instruction @var{insn} as a
5249function of the context in which it is used. @var{length} is an lvalue
5250that contains the initially computed length of the insn and should be
a8aa4e0b 5251updated with the correct length of the insn.
03dda8e3
RK
5252
5253This macro will normally not be required. A case in which it is
161d7b59 5254required is the ROMP@. On this machine, the size of an @code{addr_vec}
03dda8e3
RK
5255insn must be increased by two to compensate for the fact that alignment
5256may be required.
5257@end table
5258
5259@findex get_attr_length
5260The routine that returns @code{get_attr_length} (the value of the
5261@code{length} attribute) can be used by the output routine to
5262determine the form of the branch instruction to be written, as the
5263example below illustrates.
5264
5265As an example of the specification of variable-length branches, consider
5266the IBM 360. If we adopt the convention that a register will be set to
5267the starting address of a function, we can jump to labels within 4k of
5268the start using a four-byte instruction. Otherwise, we need a six-byte
5269sequence to load the address from memory and then branch to it.
5270
5271On such a machine, a pattern for a branch instruction might be specified
5272as follows:
5273
5274@smallexample
5275(define_insn "jump"
5276 [(set (pc)
5277 (label_ref (match_operand 0 "" "")))]
5278 ""
03dda8e3
RK
5279@{
5280 return (get_attr_length (insn) == 4
0f40f9f7
ZW
5281 ? "b %l0" : "l r15,=a(%l0); br r15");
5282@}
9c34dbbf
ZW
5283 [(set (attr "length")
5284 (if_then_else (lt (match_dup 0) (const_int 4096))
5285 (const_int 4)
5286 (const_int 6)))])
03dda8e3
RK
5287@end smallexample
5288
5289@node Constant Attributes
5290@subsection Constant Attributes
5291@cindex constant attributes
5292
5293A special form of @code{define_attr}, where the expression for the
5294default value is a @code{const} expression, indicates an attribute that
5295is constant for a given run of the compiler. Constant attributes may be
5296used to specify which variety of processor is used. For example,
5297
5298@smallexample
5299(define_attr "cpu" "m88100,m88110,m88000"
5300 (const
5301 (cond [(symbol_ref "TARGET_88100") (const_string "m88100")
5302 (symbol_ref "TARGET_88110") (const_string "m88110")]
5303 (const_string "m88000"))))
5304
5305(define_attr "memory" "fast,slow"
5306 (const
5307 (if_then_else (symbol_ref "TARGET_FAST_MEM")
5308 (const_string "fast")
5309 (const_string "slow"))))
5310@end smallexample
5311
5312The routine generated for constant attributes has no parameters as it
5313does not depend on any particular insn. RTL expressions used to define
5314the value of a constant attribute may use the @code{symbol_ref} form,
5315but may not use either the @code{match_operand} form or @code{eq_attr}
5316forms involving insn attributes.
5317
5318@node Delay Slots
5319@subsection Delay Slot Scheduling
5320@cindex delay slots, defining
5321
5322The insn attribute mechanism can be used to specify the requirements for
5323delay slots, if any, on a target machine. An instruction is said to
5324require a @dfn{delay slot} if some instructions that are physically
5325after the instruction are executed as if they were located before it.
5326Classic examples are branch and call instructions, which often execute
5327the following instruction before the branch or call is performed.
5328
5329On some machines, conditional branch instructions can optionally
5330@dfn{annul} instructions in the delay slot. This means that the
5331instruction will not be executed for certain branch outcomes. Both
5332instructions that annul if the branch is true and instructions that
5333annul if the branch is false are supported.
5334
5335Delay slot scheduling differs from instruction scheduling in that
5336determining whether an instruction needs a delay slot is dependent only
5337on the type of instruction being generated, not on data flow between the
5338instructions. See the next section for a discussion of data-dependent
5339instruction scheduling.
5340
5341@findex define_delay
5342The requirement of an insn needing one or more delay slots is indicated
5343via the @code{define_delay} expression. It has the following form:
5344
5345@smallexample
5346(define_delay @var{test}
5347 [@var{delay-1} @var{annul-true-1} @var{annul-false-1}
5348 @var{delay-2} @var{annul-true-2} @var{annul-false-2}
5349 @dots{}])
5350@end smallexample
5351
5352@var{test} is an attribute test that indicates whether this
5353@code{define_delay} applies to a particular insn. If so, the number of
5354required delay slots is determined by the length of the vector specified
5355as the second argument. An insn placed in delay slot @var{n} must
5356satisfy attribute test @var{delay-n}. @var{annul-true-n} is an
5357attribute test that specifies which insns may be annulled if the branch
5358is true. Similarly, @var{annul-false-n} specifies which insns in the
5359delay slot may be annulled if the branch is false. If annulling is not
bd819a4a 5360supported for that delay slot, @code{(nil)} should be coded.
03dda8e3
RK
5361
5362For example, in the common case where branch and call insns require
5363a single delay slot, which may contain any insn other than a branch or
5364call, the following would be placed in the @file{md} file:
5365
5366@smallexample
5367(define_delay (eq_attr "type" "branch,call")
5368 [(eq_attr "type" "!branch,call") (nil) (nil)])
5369@end smallexample
5370
5371Multiple @code{define_delay} expressions may be specified. In this
5372case, each such expression specifies different delay slot requirements
5373and there must be no insn for which tests in two @code{define_delay}
5374expressions are both true.
5375
5376For example, if we have a machine that requires one delay slot for branches
5377but two for calls, no delay slot can contain a branch or call insn,
5378and any valid insn in the delay slot for the branch can be annulled if the
5379branch is true, we might represent this as follows:
5380
5381@smallexample
5382(define_delay (eq_attr "type" "branch")
5383 [(eq_attr "type" "!branch,call")
5384 (eq_attr "type" "!branch,call")
5385 (nil)])
5386
5387(define_delay (eq_attr "type" "call")
5388 [(eq_attr "type" "!branch,call") (nil) (nil)
5389 (eq_attr "type" "!branch,call") (nil) (nil)])
5390@end smallexample
5391@c the above is *still* too long. --mew 4feb93
5392
fae15c93
VM
5393@node Processor pipeline description
5394@subsection Specifying processor pipeline description
5395@cindex processor pipeline description
5396@cindex processor functional units
5397@cindex instruction latency time
5398@cindex interlock delays
5399@cindex data dependence delays
5400@cindex reservation delays
5401@cindex pipeline hazard recognizer
5402@cindex automaton based pipeline description
5403@cindex regular expressions
5404@cindex deterministic finite state automaton
5405@cindex automaton based scheduler
5406@cindex RISC
5407@cindex VLIW
5408
ef261fee 5409To achieve better performance, most modern processors
fae15c93
VM
5410(super-pipelined, superscalar @acronym{RISC}, and @acronym{VLIW}
5411processors) have many @dfn{functional units} on which several
5412instructions can be executed simultaneously. An instruction starts
5413execution if its issue conditions are satisfied. If not, the
ef261fee 5414instruction is stalled until its conditions are satisfied. Such
fae15c93
VM
5415@dfn{interlock (pipeline) delay} causes interruption of the fetching
5416of successor instructions (or demands nop instructions, e.g. for some
5417MIPS processors).
5418
5419There are two major kinds of interlock delays in modern processors.
5420The first one is a data dependence delay determining @dfn{instruction
5421latency time}. The instruction execution is not started until all
5422source data have been evaluated by prior instructions (there are more
5423complex cases when the instruction execution starts even when the data
c0478a66 5424are not available but will be ready in given time after the
fae15c93
VM
5425instruction execution start). Taking the data dependence delays into
5426account is simple. The data dependence (true, output, and
5427anti-dependence) delay between two instructions is given by a
5428constant. In most cases this approach is adequate. The second kind
5429of interlock delays is a reservation delay. The reservation delay
5430means that two instructions under execution will be in need of shared
5431processors resources, i.e. buses, internal registers, and/or
5432functional units, which are reserved for some time. Taking this kind
5433of delay into account is complex especially for modern @acronym{RISC}
5434processors.
5435
5436The task of exploiting more processor parallelism is solved by an
ef261fee 5437instruction scheduler. For a better solution to this problem, the
fae15c93 5438instruction scheduler has to have an adequate description of the
ef261fee
R
5439processor parallelism (or @dfn{pipeline description}). Currently GCC
5440provides two alternative ways to describe processor parallelism,
5441both described below. The first method is outlined in the next section;
5442it was once the only method provided by GCC, and thus is used in a number
5443of exiting ports. The second, and preferred method, specifies functional
5444unit reservations for groups of instructions with the aid of @dfn{regular
5445expressions}. This is called the @dfn{automaton based description}.
5446
5447The GCC instruction scheduler uses a @dfn{pipeline hazard recognizer} to
fae15c93 5448figure out the possibility of the instruction issue by the processor
ef261fee
R
5449on a given simulated processor cycle. The pipeline hazard recognizer is
5450automatically generated from the processor pipeline description. The
fae15c93 5451pipeline hazard recognizer generated from the automaton based
ef261fee 5452description is more sophisticated and based on a deterministic finite
fae15c93 5453state automaton (@acronym{DFA}) and therefore faster than one
ef261fee
R
5454generated from the old description. Furthermore, its speed is not dependent
5455on processor complexity. The instruction issue is possible if there is
fae15c93
VM
5456a transition from one automaton state to another one.
5457
cc6a602b
BE
5458You can use either model to describe processor pipeline
5459characteristics or even mix them. You could use the old description
5460for some processor submodels and the @acronym{DFA}-based one for other
fae15c93
VM
5461processor submodels.
5462
cc6a602b
BE
5463In general, using the automaton based description is preferred. Its
5464model is richer and makes it possible to more accurately describe
5465pipeline characteristics of processors, which results in improved
5466code quality (although sometimes only marginally). It will also be
5467used as an infrastructure to implement sophisticated and practical
5468instruction scheduling which will try many instruction sequences to
5469choose the best one.
fae15c93
VM
5470
5471
5472@menu
5473* Old pipeline description:: Specifying information for insn scheduling.
5474* Automaton pipeline description:: Describing insn pipeline characteristics.
5475* Comparison of the two descriptions:: Drawbacks of the old pipeline description
5476@end menu
5477
5478@node Old pipeline description
5479@subsubsection Specifying Function Units
5480@cindex old pipeline description
03dda8e3
RK
5481@cindex function units, for scheduling
5482
fae15c93
VM
5483On most @acronym{RISC} machines, there are instructions whose results
5484are not available for a specific number of cycles. Common cases are
5485instructions that load data from memory. On many machines, a pipeline
5486stall will result if the data is referenced too soon after the load
5487instruction.
03dda8e3
RK
5488
5489In addition, many newer microprocessors have multiple function units, usually
5490one for integer and one for floating point, and often will incur pipeline
5491stalls when a result that is needed is not yet ready.
5492
5493The descriptions in this section allow the specification of how much
5494time must elapse between the execution of an instruction and the time
5495when its result is used. It also allows specification of when the
5496execution of an instruction will delay execution of similar instructions
5497due to function unit conflicts.
5498
5499For the purposes of the specifications in this section, a machine is
5500divided into @dfn{function units}, each of which execute a specific
fae15c93
VM
5501class of instructions in first-in-first-out order. Function units
5502that accept one instruction each cycle and allow a result to be used
5503in the succeeding instruction (usually via forwarding) need not be
5504specified. Classic @acronym{RISC} microprocessors will normally have
5505a single function unit, which we can call @samp{memory}. The newer
5506``superscalar'' processors will often have function units for floating
5507point operations, usually at least a floating point adder and
5508multiplier.
03dda8e3
RK
5509
5510@findex define_function_unit
5511Each usage of a function units by a class of insns is specified with a
5512@code{define_function_unit} expression, which looks like this:
5513
5514@smallexample
5515(define_function_unit @var{name} @var{multiplicity} @var{simultaneity}
5516 @var{test} @var{ready-delay} @var{issue-delay}
5517 [@var{conflict-list}])
5518@end smallexample
5519
5520@var{name} is a string giving the name of the function unit.
5521
5522@var{multiplicity} is an integer specifying the number of identical
5523units in the processor. If more than one unit is specified, they will
5524be scheduled independently. Only truly independent units should be
5525counted; a pipelined unit should be specified as a single unit. (The
5526only common example of a machine that has multiple function units for a
5527single instruction class that are truly independent and not pipelined
5528are the two multiply and two increment units of the CDC 6600.)
5529
5530@var{simultaneity} specifies the maximum number of insns that can be
5531executing in each instance of the function unit simultaneously or zero
5532if the unit is pipelined and has no limit.
5533
5534All @code{define_function_unit} definitions referring to function unit
5535@var{name} must have the same name and values for @var{multiplicity} and
5536@var{simultaneity}.
5537
5538@var{test} is an attribute test that selects the insns we are describing
5539in this definition. Note that an insn may use more than one function
5540unit and a function unit may be specified in more than one
5541@code{define_function_unit}.
5542
5543@var{ready-delay} is an integer that specifies the number of cycles
5544after which the result of the instruction can be used without
5545introducing any stalls.
5546
5547@var{issue-delay} is an integer that specifies the number of cycles
5548after the instruction matching the @var{test} expression begins using
5549this unit until a subsequent instruction can begin. A cost of @var{N}
5550indicates an @var{N-1} cycle delay. A subsequent instruction may also
5551be delayed if an earlier instruction has a longer @var{ready-delay}
5552value. This blocking effect is computed using the @var{simultaneity},
5553@var{ready-delay}, @var{issue-delay}, and @var{conflict-list} terms.
5554For a normal non-pipelined function unit, @var{simultaneity} is one, the
5555unit is taken to block for the @var{ready-delay} cycles of the executing
5556insn, and smaller values of @var{issue-delay} are ignored.
5557
5558@var{conflict-list} is an optional list giving detailed conflict costs
5559for this unit. If specified, it is a list of condition test expressions
5560to be applied to insns chosen to execute in @var{name} following the
5561particular insn matching @var{test} that is already executing in
5562@var{name}. For each insn in the list, @var{issue-delay} specifies the
5563conflict cost; for insns not in the list, the cost is zero. If not
5564specified, @var{conflict-list} defaults to all instructions that use the
5565function unit.
5566
5567Typical uses of this vector are where a floating point function unit can
5568pipeline either single- or double-precision operations, but not both, or
5569where a memory unit can pipeline loads, but not stores, etc.
5570
fae15c93
VM
5571As an example, consider a classic @acronym{RISC} machine where the
5572result of a load instruction is not available for two cycles (a single
5573``delay'' instruction is required) and where only one load instruction
5574can be executed simultaneously. This would be specified as:
03dda8e3
RK
5575
5576@smallexample
5577(define_function_unit "memory" 1 1 (eq_attr "type" "load") 2 0)
5578@end smallexample
5579
5580For the case of a floating point function unit that can pipeline either
5581single or double precision, but not both, the following could be specified:
5582
5583@smallexample
5584(define_function_unit
5585 "fp" 1 0 (eq_attr "type" "sp_fp") 4 4 [(eq_attr "type" "dp_fp")])
5586(define_function_unit
5587 "fp" 1 0 (eq_attr "type" "dp_fp") 4 4 [(eq_attr "type" "sp_fp")])
5588@end smallexample
5589
5590@strong{Note:} The scheduler attempts to avoid function unit conflicts
5591and uses all the specifications in the @code{define_function_unit}
5592expression. It has recently come to our attention that these
5593specifications may not allow modeling of some of the newer
5594``superscalar'' processors that have insns using multiple pipelined
5595units. These insns will cause a potential conflict for the second unit
5596used during their execution and there is no way of representing that
5597conflict. We welcome any examples of how function unit conflicts work
5598in such processors and suggestions for their representation.
3262c1f5 5599
fae15c93
VM
5600@node Automaton pipeline description
5601@subsubsection Describing instruction pipeline characteristics
5602@cindex automaton based pipeline description
5603
5604This section describes constructions of the automaton based processor
c62347f0
BE
5605pipeline description. The order of constructions within the machine
5606description file is not important.
fae15c93
VM
5607
5608@findex define_automaton
5609@cindex pipeline hazard recognizer
5610The following optional construction describes names of automata
5611generated and used for the pipeline hazards recognition. Sometimes
5612the generated finite state automaton used by the pipeline hazard
ef261fee 5613recognizer is large. If we use more than one automaton and bind functional
c62347f0 5614units to the automata, the total size of the automata is usually
fae15c93
VM
5615less than the size of the single automaton. If there is no one such
5616construction, only one finite state automaton is generated.
5617
5618@smallexample
5619(define_automaton @var{automata-names})
5620@end smallexample
5621
5622@var{automata-names} is a string giving names of the automata. The
5623names are separated by commas. All the automata should have unique names.
c62347f0 5624The automaton name is used in the constructions @code{define_cpu_unit} and
fae15c93
VM
5625@code{define_query_cpu_unit}.
5626
5627@findex define_cpu_unit
5628@cindex processor functional units
c62347f0 5629Each processor functional unit used in the description of instruction
fae15c93
VM
5630reservations should be described by the following construction.
5631
5632@smallexample
5633(define_cpu_unit @var{unit-names} [@var{automaton-name}])
5634@end smallexample
5635
5636@var{unit-names} is a string giving the names of the functional units
5637separated by commas. Don't use name @samp{nothing}, it is reserved
5638for other goals.
5639
ef261fee 5640@var{automaton-name} is a string giving the name of the automaton with
fae15c93
VM
5641which the unit is bound. The automaton should be described in
5642construction @code{define_automaton}. You should give
5643@dfn{automaton-name}, if there is a defined automaton.
5644
30028c85
VM
5645The assignment of units to automata are constrained by the uses of the
5646units in insn reservations. The most important constraint is: if a
5647unit reservation is present on a particular cycle of an alternative
5648for an insn reservation, then some unit from the same automaton must
5649be present on the same cycle for the other alternatives of the insn
5650reservation. The rest of the constraints are mentioned in the
5651description of the subsequent constructions.
5652
fae15c93
VM
5653@findex define_query_cpu_unit
5654@cindex querying function unit reservations
5655The following construction describes CPU functional units analogously
30028c85
VM
5656to @code{define_cpu_unit}. The reservation of such units can be
5657queried for an automaton state. The instruction scheduler never
5658queries reservation of functional units for given automaton state. So
5659as a rule, you don't need this construction. This construction could
5660be used for future code generation goals (e.g. to generate
5661@acronym{VLIW} insn templates).
fae15c93
VM
5662
5663@smallexample
5664(define_query_cpu_unit @var{unit-names} [@var{automaton-name}])
5665@end smallexample
5666
5667@var{unit-names} is a string giving names of the functional units
5668separated by commas.
5669
ef261fee 5670@var{automaton-name} is a string giving the name of the automaton with
fae15c93
VM
5671which the unit is bound.
5672
5673@findex define_insn_reservation
5674@cindex instruction latency time
5675@cindex regular expressions
5676@cindex data bypass
ef261fee 5677The following construction is the major one to describe pipeline
fae15c93
VM
5678characteristics of an instruction.
5679
5680@smallexample
5681(define_insn_reservation @var{insn-name} @var{default_latency}
5682 @var{condition} @var{regexp})
5683@end smallexample
5684
5685@var{default_latency} is a number giving latency time of the
5686instruction. There is an important difference between the old
5687description and the automaton based pipeline description. The latency
5688time is used for all dependencies when we use the old description. In
ef261fee
R
5689the automaton based pipeline description, the given latency time is only
5690used for true dependencies. The cost of anti-dependencies is always
fae15c93
VM
5691zero and the cost of output dependencies is the difference between
5692latency times of the producing and consuming insns (if the difference
ef261fee
R
5693is negative, the cost is considered to be zero). You can always
5694change the default costs for any description by using the target hook
fae15c93
VM
5695@code{TARGET_SCHED_ADJUST_COST} (@pxref{Scheduling}).
5696
cc6a602b 5697@var{insn-name} is a string giving the internal name of the insn. The
fae15c93
VM
5698internal names are used in constructions @code{define_bypass} and in
5699the automaton description file generated for debugging. The internal
ef261fee 5700name has nothing in common with the names in @code{define_insn}. It is a
fae15c93
VM
5701good practice to use insn classes described in the processor manual.
5702
5703@var{condition} defines what RTL insns are described by this
5704construction. You should remember that you will be in trouble if
5705@var{condition} for two or more different
5706@code{define_insn_reservation} constructions is TRUE for an insn. In
5707this case what reservation will be used for the insn is not defined.
5708Such cases are not checked during generation of the pipeline hazards
5709recognizer because in general recognizing that two conditions may have
5710the same value is quite difficult (especially if the conditions
5711contain @code{symbol_ref}). It is also not checked during the
5712pipeline hazard recognizer work because it would slow down the
5713recognizer considerably.
5714
ef261fee 5715@var{regexp} is a string describing the reservation of the cpu's functional
fae15c93
VM
5716units by the instruction. The reservations are described by a regular
5717expression according to the following syntax:
5718
5719@smallexample
5720 regexp = regexp "," oneof
5721 | oneof
5722
5723 oneof = oneof "|" allof
5724 | allof
5725
5726 allof = allof "+" repeat
5727 | repeat
5728
5729 repeat = element "*" number
5730 | element
5731
5732 element = cpu_function_unit_name
5733 | reservation_name
5734 | result_name
5735 | "nothing"
5736 | "(" regexp ")"
5737@end smallexample
5738
5739@itemize @bullet
5740@item
5741@samp{,} is used for describing the start of the next cycle in
5742the reservation.
5743
5744@item
5745@samp{|} is used for describing a reservation described by the first
5746regular expression @strong{or} a reservation described by the second
5747regular expression @strong{or} etc.
5748
5749@item
5750@samp{+} is used for describing a reservation described by the first
5751regular expression @strong{and} a reservation described by the
5752second regular expression @strong{and} etc.
5753
5754@item
5755@samp{*} is used for convenience and simply means a sequence in which
5756the regular expression are repeated @var{number} times with cycle
5757advancing (see @samp{,}).
5758
5759@item
5760@samp{cpu_function_unit_name} denotes reservation of the named
5761functional unit.
5762
5763@item
5764@samp{reservation_name} --- see description of construction
5765@samp{define_reservation}.
5766
5767@item
5768@samp{nothing} denotes no unit reservations.
5769@end itemize
5770
5771@findex define_reservation
5772Sometimes unit reservations for different insns contain common parts.
5773In such case, you can simplify the pipeline description by describing
5774the common part by the following construction
5775
5776@smallexample
5777(define_reservation @var{reservation-name} @var{regexp})
5778@end smallexample
5779
5780@var{reservation-name} is a string giving name of @var{regexp}.
5781Functional unit names and reservation names are in the same name
5782space. So the reservation names should be different from the
cc6a602b 5783functional unit names and can not be the reserved name @samp{nothing}.
fae15c93
VM
5784
5785@findex define_bypass
5786@cindex instruction latency time
5787@cindex data bypass
5788The following construction is used to describe exceptions in the
5789latency time for given instruction pair. This is so called bypasses.
5790
5791@smallexample
5792(define_bypass @var{number} @var{out_insn_names} @var{in_insn_names}
5793 [@var{guard}])
5794@end smallexample
5795
5796@var{number} defines when the result generated by the instructions
5797given in string @var{out_insn_names} will be ready for the
5798instructions given in string @var{in_insn_names}. The instructions in
5799the string are separated by commas.
5800
ef261fee 5801@var{guard} is an optional string giving the name of a C function which
fae15c93
VM
5802defines an additional guard for the bypass. The function will get the
5803two insns as parameters. If the function returns zero the bypass will
5804be ignored for this case. The additional guard is necessary to
ef261fee 5805recognize complicated bypasses, e.g. when the consumer is only an address
fae15c93
VM
5806of insn @samp{store} (not a stored value).
5807
5808@findex exclusion_set
5809@findex presence_set
30028c85 5810@findex final_presence_set
fae15c93 5811@findex absence_set
30028c85 5812@findex final_absence_set
fae15c93
VM
5813@cindex VLIW
5814@cindex RISC
cc6a602b
BE
5815The following five constructions are usually used to describe
5816@acronym{VLIW} processors, or more precisely, to describe a placement
5817of small instructions into @acronym{VLIW} instruction slots. They
5818can be used for @acronym{RISC} processors, too.
fae15c93
VM
5819
5820@smallexample
5821(exclusion_set @var{unit-names} @var{unit-names})
30028c85
VM
5822(presence_set @var{unit-names} @var{patterns})
5823(final_presence_set @var{unit-names} @var{patterns})
5824(absence_set @var{unit-names} @var{patterns})
5825(final_absence_set @var{unit-names} @var{patterns})
fae15c93
VM
5826@end smallexample
5827
5828@var{unit-names} is a string giving names of functional units
5829separated by commas.
5830
30028c85
VM
5831@var{patterns} is a string giving patterns of functional units
5832separated by comma. Currently pattern is is one unit or units
5833separated by white-spaces.
5834
fae15c93
VM
5835The first construction (@samp{exclusion_set}) means that each
5836functional unit in the first string can not be reserved simultaneously
5837with a unit whose name is in the second string and vice versa. For
5838example, the construction is useful for describing processors
5839(e.g. some SPARC processors) with a fully pipelined floating point
5840functional unit which can execute simultaneously only single floating
5841point insns or only double floating point insns.
5842
5843The second construction (@samp{presence_set}) means that each
5844functional unit in the first string can not be reserved unless at
30028c85
VM
5845least one of pattern of units whose names are in the second string is
5846reserved. This is an asymmetric relation. For example, it is useful
5847for description that @acronym{VLIW} @samp{slot1} is reserved after
5848@samp{slot0} reservation. We could describe it by the following
5849construction
5850
5851@smallexample
5852(presence_set "slot1" "slot0")
5853@end smallexample
5854
5855Or @samp{slot1} is reserved only after @samp{slot0} and unit @samp{b0}
5856reservation. In this case we could write
5857
5858@smallexample
5859(presence_set "slot1" "slot0 b0")
5860@end smallexample
5861
5862The third construction (@samp{final_presence_set}) is analogous to
5863@samp{presence_set}. The difference between them is when checking is
5864done. When an instruction is issued in given automaton state
5865reflecting all current and planned unit reservations, the automaton
5866state is changed. The first state is a source state, the second one
5867is a result state. Checking for @samp{presence_set} is done on the
5868source state reservation, checking for @samp{final_presence_set} is
5869done on the result reservation. This construction is useful to
5870describe a reservation which is actually two subsequent reservations.
5871For example, if we use
5872
5873@smallexample
5874(presence_set "slot1" "slot0")
5875@end smallexample
5876
5877the following insn will be never issued (because @samp{slot1} requires
5878@samp{slot0} which is absent in the source state).
5879
5880@smallexample
5881(define_reservation "insn_and_nop" "slot0 + slot1")
5882@end smallexample
5883
5884but it can be issued if we use analogous @samp{final_presence_set}.
5885
5886The forth construction (@samp{absence_set}) means that each functional
5887unit in the first string can be reserved only if each pattern of units
5888whose names are in the second string is not reserved. This is an
5889asymmetric relation (actually @samp{exclusion_set} is analogous to
5890this one but it is symmetric). For example, it is useful for
5891description that @acronym{VLIW} @samp{slot0} can not be reserved after
5892@samp{slot1} or @samp{slot2} reservation. We could describe it by the
5893following construction
5894
5895@smallexample
5896(absence_set "slot2" "slot0, slot1")
5897@end smallexample
5898
5899Or @samp{slot2} can not be reserved if @samp{slot0} and unit @samp{b0}
5900are reserved or @samp{slot1} and unit @samp{b1} are reserved. In
5901this case we could write
5902
5903@smallexample
5904(absence_set "slot2" "slot0 b0, slot1 b1")
5905@end smallexample
fae15c93 5906
ef261fee 5907All functional units mentioned in a set should belong to the same
fae15c93
VM
5908automaton.
5909
30028c85
VM
5910The last construction (@samp{final_absence_set}) is analogous to
5911@samp{absence_set} but checking is done on the result (state)
5912reservation. See comments for @samp{final_presence_set}.
5913
fae15c93
VM
5914@findex automata_option
5915@cindex deterministic finite state automaton
5916@cindex nondeterministic finite state automaton
5917@cindex finite state automaton minimization
5918You can control the generator of the pipeline hazard recognizer with
5919the following construction.
5920
5921@smallexample
5922(automata_option @var{options})
5923@end smallexample
5924
5925@var{options} is a string giving options which affect the generated
5926code. Currently there are the following options:
5927
5928@itemize @bullet
5929@item
5930@dfn{no-minimization} makes no minimization of the automaton. This is
30028c85
VM
5931only worth to do when we are debugging the description and need to
5932look more accurately at reservations of states.
fae15c93
VM
5933
5934@item
e3c8eb86
VM
5935@dfn{time} means printing additional time statistics about
5936generation of automata.
5937
5938@item
5939@dfn{v} means a generation of the file describing the result automata.
5940The file has suffix @samp{.dfa} and can be used for the description
5941verification and debugging.
5942
5943@item
5944@dfn{w} means a generation of warning instead of error for
5945non-critical errors.
fae15c93
VM
5946
5947@item
5948@dfn{ndfa} makes nondeterministic finite state automata. This affects
5949the treatment of operator @samp{|} in the regular expressions. The
5950usual treatment of the operator is to try the first alternative and,
5951if the reservation is not possible, the second alternative. The
5952nondeterministic treatment means trying all alternatives, some of them
5953may be rejected by reservations in the subsequent insns. You can not
5954query functional unit reservations in nondeterministic automaton
5955states.
5956@end itemize
5957
5958As an example, consider a superscalar @acronym{RISC} machine which can
5959issue three insns (two integer insns and one floating point insn) on
5960the cycle but can finish only two insns. To describe this, we define
5961the following functional units.
5962
5963@smallexample
5964(define_cpu_unit "i0_pipeline, i1_pipeline, f_pipeline")
ef261fee 5965(define_cpu_unit "port0, port1")
fae15c93
VM
5966@end smallexample
5967
5968All simple integer insns can be executed in any integer pipeline and
5969their result is ready in two cycles. The simple integer insns are
5970issued into the first pipeline unless it is reserved, otherwise they
5971are issued into the second pipeline. Integer division and
5972multiplication insns can be executed only in the second integer
5973pipeline and their results are ready correspondingly in 8 and 4
5974cycles. The integer division is not pipelined, i.e. the subsequent
5975integer division insn can not be issued until the current division
5976insn finished. Floating point insns are fully pipelined and their
ef261fee
R
5977results are ready in 3 cycles. Where the result of a floating point
5978insn is used by an integer insn, an additional delay of one cycle is
5979incurred. To describe all of this we could specify
fae15c93
VM
5980
5981@smallexample
5982(define_cpu_unit "div")
5983
68e4d4c5 5984(define_insn_reservation "simple" 2 (eq_attr "type" "int")
ef261fee 5985 "(i0_pipeline | i1_pipeline), (port0 | port1)")
fae15c93 5986
68e4d4c5 5987(define_insn_reservation "mult" 4 (eq_attr "type" "mult")
ef261fee 5988 "i1_pipeline, nothing*2, (port0 | port1)")
fae15c93 5989
68e4d4c5 5990(define_insn_reservation "div" 8 (eq_attr "type" "div")
ef261fee 5991 "i1_pipeline, div*7, div + (port0 | port1)")
fae15c93 5992
68e4d4c5 5993(define_insn_reservation "float" 3 (eq_attr "type" "float")
ef261fee 5994 "f_pipeline, nothing, (port0 | port1))
fae15c93 5995
ef261fee 5996(define_bypass 4 "float" "simple,mult,div")
fae15c93
VM
5997@end smallexample
5998
5999To simplify the description we could describe the following reservation
6000
6001@smallexample
6002(define_reservation "finish" "port0|port1")
6003@end smallexample
6004
6005and use it in all @code{define_insn_reservation} as in the following
6006construction
6007
6008@smallexample
68e4d4c5 6009(define_insn_reservation "simple" 2 (eq_attr "type" "int")
fae15c93
VM
6010 "(i0_pipeline | i1_pipeline), finish")
6011@end smallexample
6012
6013
6014@node Comparison of the two descriptions
6015@subsubsection Drawbacks of the old pipeline description
6016@cindex old pipeline description
6017@cindex automaton based pipeline description
6018@cindex processor functional units
6019@cindex interlock delays
6020@cindex instruction latency time
6021@cindex pipeline hazard recognizer
6022@cindex data bypass
6023
6024The old instruction level parallelism description and the pipeline
6025hazards recognizer based on it have the following drawbacks in
6026comparison with the @acronym{DFA}-based ones:
6027
6028@itemize @bullet
6029@item
6030Each functional unit is believed to be reserved at the instruction
6031execution start. This is a very inaccurate model for modern
6032processors.
6033
6034@item
6035An inadequate description of instruction latency times. The latency
6036time is bound with a functional unit reserved by an instruction not
6037with the instruction itself. In other words, the description is
6038oriented to describe at most one unit reservation by each instruction.
6039It also does not permit to describe special bypasses between
6040instruction pairs.
6041
6042@item
6043The implementation of the pipeline hazard recognizer interface has
6044constraints on number of functional units. This is a number of bits
6045in integer on the host machine.
6046
6047@item
6048The interface to the pipeline hazard recognizer is more complex than
6049one to the automaton based pipeline recognizer.
6050
6051@item
ef261fee 6052An unnatural description when you write a unit and a condition which
fae15c93
VM
6053selects instructions using the unit. Writing all unit reservations
6054for an instruction (an instruction class) is more natural.
6055
6056@item
ef261fee 6057The recognition of the interlock delays has a slow implementation. The GCC
fae15c93 6058scheduler supports structures which describe the unit reservations.
ef261fee
R
6059The more functional units a processor has, the slower its pipeline hazard
6060recognizer will be. Such an implementation would become even slower when we
6061allowed to
fae15c93 6062reserve functional units not only at the instruction execution start.
ef261fee 6063In an automaton based pipeline hazard recognizer, speed is not dependent
fae15c93
VM
6064on processor complexity.
6065@end itemize
6066
3262c1f5
RH
6067@node Conditional Execution
6068@section Conditional Execution
6069@cindex conditional execution
6070@cindex predication
6071
6072A number of architectures provide for some form of conditional
6073execution, or predication. The hallmark of this feature is the
6074ability to nullify most of the instructions in the instruction set.
6075When the instruction set is large and not entirely symmetric, it
6076can be quite tedious to describe these forms directly in the
6077@file{.md} file. An alternative is the @code{define_cond_exec} template.
6078
6079@findex define_cond_exec
6080@smallexample
6081(define_cond_exec
6082 [@var{predicate-pattern}]
6083 "@var{condition}"
630d3d5a 6084 "@var{output-template}")
3262c1f5
RH
6085@end smallexample
6086
6087@var{predicate-pattern} is the condition that must be true for the
6088insn to be executed at runtime and should match a relational operator.
6089One can use @code{match_operator} to match several relational operators
6090at once. Any @code{match_operand} operands must have no more than one
6091alternative.
6092
6093@var{condition} is a C expression that must be true for the generated
6094pattern to match.
6095
6096@findex current_insn_predicate
630d3d5a 6097@var{output-template} is a string similar to the @code{define_insn}
3262c1f5
RH
6098output template (@pxref{Output Template}), except that the @samp{*}
6099and @samp{@@} special cases do not apply. This is only useful if the
6100assembly text for the predicate is a simple prefix to the main insn.
6101In order to handle the general case, there is a global variable
6102@code{current_insn_predicate} that will contain the entire predicate
6103if the current insn is predicated, and will otherwise be @code{NULL}.
6104
ebb48a4d
JM
6105When @code{define_cond_exec} is used, an implicit reference to
6106the @code{predicable} instruction attribute is made.
e979f9e8 6107@xref{Insn Attributes}. This attribute must be boolean (i.e.@: have
3262c1f5
RH
6108exactly two elements in its @var{list-of-values}). Further, it must
6109not be used with complex expressions. That is, the default and all
ebb48a4d 6110uses in the insns must be a simple constant, not dependent on the
3262c1f5
RH
6111alternative or anything else.
6112
ebb48a4d 6113For each @code{define_insn} for which the @code{predicable}
3262c1f5
RH
6114attribute is true, a new @code{define_insn} pattern will be
6115generated that matches a predicated version of the instruction.
6116For example,
6117
6118@smallexample
6119(define_insn "addsi"
6120 [(set (match_operand:SI 0 "register_operand" "r")
6121 (plus:SI (match_operand:SI 1 "register_operand" "r")
6122 (match_operand:SI 2 "register_operand" "r")))]
6123 "@var{test1}"
6124 "add %2,%1,%0")
6125
6126(define_cond_exec
6127 [(ne (match_operand:CC 0 "register_operand" "c")
6128 (const_int 0))]
6129 "@var{test2}"
6130 "(%0)")
6131@end smallexample
6132
6133@noindent
6134generates a new pattern
6135
6136@smallexample
6137(define_insn ""
6138 [(cond_exec
6139 (ne (match_operand:CC 3 "register_operand" "c") (const_int 0))
6140 (set (match_operand:SI 0 "register_operand" "r")
6141 (plus:SI (match_operand:SI 1 "register_operand" "r")
6142 (match_operand:SI 2 "register_operand" "r"))))]
6143 "(@var{test2}) && (@var{test1})"
6144 "(%3) add %2,%1,%0")
6145@end smallexample
c25c12b8
R
6146
6147@node Constant Definitions
6148@section Constant Definitions
6149@cindex constant definitions
6150@findex define_constants
6151
6152Using literal constants inside instruction patterns reduces legibility and
6153can be a maintenance problem.
6154
6155To overcome this problem, you may use the @code{define_constants}
6156expression. It contains a vector of name-value pairs. From that
6157point on, wherever any of the names appears in the MD file, it is as
6158if the corresponding value had been written instead. You may use
6159@code{define_constants} multiple times; each appearance adds more
6160constants to the table. It is an error to redefine a constant with
6161a different value.
6162
6163To come back to the a29k load multiple example, instead of
6164
6165@smallexample
6166(define_insn ""
6167 [(match_parallel 0 "load_multiple_operation"
6168 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
6169 (match_operand:SI 2 "memory_operand" "m"))
6170 (use (reg:SI 179))
6171 (clobber (reg:SI 179))])]
6172 ""
6173 "loadm 0,0,%1,%2")
6174@end smallexample
6175
6176You could write:
6177
6178@smallexample
6179(define_constants [
6180 (R_BP 177)
6181 (R_FC 178)
6182 (R_CR 179)
6183 (R_Q 180)
6184])
6185
6186(define_insn ""
6187 [(match_parallel 0 "load_multiple_operation"
6188 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
6189 (match_operand:SI 2 "memory_operand" "m"))
6190 (use (reg:SI R_CR))
6191 (clobber (reg:SI R_CR))])]
6192 ""
6193 "loadm 0,0,%1,%2")
6194@end smallexample
6195
6196The constants that are defined with a define_constant are also output
6197in the insn-codes.h header file as #defines.
b11cc610 6198@end ifset
This page took 2.368777 seconds and 5 git commands to generate.