]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/gccint/machine-descriptions/example-of-defineinsn.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / doc / gccint / machine-descriptions / example-of-defineinsn.rst
1 ..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6 .. index:: define_insn example
7
8 .. _example:
9
10 Example of define_insn
11 **********************
12
13 Here is an example of an instruction pattern, taken from the machine
14 description for the 68000/68020.
15
16 .. code-block::
17
18 (define_insn "tstsi"
19 [(set (cc0)
20 (match_operand:SI 0 "general_operand" "rm"))]
21 ""
22 "*
23 {
24 if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
25 return \"tstl %0\";
26 return \"cmpl #0,%0\";
27 }")
28
29 This can also be written using braced strings:
30
31 .. code-block::
32
33 (define_insn "tstsi"
34 [(set (cc0)
35 (match_operand:SI 0 "general_operand" "rm"))]
36 ""
37 {
38 if (TARGET_68020 || ! ADDRESS_REG_P (operands[0]))
39 return "tstl %0";
40 return "cmpl #0,%0";
41 })
42
43 This describes an instruction which sets the condition codes based on the
44 value of a general operand. It has no condition, so any insn with an RTL
45 description of the form shown may be matched to this pattern. The name
46 :samp:`tstsi` means 'test a ``SImode`` value' and tells the RTL
47 generation pass that, when it is necessary to test such a value, an insn
48 to do so can be constructed using this pattern.
49
50 The output control string is a piece of C code which chooses which
51 output template to return based on the kind of operand and the specific
52 type of CPU for which code is being generated.
53
54 :samp:`"rm"` is an operand constraint. Its meaning is explained below.