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