genmova.sh revision 1.10
1#!/bin/sh 2# Generate mova.md, a file containing patterns that can be implemented 3# using the h8sx mova instruction. 4 5# Copyright (C) 2004-2019 Free Software Foundation, Inc. 6# 7# This file is part of GCC. 8# 9# GCC is free software; you can redistribute it and/or modify 10# it under the terms of the GNU General Public License as published by 11# the Free Software Foundation; either version 3, or (at your option) 12# any later version. 13# 14# GCC is distributed in the hope that it will be useful, 15# but WITHOUT ANY WARRANTY; without even the implied warranty of 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17# GNU General Public License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with GCC; see the file COPYING3. If not see 21# <http://www.gnu.org/licenses/>. 22 23echo ";; -*- buffer-read-only: t -*-" 24echo ";; Generated automatically from genmova.sh" 25echo ";; Copyright (C) 2004-2019 Free Software Foundation, Inc." 26echo ";;" 27echo ";; This file is part of GCC." 28echo ";;" 29echo ";; GCC is free software; you can redistribute it and/or modify" 30echo ";; it under the terms of the GNU General Public License as published by" 31echo ";; the Free Software Foundation; either version 3, or (at your option)" 32echo ";; any later version." 33echo ";;" 34echo ";; GCC is distributed in the hope that it will be useful," 35echo ";; but WITHOUT ANY WARRANTY; without even the implied warranty of" 36echo ";; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" 37echo ";; GNU General Public License for more details." 38echo ";;" 39echo ";; You should have received a copy of the GNU General Public License" 40echo ";; along with GCC; see the file COPYING3. If not see" 41echo ";; <http://www.gnu.org/licenses/>." 42 43# Loop over modes for the source operand (the index). Only 8-bit and 44# 16-bit indices are allowed. 45for s in QI HI; do 46 47 # Set $src to the operand syntax for this size of index. 48 case $s in 49 QI) src=%X1.b;; 50 HI) src=%T1.w;; 51 esac 52 53 # A match_operand for the source. 54 operand="(match_operand:$s 1 \"h8300_dst_operand\" \"0,rQ\")" 55 56 # Loop over the destination register's mode. The QI and HI versions use 57 # the same instructions as the SI ones, they just ignore the upper bits 58 # of the result. 59 for d in QI HI SI; do 60 61 # If the destination is larger than the source, include a 62 # zero_extend/plus pattern. We could also match zero extensions 63 # of memory without the plus, but it's not any smaller or faster 64 # than separate insns. 65 case $d:$s in 66 SI:QI | SI:HI | HI:QI) 67 cat <<EOF 68(define_insn "" 69 [(set (match_operand:$d 0 "register_operand" "=r,r") 70 (plus:$d (zero_extend:$d $operand) 71 (match_operand:$d 2 "immediate_operand" "i,i")))] 72 "TARGET_H8300SX" 73 "mova/b.l @(%o2%C2,$src),%S0" 74 [(set_attr "length_table" "mova") 75 (set_attr "cc" "none")]) 76 77EOF 78 ;; 79 esac 80 81 # Loop over the shift amount. 82 for shift in 1 2; do 83 case $shift in 84 1) opsize=w mult=2;; 85 2) opsize=l mult=4;; 86 esac 87 88 # Calculate the mask of bits that will be nonzero after the source 89 # has been extended and shifted. 90 case $s:$shift in 91 QI:1) mask=510;; 92 QI:2) mask=1020;; 93 HI:1) mask=131070;; 94 HI:2) mask=262140;; 95 esac 96 97 # There doesn't seem to be a well-established canonical form for 98 # some of the patterns we need. Emit both shift and multiplication 99 # patterns. 100 for form in mult ashift; do 101 case $form in 102 mult) amount=$mult;; 103 ashift) amount=$shift;; 104 esac 105 106 case $d:$s in 107 # If the source and destination are the same size, we can treat 108 # mova as a sort of multiply-add instruction. 109 QI:QI | HI:HI) 110 cat <<EOF 111(define_insn "" 112 [(set (match_operand:$d 0 "register_operand" "=r,r") 113 (plus:$d ($form:$d $operand 114 (const_int $amount)) 115 (match_operand:$d 2 "immediate_operand" "i,i")))] 116 "TARGET_H8300SX" 117 "mova/$opsize.l @(%o2%C2,$src),%S0" 118 [(set_attr "length_table" "mova") 119 (set_attr "cc" "none")]) 120 121EOF 122 ;; 123 124 # Handle the cases where the source is smaller than the 125 # destination. Sometimes combine will keep the extension, 126 # sometimes it will use an AND. 127 SI:QI | SI:HI | HI:QI) 128 129 # Emit the forms that use zero_extend. 130 cat <<EOF 131(define_insn "" 132 [(set (match_operand:$d 0 "register_operand" "=r,r") 133 ($form:$d (zero_extend:$d $operand) 134 (const_int $amount)))] 135 "TARGET_H8300SX" 136 "mova/$opsize.l @(0,$src),%S0" 137 [(set_attr "length_table" "mova_zero") 138 (set_attr "cc" "none")]) 139 140(define_insn "" 141 [(set (match_operand:$d 0 "register_operand" "=r,r") 142 (plus:$d ($form:$d (zero_extend:$d $operand) 143 (const_int $amount)) 144 (match_operand:$d 2 "immediate_operand" "i,i")))] 145 "TARGET_H8300SX" 146 "mova/$opsize.l @(%o2%C2,$src),%S0" 147 [(set_attr "length_table" "mova") 148 (set_attr "cc" "none")]) 149 150EOF 151 152 # Now emit the forms that use AND. When the index is a register, 153 # these forms are effectively $d-mode operations: the index will 154 # be a $d-mode REG or SUBREG. When the index is a memory 155 # location, we will have a paradoxical subreg such as: 156 # 157 # (and:SI (mult:SI (subreg:SI (mem:QI ...) 0) 158 # (const_int 4)) 159 # (const_int 1020)) 160 # 161 # Match the two case separately: a $d-mode register_operand 162 # or a $d-mode subreg of an $s-mode memory_operand. Match the 163 # memory form first since register_operand accepts mem subregs 164 # before reload. 165 memory="(match_operand:$s 1 \"memory_operand\" \"m\")" 166 memory="(subreg:$d $memory 0)" 167 register="(match_operand:$d 1 \"register_operand\" \"0\")" 168 for paradoxical in "$memory" "$register"; do 169 cat <<EOF 170(define_insn "" 171 [(set (match_operand:$d 0 "register_operand" "=r") 172 (and:$d ($form:$d $paradoxical 173 (const_int $amount)) 174 (const_int $mask)))] 175 "TARGET_H8300SX" 176 "mova/$opsize.l @(0,$src),%S0" 177 [(set_attr "length_table" "mova_zero") 178 (set_attr "cc" "none")]) 179 180(define_insn "" 181 [(set (match_operand:$d 0 "register_operand" "=r") 182 (plus:$d (and:$d ($form:$d $paradoxical 183 (const_int $amount)) 184 (const_int $mask)) 185 (match_operand:$d 2 "immediate_operand" "i")))] 186 "TARGET_H8300SX" 187 "mova/$opsize.l @(%o2%C2,$src),%S0" 188 [(set_attr "length_table" "mova") 189 (set_attr "cc" "none")]) 190 191EOF 192 done 193 ;; 194 esac 195 done 196 done 197 done 198done 199