Home | History | Annotate | Line # | Download | only in rl78
rl78-virt.md revision 1.1.1.1
      1 ;;  Machine Description for Renesas RL78 processors
      2 ;;  Copyright (C) 2011-2013 Free Software Foundation, Inc.
      3 ;;  Contributed by Red Hat.
      4 
      5 ;; This file is part of GCC.
      6 
      7 ;; GCC is free software; you can redistribute it and/or modify
      8 ;; it under the terms of the GNU General Public License as published by
      9 ;; the Free Software Foundation; either version 3, or (at your option)
     10 ;; any later version.
     11 
     12 ;; GCC is distributed in the hope that it will be useful,
     13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 ;; GNU General Public License for more details.
     16 
     17 ;; You should have received a copy of the GNU General Public License
     18 ;; along with GCC; see the file COPYING3.  If not see
     19 ;; <http://www.gnu.org/licenses/>.
     20 
     22 ;; In this MD file, we define those insn patterns that involve
     23 ;; registers, where such registers are virtual until allocated to a
     24 ;; physical register.  All of these insns need to be conditional on
     25 ;; rl78_virt_insns_ok () being true.
     26 
     27 ;; This tells the physical register allocator what method to use to
     28 ;; allocate registers.  Basically, this defines the template of the
     29 ;; instruction - op1 is of the form "a = op(b)", op2 is "a = b op c"
     30 ;; etc.
     31 
     32 (define_attr "valloc" "op1,op2,ro1,cmp,umul,macax"
     33   (const_string "op2"))
     34 
     35 ;;---------- Moving ------------------------
     36 
     37 (define_insn "*movqi_virt"
     38   [(set (match_operand:QI 0 "nonimmediate_operand" "=vY,v,Wfr")
     39 	(match_operand    1 "general_operand" "vInt8JY,Wfr,vInt8J"))]
     40   "rl78_virt_insns_ok ()"
     41   "v.mov %0, %1"
     42   [(set_attr "valloc" "op1")]
     43 )
     44 
     45 (define_insn "*movhi_virt"
     46   [(set (match_operand:HI 0 "nonimmediate_operand" "=vYS,v,Wfr")
     47 	(match_operand:HI 1 "general_operand" "viYS,Wfr,v"))]
     48   "rl78_virt_insns_ok ()"
     49   "v.movw %0, %1"
     50   [(set_attr "valloc" "op1")]
     51 )
     52 
     53 ;;---------- Conversions ------------------------
     54 
     55 (define_insn "*zero_extendqihi2_virt"
     56   [(set (match_operand:HI                 0 "rl78_nonfar_nonimm_operand" "=vm")
     57 	(zero_extend:HI (match_operand:QI 1 "general_operand" "vim")))]
     58   "rl78_virt_insns_ok ()"
     59   "v.zero_extend\t%0, %1"
     60   [(set_attr "valloc" "op1")]
     61   )
     62 
     63 (define_insn "*extendqihi2_virt"
     64   [(set (match_operand:HI                 0 "rl78_nonfar_nonimm_operand" "=vm")
     65 	(sign_extend:HI (match_operand:QI 1 "general_operand" "vim")))]
     66   "rl78_virt_insns_ok ()"
     67   "v.sign_extend\t%0, %1"
     68   [(set_attr "valloc" "op1")]
     69   )
     70 
     71 ;;---------- Arithmetic ------------------------
     72 
     73 (define_insn "*add<mode>3_virt"
     74   [(set (match_operand:QHI           0 "rl78_nonfar_nonimm_operand" "=vY,S")
     75 	(plus:QHI (match_operand:QHI 1 "rl78_nonfar_operand" "viY,0")
     76 		  (match_operand:QHI 2 "general_operand" "vim,i")))
     77    ]
     78   "rl78_virt_insns_ok ()"
     79   "v.add\t%0, %1, %2"
     80 )
     81 
     82 (define_insn "*sub<mode>3_virt"
     83   [(set (match_operand:QHI            0 "rl78_nonfar_nonimm_operand" "=vm,S")
     84 	(minus:QHI (match_operand:QHI 1 "rl78_nonfar_operand" "vim,0")
     85 		   (match_operand:QHI 2 "general_operand" "vim,i")))
     86    ]
     87   "rl78_virt_insns_ok ()"
     88   "v.sub\t%0, %1, %2"
     89 )
     90 
     91 (define_insn "*umulhi3_shift_virt"
     92   [(set (match_operand:HI 0 "register_operand" "=vm")
     93         (mult:HI (match_operand:HI 1 "rl78_nonfar_operand" "%vim")
     94                  (match_operand:HI 2 "rl78_24_operand" "Ni")))]
     95   "rl78_virt_insns_ok ()"
     96   "v.mulu\t%0, %1, %2"
     97   [(set_attr "valloc" "umul")]
     98 )
     99 
    100 (define_insn "*umulqihi3_virt"
    101   [(set (match_operand:HI 0 "register_operand" "=vm")
    102         (mult:HI (zero_extend:HI (match_operand:QI 1 "rl78_nonfar_operand" "%vim"))
    103                  (zero_extend:HI (match_operand:QI 2 "general_operand" "vim"))))]
    104   "rl78_virt_insns_ok ()"
    105   "v.mulu\t%0, %2"
    106   [(set_attr "valloc" "umul")]
    107 )
    108 
    109 (define_insn "*andqi3_virt"
    110   [(set (match_operand:QI         0 "rl78_nonfar_nonimm_operand" "=vm")
    111 	(and:QI (match_operand:QI 1 "rl78_nonfar_operand" "vim")
    112 		(match_operand:QI 2 "general_operand" "vim")))
    113    ]
    114   "rl78_virt_insns_ok ()"
    115   "v.and\t%0, %1, %2"
    116 )
    117 
    118 (define_insn "*iorqi3_virt"
    119   [(set (match_operand:QI         0 "rl78_nonfar_nonimm_operand" "=vm")
    120 	(ior:QI (match_operand:QI 1 "rl78_nonfar_operand" "vim")
    121 		(match_operand:QI 2 "general_operand" "vim")))
    122    ]
    123   "rl78_virt_insns_ok ()"
    124   "v.or\t%0, %1, %2"
    125 )
    126 
    127 (define_insn "*xor3_virt"
    128   [(set (match_operand:QI         0 "rl78_nonfar_nonimm_operand" "=v,vm,m")
    129 	(xor:QI (match_operand:QI 1 "rl78_nonfar_operand" "%0,vm,vm")
    130 		(match_operand    2 "general_operand" "i,vm,vim")))
    131    ]
    132   "rl78_virt_insns_ok ()"
    133   "v.xor\t%0, %1, %2"
    134 )
    135 
    136 ;;---------- Shifts ------------------------
    137 
    138 (define_insn "*ashl<mode>3_virt"
    139   [(set (match_operand:QHI             0 "rl78_nonfar_nonimm_operand" "=vm")
    140 	(ashift:QHI (match_operand:QHI 1 "rl78_nonfar_operand" "vim")
    141 		    (match_operand:QI  2 "general_operand" "vim")))
    142    ]
    143   "rl78_virt_insns_ok ()"
    144   "v.shl\t%0, %1, %2"
    145 )
    146 
    147 (define_insn "*ashr<mode>3_virt"
    148   [(set (match_operand:QHI               0 "rl78_nonfar_nonimm_operand" "=vm")
    149 	(ashiftrt:QHI (match_operand:QHI 1 "rl78_nonfar_operand" "vim")
    150 		      (match_operand:QI  2 "general_operand" "vim")))
    151    ]
    152   "rl78_virt_insns_ok ()"
    153   "v.sar\t%0, %1, %2"
    154 )
    155 
    156 (define_insn "*lshr<mode>3_virt"
    157   [(set (match_operand:QHI               0 "rl78_nonfar_nonimm_operand" "=vm")
    158 	(lshiftrt:QHI (match_operand:QHI 1 "rl78_nonfar_operand" "vim")
    159 		      (match_operand:QI  2 "general_operand" "vim")))
    160    ]
    161   "rl78_virt_insns_ok ()"
    162   "v.shr\t%0, %1, %2"
    163 )
    164 
    165 ;; really a macro
    166 (define_insn "*ashrsi3_virt"
    167   [(set (match_operand:SI               0 "register_operand" "=v,v,v")
    168 	(ashiftrt:SI (match_operand:SI  1 "register_operand" "0,v,0")
    169 		      (match_operand:SI 2 "immediate_operand" "M,K,i")))
    170    ]
    171   ""
    172   "@
    173    ; ashrsi %0, 0
    174    movw\tax,%H1\;sarw\tax,1\;movw\t%H0,ax\;mov\ta,%Q1\;rorc\ta,1\;mov\t%Q0,a\;mov\ta,%q1\;rorc\ta,1\;mov\t%q0,a
    175    mov\tb,%2\;1:\;movw\tax,%H1\;sarw\tax,1\;movw\t%H0,ax\;mov\ta,%Q1\;rorc\ta,1\;mov\t%Q0,a\;mov\ta,%q1\;rorc\ta,1\;mov\t%q0,a\;dec\tb\;bnz $1b"
    176   [(set_attr "valloc" "macax")]
    177 )
    178 
    179 ;;---------- Branching ------------------------
    180 
    181 (define_insn "*indirect_jump_virt"
    182   [(set (pc)
    183 	(match_operand:HI 0 "nonimmediate_operand" "vm"))]
    184   "rl78_virt_insns_ok ()"
    185   "v.br\t%0"
    186   [(set_attr "valloc" "ro1")]
    187 )
    188 
    189 (define_insn "*call_virt"
    190   [(call (match_operand:HI 0 "memory_operand" "Wab,Wcv")
    191 	 (match_operand 1 "" ""))]
    192   "rl78_virt_insns_ok ()"
    193   "v.call\t%0"
    194   [(set_attr "valloc" "ro1")]
    195   )
    196 
    197 (define_insn "*call_value_virt"
    198   [(set (match_operand 0 "register_operand" "=v,v")
    199 	(call (match_operand:HI 1 "memory_operand" "Wab,Wcv")
    200 	      (match_operand 2 "" "")))]
    201   "rl78_virt_insns_ok ()"
    202   "v.call\t%1"
    203   [(set_attr "valloc" "op1")]
    204   )
    205 
    206 (define_insn "*cbranchqi4_virt"
    207   [(set (pc) (if_then_else
    208 	      (match_operator 0 "rl78_cmp_operator_real"
    209 			      [(match_operand:QI 1 "general_operand" "vim")
    210 			       (match_operand:QI 2 "general_operand" "vim")])
    211               (label_ref (match_operand 3 "" ""))
    212 	      (pc)))]
    213   "rl78_virt_insns_ok ()"
    214   "v.cmp\t%1, %2\\n\tv.b%c0\t%3"
    215   [(set_attr "valloc" "cmp")]
    216   )
    217 
    218 (define_insn "*cbranchhi4_virt"
    219   [(set (pc) (if_then_else
    220 	      (match_operator 0 "rl78_cmp_operator_real"
    221 			      [(match_operand:HI 1 "general_operand" "vim")
    222 			       (match_operand:HI 2 "general_operand" "vim")])
    223               (label_ref (match_operand 3 "" ""))
    224 	      (pc)))]
    225   "rl78_virt_insns_ok ()"
    226   "v.cmpw\t%1, %2\\n\tv.b%c0\t%3"
    227   [(set_attr "valloc" "cmp")]
    228   )
    229 
    230 ;;---------- Peepholes ------------------------
    231 
    232 (define_peephole2
    233   [(set (match_operand:QI 0 "" "")
    234 	(match_operand:QI 1 "" ""))
    235    (set (match_operand:QI 2 "" "")
    236 	(match_operand:QI 3 "" ""))]
    237   "rl78_peep_movhi_p (operands)"
    238   [(set (match_dup 4)
    239 	(match_dup 5))]
    240   "rl78_setup_peep_movhi (operands);"
    241   )
    242 
    243 (define_peephole2
    244   [(set (reg:QI A_REG)
    245 	(match_operand:QI 1 "" ""))
    246    (set (match_operand:QI 0 "" "")
    247 	(reg:QI A_REG))
    248    (set (reg:QI A_REG)
    249 	(match_operand:QI 3 "" ""))
    250    (set (match_operand:QI 2 "" "")
    251 	(reg:QI A_REG))
    252    ]
    253   "rl78_peep_movhi_p (operands)"
    254   [(set (reg:HI AX_REG)
    255 	(match_dup 5))
    256    (set (match_dup 4)
    257 	(reg:HI AX_REG))
    258    ]
    259   "rl78_setup_peep_movhi (operands);"
    260   )
    261