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