Movatterモバイル変換


[0]ホーム

URL:


Next:, Previous:, Up:Instruction Attributes   [Contents][Index]


16.20.5 Computing the Length of an Insn

For many machines, multiple types of branch instructions are provided, eachfor different length branch displacements. In most cases, the assemblerwill choose the correct instruction to use. However, when the assemblercannot do so, GCC can when a special attribute, thelengthattribute, is defined. This attribute must be defined to have numericvalues by specifying a null string in itsdefine_attr.

In the case of thelength attribute, two additional forms ofarithmetic terms are allowed in test expressions:

(match_dupn)

This refers to the address of operandn of the current insn, whichmust be alabel_ref.

(pc)

For non-branch instructions and backward branch instructions, this refersto the address of the current insn. But for forward branch instructions,this refers to the address of the next insn, because the length of thecurrent insn is to be computed.

For normal insns, the length will be determined by value of thelength attribute. In the case ofaddr_vec andaddr_diff_vec insn patterns, the length is computed asthe number of vectors multiplied by the size of each vector.

Lengths are measured in addressable storage units (bytes).

Note that it is possible to call functions via thesymbol_refmechanism to compute the length of an insn. However, if you use thismechanism you must provide dummy clauses to express the maximum lengthwithout using the function call. You can see an example of this in thepa machine description for thecall_symref pattern.

The following macros can be used to refine the length computation:

ADJUST_INSN_LENGTH (insn,length)

If defined, modifies the length assigned to instructioninsn as afunction of the context in which it is used.length is an lvaluethat contains the initially computed length of the insn and should beupdated with the correct length of the insn.

This macro will normally not be required. A case in which it isrequired is the ROMP. On this machine, the size of anaddr_vecinsn must be increased by two to compensate for the fact that alignmentmay be required.

The routine that returnsget_attr_length (the value of thelength attribute) can be used by the output routine todetermine the form of the branch instruction to be written, as theexample below illustrates.

As an example of the specification of variable-length branches, considerthe IBM 360. If we adopt the convention that a register will be set tothe starting address of a function, we can jump to labels within 4k ofthe start using a four-byte instruction. Otherwise, we need a six-bytesequence to load the address from memory and then branch to it.

On such a machine, a pattern for a branch instruction might be specifiedas follows:

(define_insn "jump"  [(set (pc)        (label_ref (match_operand 0 "" "")))]  ""{   return (get_attr_length (insn) == 4           ? "b %l0" : "l r15,=a(%l0); br r15");}  [(set (attr "length")        (if_then_else (lt (match_dup 0) (const_int 4096))                      (const_int 4)                      (const_int 6)))])

Next:Constant Attributes, Previous:Example of Attribute Specifications, Up:Instruction Attributes   [Contents][Index]


[8]ページ先頭

©2009-2026 Movatter.jp