Previous: Substitutions, Up: Mode Iterators


16.22.1.3 有关机器模式迭代器的例子

这里有一个来自MIPS后端的一个例子。其定义了下列机器模式和属性(除了别的以外):

     (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
     (define_mode_attr d [(SI "") (DI "d")])

并且使用下列模板来同时定义 subsi3subdi3

     (define_insn "sub<mode>3"
       [(set (match_operand:GPR 0 "register_operand" "=d")
             (minus:GPR (match_operand:GPR 1 "register_operand" "d")
                        (match_operand:GPR 2 "register_operand" "d")))]
       ""
       "<d>subu\t%0,%1,%2"
       [(set_attr "type" "arith")
        (set_attr "mode" "<MODE>")])

这就完全等价于:

     (define_insn "subsi3"
       [(set (match_operand:SI 0 "register_operand" "=d")
             (minus:SI (match_operand:SI 1 "register_operand" "d")
                       (match_operand:SI 2 "register_operand" "d")))]
       ""
       "subu\t%0,%1,%2"
       [(set_attr "type" "arith")
        (set_attr "mode" "SI")])
     
     (define_insn "subdi3"
       [(set (match_operand:DI 0 "register_operand" "=d")
             (minus:DI (match_operand:DI 1 "register_operand" "d")
                       (match_operand:DI 2 "register_operand" "d")))]
       ""
       "dsubu\t%0,%1,%2"
       [(set_attr "type" "arith")
        (set_attr "mode" "DI")])