Home | History | Annotate | Line # | Download | only in rl78
rl78-expand.md revision 1.1.1.2
      1 ;;  Machine Description for Renesas RL78 processors
      2 ;;  Copyright (C) 2011-2015 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 ;;---------- Moving ------------------------
     23 
     24 (define_expand "movqi"
     25   [(set (match_operand:QI 0 "nonimmediate_operand")
     26 	(match_operand:QI 1 "general_operand"))]
     27   ""
     28   {
     29     if (MEM_P (operands[0]) && MEM_P (operands[1]))
     30       operands[1] = copy_to_mode_reg (QImode, operands[1]);
     31     if (rl78_far_p (operands[0]) && rl78_far_p (operands[1]))
     32       operands[1] = copy_to_mode_reg (QImode, operands[1]);
     33 
     34     /* GCC can generate (SUBREG (SYMBOL_REF)) when it has to store a symbol
     35        into a bitfield, or a packed ordinary field.  We can handle this
     36        provided that the destination is a register.  If not, then load the
     37        source into a register first.  */
     38     if (GET_CODE (operands[1]) == SUBREG
     39         && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
     40 	&& ! REG_P (operands[0]))
     41 	operands[1] = copy_to_mode_reg (QImode, operands[1]);
     42 
     43     /* Similarly for (SUBREG (CONST (PLUS (SYMBOL_REF)))).
     44        cf. g++.dg/abi/packed.C.  */
     45     if (GET_CODE (operands[1]) == SUBREG
     46 	&& GET_CODE (XEXP (operands[1], 0)) == CONST
     47         && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == PLUS
     48         && GET_CODE (XEXP (XEXP (XEXP (operands[1], 0), 0), 0)) == SYMBOL_REF
     49 	&& ! REG_P (operands[0]))
     50 	operands[1] = copy_to_mode_reg (QImode, operands[1]);
     51 
     52     if (CONST_INT_P (operands[1]) && ! IN_RANGE (INTVAL (operands[1]), (-1 << 8) + 1, (1 << 8) - 1))
     53       FAIL;
     54   }
     55 )
     56 
     57 (define_expand "movhi"
     58   [(set (match_operand:HI 0 "nonimmediate_operand")
     59 	(match_operand:HI 1 "general_operand"))]
     60   ""
     61   {
     62     if (MEM_P (operands[0]) && MEM_P (operands[1]))
     63       operands[1] = copy_to_mode_reg (HImode, operands[1]);
     64     if (rl78_far_p (operands[0]) && rl78_far_p (operands[1]))
     65       operands[1] = copy_to_mode_reg (HImode, operands[1]);
     66 
     67     /* FIXME: Not sure how GCC can generate (SUBREG (SYMBOL_REF)),
     68        but it does.  Since this makes no sense, reject it here.  */
     69     if (GET_CODE (operands[1]) == SUBREG
     70         && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF)
     71       FAIL;
     72     /* Similarly for (SUBREG (CONST (PLUS (SYMBOL_REF)))).  */
     73     if (GET_CODE (operands[1]) == SUBREG
     74 	&& GET_CODE (XEXP (operands[1], 0)) == CONST
     75         && GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == PLUS
     76         && GET_CODE (XEXP (XEXP (XEXP (operands[1], 0), 0), 0)) == SYMBOL_REF)
     77       FAIL;
     78   }
     79 )
     80 
     81 (define_insn_and_split "movsi"
     82   [(set (match_operand:SI 0 "nonimmediate_operand" "=vYS,v,Wfr")
     83 	(match_operand:SI 1 "general_operand" "viYS,Wfr,v"))]
     84   ""
     85   "#"
     86   ""
     87   [(set (match_operand:HI 2 "nonimmediate_operand")
     88 	(match_operand:HI 4 "general_operand"))
     89    (set (match_operand:HI 3 "nonimmediate_operand")
     90 	(match_operand:HI 5 "general_operand"))]
     91   "rl78_split_movsi (operands, SImode);"
     92   [(set_attr "valloc" "op1")]
     93 )
     94 
     95 (define_insn_and_split "movsf"
     96   [(set (match_operand:SF 0 "nonimmediate_operand" "=vYS,v,Wfr")
     97 	(match_operand:SF 1 "general_operand" "viYS,Wfr,v"))]
     98   ""
     99   "#"
    100   ""
    101   [(set (match_operand:HI 2 "nonimmediate_operand")
    102 	(match_operand:HI 4 "general_operand"))
    103    (set (match_operand:HI 3 "nonimmediate_operand")
    104 	(match_operand:HI 5 "general_operand"))]
    105   "rl78_split_movsi (operands, SFmode);"
    106   [(set_attr "valloc" "op1")]
    107 )
    108 
    109 ;;---------- Conversions ------------------------
    110 
    111 (define_expand "zero_extendqihi2"
    112   [(set (match_operand:HI                 0 "nonimmediate_operand")
    113 	(zero_extend:HI (match_operand:QI 1 "general_operand")))]
    114   ""
    115   "if (rl78_force_nonfar_2 (operands, gen_zero_extendqihi2))
    116      DONE;"
    117   )
    118 
    119 (define_expand "extendqihi2"
    120   [(set (match_operand:HI                 0 "nonimmediate_operand")
    121 	(sign_extend:HI (match_operand:QI 1 "general_operand")))]
    122   ""
    123   "if (rl78_force_nonfar_2 (operands, gen_extendqihi2))
    124      DONE;"
    125   )
    126 
    127 ;;---------- Arithmetic ------------------------
    128 
    129 (define_expand "add<mode>3"
    130   [(set (match_operand:QHI           0 "nonimmediate_operand")
    131 	(plus:QHI (match_operand:QHI 1 "general_operand")
    132 		  (match_operand:QHI 2 "general_operand")))
    133    ]
    134   ""
    135   "if (rl78_force_nonfar_3 (operands, gen_add<mode>3))
    136      DONE;"
    137 )
    138 
    139 (define_expand "sub<mode>3"
    140   [(set (match_operand:QHI            0 "nonimmediate_operand")
    141 	(minus:QHI (match_operand:QHI 1 "general_operand")
    142 		   (match_operand:QHI 2 "general_operand")))
    143    ]
    144   ""
    145   "if (rl78_force_nonfar_3 (operands, gen_sub<mode>3))
    146      DONE;"
    147 )
    148 
    149 (define_expand "neg<mode>2"
    150   [(set (match_operand:QHI            0 "nonimmediate_operand")
    151 	(minus:QHI (const_int 0)
    152 		   (match_operand:QHI 1 "general_operand")))
    153    ]
    154   ""
    155   "if (rl78_force_nonfar_2 (operands, gen_neg<mode>2))
    156      DONE;"
    157 )
    158 
    159 (define_expand "umulqihi3"
    160   [(set (match_operand:HI 0 "register_operand")
    161         (mult:HI (zero_extend:HI (match_operand:QI 1 "register_operand"))
    162                  (zero_extend:HI (match_operand:QI 2 "register_operand"))))]
    163   "!TARGET_G10"
    164   ""
    165 )
    166 
    167 (define_expand "andqi3"
    168   [(set (match_operand:QI         0 "rl78_nonimmediate_operand")
    169 	(and:QI (match_operand:QI 1 "rl78_general_operand")
    170 		(match_operand:QI 2 "rl78_general_operand")))
    171    ]
    172   ""
    173   "if (rl78_force_nonfar_3 (operands, gen_andqi3))
    174      DONE;"
    175 )
    176 
    177 (define_expand "iorqi3"
    178   [(set (match_operand:QI         0 "rl78_nonimmediate_operand")
    179 	(ior:QI (match_operand:QI 1 "rl78_general_operand")
    180 		(match_operand:QI 2 "rl78_general_operand")))
    181    ]
    182   ""
    183   "if (rl78_force_nonfar_3 (operands, gen_iorqi3))
    184      DONE;"
    185 )
    186 
    187 (define_expand "xorqi3"
    188   [(set (match_operand:QI         0 "rl78_nonimmediate_operand")
    189 	(xor:QI (match_operand:QI 1 "rl78_general_operand")
    190 		(match_operand:QI 2 "rl78_general_operand")))
    191    ]
    192   ""
    193   "if (rl78_force_nonfar_3 (operands, gen_xorqi3))
    194      DONE;"
    195 )
    196 
    197 (define_expand "one_cmplqi2"
    198   [(set (match_operand:QI         0 "nonimmediate_operand")
    199 	(xor:QI (match_operand:QI 1 "general_operand")
    200 		(const_int -1)))
    201    ]
    202   ""
    203   "if (rl78_force_nonfar_2 (operands, gen_one_cmplqi2))
    204      DONE;"
    205 )
    206 
    207 ;;---------- Shifts ------------------------
    208 
    209 (define_expand "ashl<mode>3"
    210   [(set (match_operand:QHI             0 "nonimmediate_operand")
    211 	(ashift:QHI (match_operand:QHI 1 "general_operand")
    212 		    (match_operand:QI  2 "general_operand")))
    213    ]
    214   ""
    215   "if (rl78_force_nonfar_3 (operands, gen_ashl<mode>3))
    216      DONE;"
    217 )
    218 
    219 (define_expand "ashr<mode>3"
    220   [(set (match_operand:QHI               0 "nonimmediate_operand")
    221 	(ashiftrt:QHI (match_operand:QHI 1 "general_operand")
    222 		      (match_operand:QI  2 "general_operand")))
    223    ]
    224   ""
    225   "if (rl78_force_nonfar_3 (operands, gen_ashr<mode>3))
    226      DONE;"
    227 )
    228 
    229 (define_expand "lshr<mode>3"
    230   [(set (match_operand:QHI               0 "nonimmediate_operand")
    231 	(lshiftrt:QHI (match_operand:QHI 1 "general_operand")
    232 		      (match_operand:QI  2 "general_operand")))
    233    ]
    234   ""
    235   "if (rl78_force_nonfar_3 (operands, gen_lshr<mode>3))
    236      DONE;"
    237 )
    238 
    239 (define_expand "ashrsi3"
    240   [(parallel [(set (match_operand:SI               0 "nonimmediate_operand")
    241 		   (ashiftrt:SI (match_operand:SI  1 "nonimmediate_operand")
    242 				(match_operand:SI  2 "nonmemory_operand")))
    243 	      (clobber (reg:HI X_REG))])
    244    ]
    245   ""
    246   ""
    247 )
    248 
    249 (define_expand "lshrsi3"
    250   [(parallel [(set (match_operand:SI               0 "nonimmediate_operand")
    251 		   (lshiftrt:SI (match_operand:SI  1 "nonimmediate_operand")
    252 				(match_operand:SI  2 "nonmemory_operand")))
    253 	      (clobber (reg:HI X_REG))])
    254    ]
    255   ""
    256   ""
    257 )
    258 
    259 (define_expand "ashlsi3"
    260   [(parallel [(set (match_operand:SI            0 "nonimmediate_operand")
    261 		   (ashift:SI (match_operand:SI 1 "nonimmediate_operand")
    262 			      (match_operand:SI 2 "nonmemory_operand")))
    263 	      (clobber (reg:HI X_REG))])
    264    ]
    265   ""
    266   ""
    267 )
    268 
    269 ;;---------- Branching ------------------------
    270 
    271 (define_expand "indirect_jump"
    272   [(set (pc)
    273 	(match_operand:HI 0 "nonimmediate_operand"))]
    274   ""
    275   ""
    276 )
    277 
    278 (define_expand "call"
    279   [(call (match_operand:HI 0 "memory_operand")
    280 	 (match_operand 1 ""))]
    281   ""
    282   ""
    283 )
    284 
    285 (define_expand "call_value"
    286   [(set (match_operand          0 "register_operand")
    287 	(call (match_operand:HI 1 "memory_operand")
    288 	      (match_operand    2 "")))]
    289   ""
    290   ""
    291 )
    292 
    293 (define_expand "cbranchqi4"
    294   [(set (pc) (if_then_else
    295 	      (match_operator                    0 "rl78_cmp_operator"
    296 			      [(match_operand:QI 1 "general_operand")
    297 			       (match_operand:QI 2 "general_operand")])
    298               (label_ref (match_operand 3 "" ""))
    299 	      (pc)))]
    300   ""
    301   "rl78_expand_compare (operands);"
    302 )
    303 
    304 (define_expand "cbranchhi4"
    305   [(set (pc) (if_then_else
    306 	      (match_operator                    0 "rl78_cmp_operator"
    307 			      [(match_operand:HI 1 "general_operand")
    308 			       (match_operand:HI 2 "general_operand")])
    309               (label_ref (match_operand 3 "" ""))
    310 	      (pc)))]
    311   ""
    312   "rl78_expand_compare (operands);"
    313 )
    314 
    315 (define_expand "cbranchsi4"
    316   [(parallel [(set (pc) (if_then_else
    317 			 (match_operator 0 "rl78_cmp_operator"
    318 					 [(match_operand:SI 1 "general_operand")
    319 					  (match_operand:SI 2 "nonmemory_operand")])
    320 			 (label_ref (match_operand 3 "" ""))
    321 			 (pc)))
    322 	      (clobber (reg:HI AX_REG))
    323 	      ])]
    324   "1"
    325   "rl78_expand_compare (operands);"
    326 )
    327