]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/rs6000/genfusion.pl
Update copyright years.
[thirdparty/gcc.git] / gcc / config / rs6000 / genfusion.pl
1 #!/usr/bin/perl
2 # Generate fusion.md
3 #
4 # Copyright (C) 2020-2023 Free Software Foundation, Inc.
5 #
6 # This file is part of GCC.
7 #
8 # GCC is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3, or (at your option)
11 # any later version.
12 #
13 # GCC is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GCC; see the file COPYING3. If not see
20 # <http://www.gnu.org/licenses/>.
21
22 use warnings;
23 use strict;
24
25 print <<'EOF';
26 ;; Generated automatically by genfusion.pl
27
28 ;; Copyright (C) 2020-2023 Free Software Foundation, Inc.
29 ;;
30 ;; This file is part of GCC.
31 ;;
32 ;; GCC is free software; you can redistribute it and/or modify it under
33 ;; the terms of the GNU General Public License as published by the Free
34 ;; Software Foundation; either version 3, or (at your option) any later
35 ;; version.
36 ;;
37 ;; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
38 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or
39 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
40 ;; for more details.
41 ;;
42 ;; You should have received a copy of the GNU General Public License
43 ;; along with GCC; see the file COPYING3. If not see
44 ;; <http://www.gnu.org/licenses/>.
45
46 EOF
47
48 sub mode_to_ldst_char
49 {
50 my ($mode) = @_;
51 my %x = (DI => 'd', SI => 'w', HI => 'h', QI => 'b');
52 return $x{$mode} if exists $x{$mode};
53 return '?';
54 }
55
56 sub gen_ld_cmpi_p10
57 {
58 my ($lmode, $ldst, $clobbermode, $result, $cmpl, $echr, $constpred,
59 $mempred, $ccmode, $np, $extend, $resultmode);
60 LMODE: foreach $lmode ('DI','SI','HI','QI') {
61 $ldst = mode_to_ldst_char($lmode);
62 $clobbermode = $lmode;
63 # For clobber, we need a SI/DI reg in case we
64 # split because we have to sign/zero extend.
65 if ($lmode eq 'HI' || $lmode eq 'QI') { $clobbermode = "GPR"; }
66 RESULT: foreach $result ('clobber', $lmode, "EXT".$lmode) {
67 # EXTDI does not exist, and we cannot directly produce HI/QI results.
68 next RESULT if $result eq "EXTDI" || $result eq "HI" || $result eq "QI";
69 # Don't allow EXTQI because that would allow HI result which we can't do.
70 $result = "GPR" if $result eq "EXTQI";
71 CCMODE: foreach $ccmode ('CC','CCUNS') {
72 $np = "NON_PREFIXED_D";
73 $mempred = "non_update_memory_operand";
74 if ( $ccmode eq 'CC' ) {
75 next CCMODE if $lmode eq 'QI';
76 if ( $lmode eq 'DI' || $lmode eq 'SI' ) {
77 # ld and lwa are both DS-FORM.
78 $np = "NON_PREFIXED_DS";
79 $mempred = "ds_form_mem_operand";
80 }
81 $cmpl = "";
82 $echr = "a";
83 $constpred = "const_m1_to_1_operand";
84 } else {
85 if ( $lmode eq 'DI' ) {
86 # ld is DS-form, but lwz is not.
87 $np = "NON_PREFIXED_DS";
88 $mempred = "ds_form_mem_operand";
89 }
90 $cmpl = "l";
91 $echr = "z";
92 $constpred = "const_0_to_1_operand";
93 }
94 if ($lmode eq 'DI') { $echr = ""; }
95 if ($result =~ m/^EXT/ || $result eq 'GPR' || $clobbermode eq 'GPR') {
96 # We always need extension if result > lmode.
97 if ( $ccmode eq 'CC' ) {
98 $extend = "sign";
99 } else {
100 $extend = "zero";
101 }
102 } else {
103 # Result of SI/DI does not need sign extension.
104 $extend = "none";
105 }
106 print ";; load-cmpi fusion pattern generated by gen_ld_cmpi_p10\n";
107 print ";; load mode is $lmode result mode is $result compare mode is $ccmode extend is $extend\n";
108
109 print "(define_insn_and_split \"*l${ldst}${echr}_cmp${cmpl}di_cr0_${lmode}_${result}_${ccmode}_${extend}\"\n";
110 print " [(set (match_operand:${ccmode} 2 \"cc_reg_operand\" \"=x\")\n";
111 print " (compare:${ccmode} (match_operand:${lmode} 1 \"${mempred}\" \"m\")\n";
112 if ($ccmode eq 'CCUNS') { print " "; }
113 print " (match_operand:${lmode} 3 \"${constpred}\" \"n\")))\n";
114 if ($result eq 'clobber') {
115 print " (clobber (match_scratch:${clobbermode} 0 \"=r\"))]\n";
116 } elsif ($result eq $lmode) {
117 print " (set (match_operand:${result} 0 \"gpc_reg_operand\" \"=r\") (match_dup 1))]\n";
118 } else {
119 print " (set (match_operand:${result} 0 \"gpc_reg_operand\" \"=r\") (${extend}_extend:${result} (match_dup 1)))]\n";
120 }
121 print " \"(TARGET_P10_FUSION)\"\n";
122 print " \"l${ldst}${echr}%X1 %0,%1\\;cmp${cmpl}di %2,%0,%3\"\n";
123 print " \"&& reload_completed\n";
124 print " && (cc_reg_not_cr0_operand (operands[2], CCmode)\n";
125 print " || !address_is_non_pfx_d_or_x (XEXP (operands[1], 0),\n";
126 print " ${lmode}mode, ${np}))\"\n";
127
128 if ($extend eq "none") {
129 print " [(set (match_dup 0) (match_dup 1))\n";
130 } else {
131 $resultmode = $result;
132 if ( $result eq 'clobber' ) { $resultmode = $clobbermode }
133 print " [(set (match_dup 0) (${extend}_extend:${resultmode} (match_dup 1)))\n";
134 }
135 print " (set (match_dup 2)\n";
136 print " (compare:${ccmode} (match_dup 0) (match_dup 3)))]\n";
137 print " \"\"\n";
138 print " [(set_attr \"type\" \"fused_load_cmpi\")\n";
139 print " (set_attr \"cost\" \"8\")\n";
140 print " (set_attr \"length\" \"8\")])\n";
141 print "\n";
142 }
143 }
144 }
145 }
146
147 sub gen_logical_addsubf
148 {
149 my @logicals = ( "and", "andc", "eqv", "nand", "nor", "or", "orc", "xor" );
150 my %logicals_addsub = ( "and"=>1, "nand"=>1, "nor"=>1, "or"=>1 );
151 my @addsub = ( "add", "subf" );
152 my %isaddsub = ( "add"=>1, "subf"=>1 );
153 my %complement = ( "and"=> 0, "andc"=> 1, "eqv"=> 0, "nand"=> 3,
154 "nor"=> 3, "or"=> 0, "orc"=> 1, "xor"=> 0,
155 "add"=> 0, "subf"=> 0 );
156 my %invert = ( "and"=> 0, "andc"=> 0, "eqv"=> 1, "nand"=> 0,
157 "nor"=> 0, "or"=> 0, "orc"=> 0, "xor"=> 0,
158 "add"=> 0, "subf"=> 0 );
159 my %commute2 = ( "and"=> 1, "andc"=> 0, "eqv"=> 1, "nand"=> 0,
160 "nor"=> 0, "or"=> 1, "orc"=> 0, "xor"=> 1 );
161 my %rtlop = ( "and"=>"and", "andc"=>"and", "eqv"=>"xor", "nand"=>"ior",
162 "nor"=>"and", "or"=>"ior", "orc"=>"ior", "xor"=>"xor",
163 "add"=>"plus", "subf"=>"minus" );
164
165 my ($kind, $vchr, $mode, $pred, $constraint, $cr, $outer, @outer_ops,
166 $outer_op, $outer_comp, $outer_inv, $outer_rtl, $inner, @inner_ops,
167 $inner_comp, $inner_inv, $inner_rtl, $inner_op, $both_commute, $c4,
168 $bc, $inner_arg0, $inner_arg1, $inner_exp, $outer_arg2, $outer_exp,
169 $ftype, $insn, $is_subf, $is_rsubf, $outer_32, $outer_42,$outer_name,
170 $fuse_type);
171 KIND: foreach $kind ('scalar','vector') {
172 @outer_ops = @logicals;
173 if ( $kind eq 'vector' ) {
174 $vchr = "v";
175 $mode = "VM";
176 $pred = "altivec_register_operand";
177 $constraint = "v";
178 $fuse_type = "fused_vector";
179 } else {
180 $vchr = "";
181 $mode = "GPR";
182 $pred = "gpc_reg_operand";
183 $constraint = "r";
184 $fuse_type = "fused_arith_logical";
185 push (@outer_ops, @addsub);
186 push (@outer_ops, ( "rsubf" ));
187 }
188 $c4 = "${constraint},${constraint},${constraint},${constraint}";
189 OUTER: foreach $outer ( @outer_ops ) {
190 $outer_name = "${vchr}${outer}";
191 $is_subf = ( $outer eq "subf" );
192 $is_rsubf = ( $outer eq "rsubf" );
193 if ( $is_rsubf ) {
194 $outer = "subf";
195 }
196 $outer_op = "${vchr}${outer}";
197 $outer_comp = $complement{$outer};
198 $outer_inv = $invert{$outer};
199 $outer_rtl = $rtlop{$outer};
200 @inner_ops = @logicals;
201 $ftype = "logical-logical";
202 if ( exists $isaddsub{$outer} ) {
203 @inner_ops = sort keys %logicals_addsub;
204 $ftype = "logical-add";
205 } elsif ( $kind ne 'vector' && exists $logicals_addsub{$outer} ) {
206 push (@inner_ops, @addsub);
207 }
208 INNER: foreach $inner ( @inner_ops ) {
209 if ( exists $isaddsub{$inner} ) {
210 $ftype = "add-logical";
211 }
212 $inner_comp = $complement{$inner};
213 $inner_inv = $invert{$inner};
214 $inner_rtl = $rtlop{$inner};
215 $inner_op = "${vchr}${inner}";
216 # If both ops commute then we can specify % on operand 1
217 # so the pattern will let operands 1 and 2 interchange.
218 $both_commute = ($inner eq $outer) && ($commute2{$inner} == 1);
219 $bc = ""; if ( $both_commute ) { $bc = "%"; }
220 $inner_arg0 = "(match_operand:${mode} 0 \"${pred}\" \"${c4}\")";
221 $inner_arg1 = "(match_operand:${mode} 1 \"${pred}\" \"${bc}${c4}\")";
222 if ( ($inner_comp & 1) == 1 ) {
223 $inner_arg0 = "(not:${mode} $inner_arg0)";
224 }
225 if ( ($inner_comp & 2) == 2 ) {
226 $inner_arg1 = "(not:${mode} $inner_arg1)";
227 }
228 $inner_exp = "(${inner_rtl}:${mode} ${inner_arg0}
229 ${inner_arg1})";
230 if ( $inner_inv == 1 ) {
231 $inner_exp = "(not:${mode} $inner_exp)";
232 }
233 $outer_arg2 = "(match_operand:${mode} 2 \"${pred}\" \"${c4}\")";
234 if ( ($outer_comp & 1) == 1 ) {
235 $outer_arg2 = "(not:${mode} $outer_arg2)";
236 }
237 if ( ($outer_comp & 2) == 2 ) {
238 $inner_exp = "(not:${mode} $inner_exp)";
239 }
240 if ( $is_subf ) {
241 $outer_32 = "%2,%3";
242 $outer_42 = "%2,%4";
243 } else {
244 $outer_32 = "%3,%2";
245 $outer_42 = "%4,%2";
246 }
247 if ( $is_rsubf == 1 ) {
248 $outer_exp = "(${outer_rtl}:${mode} ${outer_arg2}
249 ${inner_exp})";
250 } else {
251 $outer_exp = "(${outer_rtl}:${mode} ${inner_exp}
252 ${outer_arg2})";
253 }
254 if ( $outer_inv == 1 ) {
255 $outer_exp = "(not:${mode} $outer_exp)";
256 }
257
258 $insn = <<"EOF";
259
260 ;; $ftype fusion pattern generated by gen_logical_addsubf
261 ;; $kind $inner_op -> $outer_name
262 (define_insn "*fuse_${inner_op}_${outer_name}"
263 [(set (match_operand:${mode} 3 "${pred}" "=&0,&1,&${constraint},${constraint}")
264 ${outer_exp})
265 (clobber (match_scratch:${mode} 4 "=X,X,X,&${constraint}"))]
266 "(TARGET_P10_FUSION)"
267 "@
268 ${inner_op} %3,%1,%0\\;${outer_op} %3,${outer_32}
269 ${inner_op} %3,%1,%0\\;${outer_op} %3,${outer_32}
270 ${inner_op} %3,%1,%0\\;${outer_op} %3,${outer_32}
271 ${inner_op} %4,%1,%0\\;${outer_op} %3,${outer_42}"
272 [(set_attr "type" "$fuse_type")
273 (set_attr "cost" "6")
274 (set_attr "length" "8")])
275 EOF
276
277 print $insn;
278 }
279 }
280 }
281 }
282
283 sub gen_addadd
284 {
285 my ($kind, $vchr, $op, $type, $mode, $pred, $constraint);
286 foreach $kind ('scalar','vector') {
287 if ( $kind eq 'vector' ) {
288 $vchr = "v";
289 $op = "vaddudm";
290 $type = "fused_vector";
291 $mode = "V2DI";
292 $pred = "altivec_register_operand";
293 $constraint = "v";
294 } else {
295 $vchr = "";
296 $op = "add";
297 $type = "fused_arith_logical";
298 $mode = "GPR";
299 $pred = "gpc_reg_operand";
300 $constraint = "r";
301 }
302 my $c4 = "${constraint},${constraint},${constraint},${constraint}";
303 print <<"EOF";
304
305 ;; ${op}-${op} fusion pattern generated by gen_addadd
306 (define_insn "*fuse_${op}_${op}"
307 [(set (match_operand:${mode} 3 "${pred}" "=&0,&1,&${constraint},${constraint}")
308 (plus:${mode}
309 (plus:${mode} (match_operand:${mode} 0 "${pred}" "${c4}")
310 (match_operand:${mode} 1 "${pred}" "%${c4}"))
311 (match_operand:${mode} 2 "${pred}" "${c4}")))
312 (clobber (match_scratch:${mode} 4 "=X,X,X,&${constraint}"))]
313 "(TARGET_P10_FUSION)"
314 "@
315 ${op} %3,%1,%0\\;${op} %3,%3,%2
316 ${op} %3,%1,%0\\;${op} %3,%3,%2
317 ${op} %3,%1,%0\\;${op} %3,%3,%2
318 ${op} %4,%1,%0\\;${op} %3,%4,%2"
319 [(set_attr "type" "${type}")
320 (set_attr "cost" "6")
321 (set_attr "length" "8")])
322 EOF
323 }
324 }
325
326 gen_ld_cmpi_p10();
327 gen_logical_addsubf();
328 gen_addadd;
329
330 exit(0);
331