Debian Codegraph @

gcc/config/arm/arm-mve-builtins-functions.h

raw
1 /* ACLE support for Arm MVE (function_base classes)
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #ifndef GCC_ARM_MVE_BUILTINS_FUNCTIONS_H
21 #define GCC_ARM_MVE_BUILTINS_FUNCTIONS_H
22
23 #include "arm-protos.h"
24
25 namespace arm_mve {
26
27 /* Wrap T, which is derived from function_base, and indicate that the
28 function never has side effects. It is only necessary to use this
29 wrapper on functions that might have floating-point suffixes, since
30 otherwise we assume by default that the function has no side effects. */
31 template<typename T>
32 class quiet : public T
33 {
34 public:
35 CONSTEXPR quiet () : T () {}
36
37 unsigned int
38 call_properties (const function_instance &) const override
39 {
40 return 0;
41 }
42 };
43
44 /* An incomplete function_base for functions that have an associated
45 rtx_code or an unspec for signed integers, unsigned integers and
46 floating-point values for the non-predicated, non-suffixed
47 intrinsics, and unspec codes, with separate codes for signed
48 integers, unsigned integers and floating-point values for
49 predicated and/or suffixed intrinsics. The class simply records
50 information about the mapping for derived classes to use and
51 provides a generic expand_unspec () to avoid duplicating expansion
52 code in derived classes. */
53 class unspec_based_mve_function_base : public function_base
54 {
55 public:
56 CONSTEXPR unspec_based_mve_function_base (rtx_code code_for_sint,
57 rtx_code code_for_uint,
58 rtx_code code_for_fp,
59 int unspec_for_sint,
60 int unspec_for_uint,
61 int unspec_for_fp,
62 int unspec_for_n_sint,
63 int unspec_for_n_uint,
64 int unspec_for_n_fp,
65 int unspec_for_m_sint,
66 int unspec_for_m_uint,
67 int unspec_for_m_fp,
68 int unspec_for_m_n_sint,
69 int unspec_for_m_n_uint,
70 int unspec_for_m_n_fp)
71 : m_code_for_sint (code_for_sint),
72 m_code_for_uint (code_for_uint),
73 m_code_for_fp (code_for_fp),
74 m_unspec_for_sint (unspec_for_sint),
75 m_unspec_for_uint (unspec_for_uint),
76 m_unspec_for_fp (unspec_for_fp),
77 m_unspec_for_n_sint (unspec_for_n_sint),
78 m_unspec_for_n_uint (unspec_for_n_uint),
79 m_unspec_for_n_fp (unspec_for_n_fp),
80 m_unspec_for_m_sint (unspec_for_m_sint),
81 m_unspec_for_m_uint (unspec_for_m_uint),
82 m_unspec_for_m_fp (unspec_for_m_fp),
83 m_unspec_for_m_n_sint (unspec_for_m_n_sint),
84 m_unspec_for_m_n_uint (unspec_for_m_n_uint),
85 m_unspec_for_m_n_fp (unspec_for_m_n_fp)
86 {}
87
88 /* The rtx code to use for signed, unsigned integers and
89 floating-point values respectively. */
90 rtx_code m_code_for_sint;
91 rtx_code m_code_for_uint;
92 rtx_code m_code_for_fp;
93
94 /* The unspec code associated with signed-integer, unsigned-integer
95 and floating-point operations respectively. It covers the cases
96 with the _n suffix, and/or the _m predicate. */
97 int m_unspec_for_sint;
98 int m_unspec_for_uint;
99 int m_unspec_for_fp;
100 int m_unspec_for_n_sint;
101 int m_unspec_for_n_uint;
102 int m_unspec_for_n_fp;
103 int m_unspec_for_m_sint;
104 int m_unspec_for_m_uint;
105 int m_unspec_for_m_fp;
106 int m_unspec_for_m_n_sint;
107 int m_unspec_for_m_n_uint;
108 int m_unspec_for_m_n_fp;
109
110 rtx expand_unspec (function_expander &e) const;
111 };
112
113 /* Expand the unspecs, which is common to all intrinsics using
114 unspec_based_mve_function_base. If some combinations are not
115 supported for an intrinsics family, they should be handled by the
116 caller (and not crash here). */
117 rtx
118 unspec_based_mve_function_base::expand_unspec (function_expander &e) const
119 {
120 machine_mode mode = e.vector_mode (0);
121 insn_code code;
122
123 switch (e.pred)
124 {
125 case PRED_none:
126 switch (e.mode_suffix_id)
127 {
128 case MODE_none:
129 /* No predicate, no suffix. */
130 if (e.type_suffix (0).integer_p)
131 {
132 int unspec = (e.type_suffix (0).unsigned_p
133 ? m_unspec_for_uint
134 : m_unspec_for_sint);
135 code = code_for_mve_q (unspec, unspec, mode);
136 }
137 else
138 code = code_for_mve_q_f (m_unspec_for_fp, mode);
139 break;
140
141 case MODE_n:
142 /* No predicate, _n suffix. */
143 if (e.type_suffix (0).integer_p)
144 {
145 int unspec = (e.type_suffix (0).unsigned_p
146 ? m_unspec_for_n_uint
147 : m_unspec_for_n_sint);
148 code = code_for_mve_q_n (unspec, unspec, mode);
149 }
150 else
151 code = code_for_mve_q_n_f (m_unspec_for_n_fp, mode);
152 break;
153
154 default:
155 gcc_unreachable ();
156 }
157 return e.use_exact_insn (code);
158
159 case PRED_m:
160 case PRED_x:
161 switch (e.mode_suffix_id)
162 {
163 case MODE_none:
164 /* No suffix, "m" or "x" predicate. */
165 if (e.type_suffix (0).integer_p)
166 {
167 int unspec = (e.type_suffix (0).unsigned_p
168 ? m_unspec_for_m_uint
169 : m_unspec_for_m_sint);
170 code = code_for_mve_q_m (unspec, unspec, mode);
171 }
172 else
173 code = code_for_mve_q_m_f (m_unspec_for_m_fp, mode);
174 break;
175
176 case MODE_n:
177 /* _n suffix, "m" or "x" predicate. */
178 if (e.type_suffix (0).integer_p)
179 {
180 int unspec = (e.type_suffix (0).unsigned_p
181 ? m_unspec_for_m_n_uint
182 : m_unspec_for_m_n_sint);
183 code = code_for_mve_q_m_n (unspec, unspec, mode);
184 }
185 else
186 code = code_for_mve_q_m_n_f (m_unspec_for_m_n_fp, mode);
187 break;
188
189 default:
190 gcc_unreachable ();
191 }
192
193 if (e.pred == PRED_m)
194 return e.use_cond_insn (code, 0);
195 else
196 return e.use_pred_x_insn (code);
197 break;
198
199 default:
200 gcc_unreachable ();
201 }
202 }
203
204 /* Map the function directly to CODE (UNSPEC, M) where M is the vector
205 mode associated with type suffix 0, except when there is no
206 predicate and no _n suffix, in which case we use the appropriate
207 rtx_code. This is useful when the basic operation is mapped to a
208 standard RTX code and all other versions use different unspecs. */
209 class unspec_based_mve_function_exact_insn : public unspec_based_mve_function_base
210 {
211 public:
212 CONSTEXPR unspec_based_mve_function_exact_insn (rtx_code code_for_sint,
213 rtx_code code_for_uint,
214 rtx_code code_for_fp,
215 int unspec_for_n_sint,
216 int unspec_for_n_uint,
217 int unspec_for_n_fp,
218 int unspec_for_m_sint,
219 int unspec_for_m_uint,
220 int unspec_for_m_fp,
221 int unspec_for_m_n_sint,
222 int unspec_for_m_n_uint,
223 int unspec_for_m_n_fp)
224 : unspec_based_mve_function_base (code_for_sint,
225 code_for_uint,
226 code_for_fp,
227 -1,
228 -1,
229 -1,
230 unspec_for_n_sint,
231 unspec_for_n_uint,
232 unspec_for_n_fp,
233 unspec_for_m_sint,
234 unspec_for_m_uint,
235 unspec_for_m_fp,
236 unspec_for_m_n_sint,
237 unspec_for_m_n_uint,
238 unspec_for_m_n_fp)
239 {}
240
241 rtx
242 expand (function_expander &e) const override
243 {
244 /* No suffix, no predicate, use the right RTX code. */
245 if ((e.mode_suffix_id != MODE_n)
246 && (e.pred == PRED_none))
247 return e.map_to_rtx_codes (m_code_for_sint, m_code_for_uint,
248 m_code_for_fp);
249
250 return expand_unspec (e);
251 }
252 };
253
254 /* Map the function directly to CODE (UNSPEC, M) where M is the vector
255 mode associated with type suffix 0. */
256 class unspec_mve_function_exact_insn : public unspec_based_mve_function_base
257 {
258 public:
259 CONSTEXPR unspec_mve_function_exact_insn (int unspec_for_sint,
260 int unspec_for_uint,
261 int unspec_for_fp,
262 int unspec_for_n_sint,
263 int unspec_for_n_uint,
264 int unspec_for_n_fp,
265 int unspec_for_m_sint,
266 int unspec_for_m_uint,
267 int unspec_for_m_fp,
268 int unspec_for_m_n_sint,
269 int unspec_for_m_n_uint,
270 int unspec_for_m_n_fp)
271 : unspec_based_mve_function_base (UNKNOWN,
272 UNKNOWN,
273 UNKNOWN,
274 unspec_for_sint,
275 unspec_for_uint,
276 unspec_for_fp,
277 unspec_for_n_sint,
278 unspec_for_n_uint,
279 unspec_for_n_fp,
280 unspec_for_m_sint,
281 unspec_for_m_uint,
282 unspec_for_m_fp,
283 unspec_for_m_n_sint,
284 unspec_for_m_n_uint,
285 unspec_for_m_n_fp)
286 {}
287
288 rtx
289 expand (function_expander &e) const override
290 {
291 return expand_unspec (e);
292 }
293 };
294
295 /* Map the function directly to CODE (UNSPEC), when there is a
296 non-predicated version and one with the "_p" predicate. */
297 class unspec_mve_function_exact_insn_pred_p : public unspec_based_mve_function_base
298 {
299 public:
300 CONSTEXPR unspec_mve_function_exact_insn_pred_p (int unspec_for_sint,
301 int unspec_for_uint,
302 int unspec_for_fp,
303 int unspec_for_p_sint,
304 int unspec_for_p_uint,
305 int unspec_for_p_fp)
306 : unspec_based_mve_function_base (UNKNOWN, /* No RTX code. */
307 UNKNOWN,
308 UNKNOWN,
309 unspec_for_sint,
310 unspec_for_uint,
311 unspec_for_fp,
312 -1, -1, -1, /* No _n intrinsics. */
313 -1, -1, -1, /* No _m intrinsics. */
314 -1, -1, -1), /* No _m_n intrinsics. */
315 m_unspec_for_p_sint (unspec_for_p_sint),
316 m_unspec_for_p_uint (unspec_for_p_uint),
317 m_unspec_for_p_fp (unspec_for_p_fp)
318 {}
319
320 /* The unspec code associated with signed-integer and
321 unsigned-integer or floating-point operations with "_p"
322 predicate. */
323 int m_unspec_for_p_sint;
324 int m_unspec_for_p_uint;
325 int m_unspec_for_p_fp;
326
327 rtx
328 expand (function_expander &e) const override
329 {
330 insn_code code;
331 int unspec;
332
333 if (m_unspec_for_sint == VADDLVQ_S
334 || m_unspec_for_sint == VADDLVAQ_S
335 || m_unspec_for_sint == VRMLALDAVHAQ_S
336 || m_unspec_for_sint == VRMLALDAVHAXQ_S
337 || m_unspec_for_sint == VRMLALDAVHQ_S
338 || m_unspec_for_sint == VRMLALDAVHXQ_S
339 || m_unspec_for_sint == VRMLSLDAVHAQ_S
340 || m_unspec_for_sint == VRMLSLDAVHAXQ_S
341 || m_unspec_for_sint == VRMLSLDAVHQ_S
342 || m_unspec_for_sint == VRMLSLDAVHXQ_S)
343 {
344 switch (e.pred)
345 {
346 case PRED_none:
347 unspec = (e.type_suffix (0).unsigned_p
348 ? m_unspec_for_uint
349 : m_unspec_for_sint);
350 code = code_for_mve_q_v4si (unspec, unspec);
351 return e.use_exact_insn (code);
352
353 case PRED_p:
354 unspec = (e.type_suffix (0).unsigned_p
355 ? m_unspec_for_p_uint
356 : m_unspec_for_p_sint);
357 code = code_for_mve_q_p_v4si (unspec, unspec);
358 return e.use_exact_insn (code);
359
360 default:
361 gcc_unreachable ();
362 }
363 }
364
365 if (e.pred == PRED_p)
366 {
367 machine_mode mode = e.vector_mode (0);
368
369 if (e.type_suffix (0).integer_p)
370 {
371 unspec = (e.type_suffix (0).unsigned_p
372 ? m_unspec_for_p_uint
373 : m_unspec_for_p_sint);
374 code = code_for_mve_q_p (unspec, unspec, mode);
375 }
376 else
377 code = code_for_mve_q_p_f (m_unspec_for_p_fp, mode);
378
379 return e.use_exact_insn (code);
380 }
381
382 return expand_unspec (e);
383 }
384 };
385
386 /* Map the function directly to CODE (UNSPEC, M) for vshl-like
387 builtins. The difference with unspec_mve_function_exact_insn is
388 that this function handles MODE_r and the related unspecs.. */
389 class unspec_mve_function_exact_insn_vshl : public unspec_based_mve_function_base
390 {
391 public:
392 CONSTEXPR unspec_mve_function_exact_insn_vshl (int unspec_for_sint,
393 int unspec_for_uint,
394 int unspec_for_n_sint,
395 int unspec_for_n_uint,
396 int unspec_for_m_sint,
397 int unspec_for_m_uint,
398 int unspec_for_m_n_sint,
399 int unspec_for_m_n_uint,
400 int unspec_for_m_r_sint,
401 int unspec_for_m_r_uint,
402 int unspec_for_r_sint,
403 int unspec_for_r_uint)
404 : unspec_based_mve_function_base (UNKNOWN,
405 UNKNOWN,
406 UNKNOWN,
407 unspec_for_sint,
408 unspec_for_uint,
409 -1,
410 unspec_for_n_sint,
411 unspec_for_n_uint,
412 -1,
413 unspec_for_m_sint,
414 unspec_for_m_uint,
415 -1,
416 unspec_for_m_n_sint,
417 unspec_for_m_n_uint,
418 -1),
419 m_unspec_for_m_r_sint (unspec_for_m_r_sint),
420 m_unspec_for_m_r_uint (unspec_for_m_r_uint),
421 m_unspec_for_r_sint (unspec_for_r_sint),
422 m_unspec_for_r_uint (unspec_for_r_uint)
423 {}
424
425 /* The unspec code associated with signed-integer and unsigned-integer
426 operations with MODE_r with or without PRED_m. */
427 int m_unspec_for_m_r_sint;
428 int m_unspec_for_m_r_uint;
429 int m_unspec_for_r_sint;
430 int m_unspec_for_r_uint;
431
432 rtx
433 expand (function_expander &e) const override
434 {
435 insn_code code;
436 int unspec;
437
438 if (e.mode_suffix_id == MODE_r)
439 {
440 machine_mode mode = e.vector_mode (0);
441 switch (e.pred)
442 {
443 case PRED_none:
444 /* No predicate, _r suffix. */
445 unspec = (e.type_suffix (0).unsigned_p
446 ? m_unspec_for_r_uint
447 : m_unspec_for_r_sint);
448 code = code_for_mve_q_r (unspec, unspec, mode);
449 return e.use_exact_insn (code);
450
451 case PRED_m:
452 case PRED_x:
453 /* _r suffix, "m" or "x" predicate. */
454 unspec = (e.type_suffix (0).unsigned_p
455 ? m_unspec_for_m_r_uint
456 : m_unspec_for_m_r_sint);
457 code = code_for_mve_q_m_r (unspec, unspec, mode);
458
459 if (e.pred == PRED_m)
460 return e.use_cond_insn (code, 0);
461 else
462 return e.use_pred_x_insn (code);
463
464 default:
465 gcc_unreachable ();
466 }
467 }
468
469 return expand_unspec (e);
470 }
471 };
472
473 /* Map the function directly to CODE (M) for vbic-like builtins. The difference
474 with unspec_based_mve_function_exact_insn is that this function has vbic
475 hardcoded for the PRED_none, MODE_none version, rather than using an
476 RTX. */
477 class unspec_based_mve_function_exact_insn_vbic : public unspec_based_mve_function_base
478 {
479 public:
480 CONSTEXPR unspec_based_mve_function_exact_insn_vbic (int unspec_for_n_sint,
481 int unspec_for_n_uint,
482 int unspec_for_m_sint,
483 int unspec_for_m_uint,
484 int unspec_for_m_fp,
485 int unspec_for_m_n_sint,
486 int unspec_for_m_n_uint)
487 : unspec_based_mve_function_base (UNKNOWN,
488 UNKNOWN,
489 UNKNOWN,
490 -1, -1, -1, /* No non-predicated, no mode intrinsics. */
491 unspec_for_n_sint,
492 unspec_for_n_uint,
493 -1,
494 unspec_for_m_sint,
495 unspec_for_m_uint,
496 unspec_for_m_fp,
497 unspec_for_m_n_sint,
498 unspec_for_m_n_uint,
499 -1)
500 {}
501
502 rtx
503 expand (function_expander &e) const override
504 {
505 machine_mode mode = e.vector_mode (0);
506 insn_code code;
507
508 /* No suffix, no predicate, use the right RTX code. */
509 if (e.pred == PRED_none
510 && e.mode_suffix_id == MODE_none)
511 {
512 if (e.type_suffix (0).integer_p)
513 if (e.type_suffix (0).unsigned_p)
514 code = code_for_mve_vbicq_u (mode);
515 else
516 code = code_for_mve_vbicq_s (mode);
517 else
518 code = code_for_mve_vbicq_f (mode);
519
520 return e.use_exact_insn (code);
521 }
522
523 return expand_unspec (e);
524 }
525 };
526
527 /* Map the function directly to CODE (M) for vorn-like builtins. The difference
528 with unspec_based_mve_function_exact_insn is that this function has vbic
529 hardcoded for the PRED_none, MODE_none version, rather than using an
530 RTX. */
531 class unspec_based_mve_function_exact_insn_vorn : public unspec_based_mve_function_base
532 {
533 public:
534 CONSTEXPR unspec_based_mve_function_exact_insn_vorn (int unspec_for_n_sint,
535 int unspec_for_n_uint,
536 int unspec_for_m_sint,
537 int unspec_for_m_uint,
538 int unspec_for_m_fp,
539 int unspec_for_m_n_sint,
540 int unspec_for_m_n_uint)
541 : unspec_based_mve_function_base (UNKNOWN,
542 UNKNOWN,
543 UNKNOWN,
544 -1, -1, -1, /* No non-predicated, no mode unspec intrinsics. */
545 unspec_for_n_sint,
546 unspec_for_n_uint,
547 -1,
548 unspec_for_m_sint,
549 unspec_for_m_uint,
550 unspec_for_m_fp,
551 unspec_for_m_n_sint,
552 unspec_for_m_n_uint,
553 -1)
554 {}
555
556 rtx
557 expand (function_expander &e) const override
558 {
559 machine_mode mode = e.vector_mode (0);
560 insn_code code;
561
562 /* No suffix, no predicate, use the right RTX code. */
563 if (e.pred == PRED_none
564 && e.mode_suffix_id == MODE_none)
565 {
566 if (e.type_suffix (0).integer_p)
567 if (e.type_suffix (0).unsigned_p)
568 code = code_for_mve_vornq_u (mode);
569 else
570 code = code_for_mve_vornq_s (mode);
571 else
572 code = code_for_mve_vornq_f (mode);
573 return e.use_exact_insn (code);
574 }
575
576 return expand_unspec (e);
577 }
578 };
579
580 /* Map the comparison functions. */
581 class unspec_based_mve_function_exact_insn_vcmp : public unspec_based_mve_function_base
582 {
583 public:
584 CONSTEXPR unspec_based_mve_function_exact_insn_vcmp (rtx_code code_for_sint,
585 rtx_code code_for_uint,
586 rtx_code code_for_fp,
587 int unspec_for_m_sint,
588 int unspec_for_m_uint,
589 int unspec_for_m_fp,
590 int unspec_for_m_n_sint,
591 int unspec_for_m_n_uint,
592 int unspec_for_m_n_fp)
593 : unspec_based_mve_function_base (code_for_sint,
594 code_for_uint,
595 code_for_fp,
596 -1, -1, -1, /* No non-predicated, no mode intrinsics. */
597 -1, -1, -1, /* No _n intrinsics. */
598 unspec_for_m_sint,
599 unspec_for_m_uint,
600 unspec_for_m_fp,
601 unspec_for_m_n_sint,
602 unspec_for_m_n_uint,
603 unspec_for_m_n_fp)
604 {}
605
606 rtx
607 expand (function_expander &e) const override
608 {
609 machine_mode mode = e.vector_mode (0);
610 insn_code code;
611 rtx target;
612
613 /* No suffix, no predicate, use the right RTX code. */
614 if (e.pred == PRED_none)
615 {
616 rtx_code r_code;
617
618 switch (e.mode_suffix_id)
619 {
620 case MODE_none:
621 if (e.type_suffix (0).integer_p)
622 {
623 r_code = (e.type_suffix (0).unsigned_p
624 ? m_code_for_uint
625 : m_code_for_sint);
626 code = code_for_mve_vcmpq (r_code, mode);
627 }
628 else
629 code = code_for_mve_vcmpq_f (m_code_for_fp, mode);
630 break;
631
632 case MODE_n:
633 if (e.type_suffix (0).integer_p)
634 {
635 r_code = (e.type_suffix (0).unsigned_p
636 ? m_code_for_uint
637 : m_code_for_sint);
638 code = code_for_mve_vcmpq_n (r_code, mode);
639 }
640 else
641 code = code_for_mve_vcmpq_n_f (m_code_for_fp, mode);
642 break;
643
644 default:
645 gcc_unreachable ();
646 }
647 target = e.use_exact_insn (code);
648 }
649 else
650 {
651 int unspec;
652
653 switch (e.pred)
654 {
655 case PRED_m:
656 switch (e.mode_suffix_id)
657 {
658 case MODE_none:
659 /* No suffix, "m" predicate. */
660 if (e.type_suffix (0).integer_p)
661 {
662 unspec = (e.type_suffix (0).unsigned_p
663 ? m_unspec_for_m_uint
664 : m_unspec_for_m_sint);
665 code = code_for_mve_vcmpq_m (unspec, unspec, mode);
666 }
667 else
668 code = code_for_mve_vcmpq_m_f (m_unspec_for_m_fp, mode);
669 break;
670
671 case MODE_n:
672 /* _n suffix, "m" predicate. */
673 if (e.type_suffix (0).integer_p)
674 {
675 unspec = (e.type_suffix (0).unsigned_p
676 ? m_unspec_for_m_n_uint
677 : m_unspec_for_m_n_sint);
678 code = code_for_mve_vcmpq_m_n (unspec, unspec, mode);
679 }
680 else
681 code = code_for_mve_vcmpq_m_n_f (m_unspec_for_m_n_fp, mode);
682 break;
683
684 default:
685 gcc_unreachable ();
686 }
687 target = e.use_cond_insn (code, 0);
688 break;
689
690 default:
691 gcc_unreachable ();
692 }
693 }
694
695 rtx HItarget = gen_reg_rtx (HImode);
696 emit_move_insn (HItarget, gen_lowpart (HImode, target));
697 return HItarget;
698 }
699 };
700
701 /* Map the function directly to CODE (UNSPEC, UNSPEC, UNSPEC, M) where
702 M is the vector mode associated with type suffix 0. USed for the
703 operations where there is a "rot90" or "rot270" suffix, depending
704 on the UNSPEC. We cannot use
705 unspec_based_mve_function_base::expand_unspec () because we call
706 code_for_mve_q with one more parameter. */
707 class unspec_mve_function_exact_insn_rot : public function_base
708 {
709 public:
710 CONSTEXPR unspec_mve_function_exact_insn_rot (int unspec_for_sint,
711 int unspec_for_uint,
712 int unspec_for_fp,
713 int unspec_for_m_sint,
714 int unspec_for_m_uint,
715 int unspec_for_m_fp)
716 : m_unspec_for_sint (unspec_for_sint),
717 m_unspec_for_uint (unspec_for_uint),
718 m_unspec_for_fp (unspec_for_fp),
719 m_unspec_for_m_sint (unspec_for_m_sint),
720 m_unspec_for_m_uint (unspec_for_m_uint),
721 m_unspec_for_m_fp (unspec_for_m_fp)
722 {}
723
724 /* The unspec code associated with signed-integer, unsigned-integer
725 and floating-point operations respectively. It covers the cases
726 with and without the _m predicate. */
727 int m_unspec_for_sint;
728 int m_unspec_for_uint;
729 int m_unspec_for_fp;
730 int m_unspec_for_m_sint;
731 int m_unspec_for_m_uint;
732 int m_unspec_for_m_fp;
733
734 rtx
735 expand (function_expander &e) const override
736 {
737 machine_mode mode = e.vector_mode (0);
738 insn_code code;
739 int unspec;
740
741 switch (e.pred)
742 {
743 case PRED_none:
744 switch (e.mode_suffix_id)
745 {
746 case MODE_none:
747 /* No predicate, no suffix. */
748 if (e.type_suffix (0).integer_p)
749 {
750 unspec = (e.type_suffix (0).unsigned_p
751 ? m_unspec_for_uint
752 : m_unspec_for_sint);
753 code = code_for_mve_q (unspec, unspec, unspec, mode);
754 }
755 else
756 code = code_for_mve_q_f (m_unspec_for_fp, m_unspec_for_fp, mode);
757 break;
758
759 default:
760 gcc_unreachable ();
761 }
762 return e.use_exact_insn (code);
763
764 case PRED_m:
765 case PRED_x:
766 switch (e.mode_suffix_id)
767 {
768 case MODE_none:
769 /* No suffix, "m" or "x" predicate. */
770 if (e.type_suffix (0).integer_p)
771 {
772 unspec = (e.type_suffix (0).unsigned_p
773 ? m_unspec_for_m_uint
774 : m_unspec_for_m_sint);
775 code = code_for_mve_q_m (unspec, unspec, unspec, mode);
776 }
777 else
778 code = code_for_mve_q_m_f (m_unspec_for_m_fp, m_unspec_for_m_fp, mode);
779
780 if (e.pred == PRED_m)
781 return e.use_cond_insn (code, 0);
782 else
783 return e.use_pred_x_insn (code);
784 break;
785
786 default:
787 gcc_unreachable ();
788 }
789
790 default:
791 gcc_unreachable ();
792 }
793
794 gcc_unreachable ();
795 }
796 };
797
798 /* Map the vmull-related function directly to CODE (UNSPEC, UNSPEC, M)
799 where M is the vector mode associated with type suffix 0. We need
800 this special case because the builtins have _int in their
801 names. */
802 class unspec_mve_function_exact_insn_vmull : public function_base
803 {
804 public:
805 CONSTEXPR unspec_mve_function_exact_insn_vmull (int unspec_for_sint,
806 int unspec_for_uint,
807 int unspec_for_m_sint,
808 int unspec_for_m_uint)
809 : m_unspec_for_sint (unspec_for_sint),
810 m_unspec_for_uint (unspec_for_uint),
811 m_unspec_for_m_sint (unspec_for_m_sint),
812 m_unspec_for_m_uint (unspec_for_m_uint)
813 {}
814
815 /* The unspec code associated with signed-integer and
816 unsigned-integer operations respectively. It covers the cases
817 with and without the _m predicate. */
818 int m_unspec_for_sint;
819 int m_unspec_for_uint;
820 int m_unspec_for_m_sint;
821 int m_unspec_for_m_uint;
822
823 rtx
824 expand (function_expander &e) const override
825 {
826 machine_mode mode = e.vector_mode (0);
827 insn_code code;
828 int unspec;
829
830 if (! e.type_suffix (0).integer_p)
831 gcc_unreachable ();
832
833 if (e.mode_suffix_id != MODE_none)
834 gcc_unreachable ();
835
836 switch (e.pred)
837 {
838 case PRED_none:
839 /* No predicate, no suffix. */
840 unspec = (e.type_suffix (0).unsigned_p
841 ? m_unspec_for_uint
842 : m_unspec_for_sint);
843 code = code_for_mve_q_int (unspec, unspec, mode);
844
845 return e.use_exact_insn (code);
846
847 case PRED_m:
848 case PRED_x:
849 /* No suffix, "m" or "x" predicate. */
850 unspec = (e.type_suffix (0).unsigned_p
851 ? m_unspec_for_m_uint
852 : m_unspec_for_m_sint);
853 code = code_for_mve_q_int_m (unspec, unspec, mode);
854
855 if (e.pred == PRED_m)
856 return e.use_cond_insn (code, 0);
857 else
858 return e.use_pred_x_insn (code);
859
860 default:
861 gcc_unreachable ();
862 }
863
864 gcc_unreachable ();
865 }
866 };
867
868 /* Map the vmull_poly-related function directly to CODE (UNSPEC,
869 UNSPEC, M) where M is the vector mode associated with type suffix
870 0. We need this special case because the builtins have _poly in
871 their names, and use the special poly type.. */
872 class unspec_mve_function_exact_insn_vmull_poly : public function_base
873 {
874 public:
875 CONSTEXPR unspec_mve_function_exact_insn_vmull_poly (int unspec_for_poly,
876 int unspec_for_m_poly)
877 : m_unspec_for_poly (unspec_for_poly),
878 m_unspec_for_m_poly (unspec_for_m_poly)
879 {}
880
881 /* The unspec code associated with signed-integer, unsigned-integer
882 and poly operations respectively. It covers the cases with and
883 without the _m predicate. */
884 int m_unspec_for_poly;
885 int m_unspec_for_m_poly;
886
887 rtx
888 expand (function_expander &e) const override
889 {
890 machine_mode mode = e.vector_mode (0);
891 insn_code code;
892
893 if (e.mode_suffix_id != MODE_none)
894 gcc_unreachable ();
895
896 if (! e.type_suffix (0).poly_p)
897 gcc_unreachable ();
898
899 switch (e.pred)
900 {
901 case PRED_none:
902 /* No predicate, no suffix. */
903 code = code_for_mve_q_poly (m_unspec_for_poly, m_unspec_for_poly, mode);
904 return e.use_exact_insn (code);
905
906 case PRED_m:
907 case PRED_x:
908 /* No suffix, "m" or "x" predicate. */
909 code = code_for_mve_q_poly_m (m_unspec_for_m_poly, m_unspec_for_m_poly, mode);
910
911 if (e.pred == PRED_m)
912 return e.use_cond_insn (code, 0);
913 else
914 return e.use_pred_x_insn (code);
915
916 default:
917 gcc_unreachable ();
918 }
919
920 gcc_unreachable ();
921 }
922 };
923
924 /* A function_base that sometimes or always operates on tuples of
925 vectors. */
926 class multi_vector_function : public function_base
927 {
928 public:
929 CONSTEXPR multi_vector_function (unsigned int vectors_per_tuple)
930 : m_vectors_per_tuple (vectors_per_tuple) {}
931
932 unsigned int
933 vectors_per_tuple () const override
934 {
935 return m_vectors_per_tuple;
936 }
937
938 /* The number of vectors in a tuple, or 1 if the function only operates
939 on single vectors. */
940 unsigned int m_vectors_per_tuple;
941 };
942
943 /* A function_base that loads or stores contiguous memory elements
944 without extending or truncating them. */
945 class full_width_access : public multi_vector_function
946 {
947 public:
948 CONSTEXPR full_width_access (unsigned int vectors_per_tuple = 1)
949 : multi_vector_function (vectors_per_tuple) {}
950
951 tree
952 memory_scalar_type (const function_instance &fi) const override
953 {
954 return fi.scalar_type (0);
955 }
956
957 machine_mode
958 memory_vector_mode (const function_instance &fi) const override
959 {
960 machine_mode mode = fi.vector_mode (0);
961
962 if (m_vectors_per_tuple != 1)
963 mode = targetm.array_mode (mode, m_vectors_per_tuple).require ();
964
965 return mode;
966 }
967 };
968
969 /* A function_base that loads elements from memory and extends them
970 to a wider element. The memory element type is a fixed part of
971 the function base name. */
972 class load_extending : public function_base
973 {
974 public:
975 CONSTEXPR load_extending (type_suffix_index signed_memory_type,
976 type_suffix_index unsigned_memory_type,
977 type_suffix_index float_memory_type)
978 : m_signed_memory_type (signed_memory_type),
979 m_unsigned_memory_type (unsigned_memory_type),
980 m_float_memory_type (float_memory_type)
981 {}
982 CONSTEXPR load_extending (type_suffix_index signed_memory_type,
983 type_suffix_index unsigned_memory_type)
984 : m_signed_memory_type (signed_memory_type),
985 m_unsigned_memory_type (unsigned_memory_type),
986 m_float_memory_type (NUM_TYPE_SUFFIXES)
987 {}
988
989 unsigned int call_properties (const function_instance &) const override
990 {
991 return CP_READ_MEMORY;
992 }
993
994 tree memory_scalar_type (const function_instance &fi) const override
995 {
996 type_suffix_index memory_type_suffix
997 = (fi.type_suffix (0).integer_p
998 ? (fi.type_suffix (0).unsigned_p
999 ? m_unsigned_memory_type
1000 : m_signed_memory_type)
1001 : m_float_memory_type);
1002 return scalar_types[type_suffixes[memory_type_suffix].vector_type];
1003 }
1004
1005 machine_mode memory_vector_mode (const function_instance &fi) const override
1006 {
1007 type_suffix_index memory_type_suffix
1008 = (fi.type_suffix (0).integer_p
1009 ? (fi.type_suffix (0).unsigned_p
1010 ? m_unsigned_memory_type
1011 : m_signed_memory_type)
1012 : m_float_memory_type);
1013 machine_mode mem_mode = type_suffixes[memory_type_suffix].vector_mode;
1014 machine_mode reg_mode = fi.vector_mode (0);
1015
1016 return arm_mve_data_mode (GET_MODE_INNER (mem_mode),
1017 GET_MODE_NUNITS (reg_mode)).require ();
1018 }
1019
1020 /* The type of the memory elements. This is part of the function base
1021 name rather than a true type suffix. */
1022 type_suffix_index m_signed_memory_type;
1023 type_suffix_index m_unsigned_memory_type;
1024 type_suffix_index m_float_memory_type;
1025 };
1026
1027 /* A function_base that truncates vector elements and stores them to memory.
1028 The memory element width is a fixed part of the function base name. */
1029 class store_truncating : public function_base
1030 {
1031 public:
1032 CONSTEXPR store_truncating (scalar_mode to_int_mode,
1033 opt_scalar_mode to_float_mode)
1034 : m_to_int_mode (to_int_mode), m_to_float_mode (to_float_mode)
1035 {}
1036
1037 unsigned int call_properties (const function_instance &) const override
1038 {
1039 return CP_WRITE_MEMORY;
1040 }
1041
1042 tree memory_scalar_type (const function_instance &fi) const override
1043 {
1044 /* In truncating stores, the signedness of the memory element is defined
1045 to be the same as the signedness of the vector element. The signedness
1046 doesn't make any difference to the behavior of the function. */
1047 type_class_index tclass = fi.type_suffix (0).tclass;
1048 unsigned int element_bits
1049 = GET_MODE_BITSIZE (fi.type_suffix (0).integer_p
1050 ? m_to_int_mode
1051 : m_to_float_mode.require ());
1052 type_suffix_index suffix = find_type_suffix (tclass, element_bits);
1053 return scalar_types[type_suffixes[suffix].vector_type];
1054 }
1055
1056 machine_mode memory_vector_mode (const function_instance &fi) const override
1057 {
1058 poly_uint64 nunits = GET_MODE_NUNITS (fi.vector_mode (0));
1059 scalar_mode mode = (fi.type_suffix (0).integer_p
1060 ? m_to_int_mode
1061 : m_to_float_mode.require ());
1062 return arm_mve_data_mode (mode, nunits).require ();
1063 }
1064
1065 /* The mode of a single memory element. */
1066 scalar_mode m_to_int_mode;
1067 opt_scalar_mode m_to_float_mode;
1068 };
1069
1070 } /* end namespace arm_mve */
1071
1072 /* Declare the global function base NAME, creating it from an instance
1073 of class CLASS with constructor arguments ARGS. */
1074 #define FUNCTION(NAME, CLASS, ARGS) \
1075 namespace { static CONSTEXPR const CLASS NAME##_obj ARGS; } \
1076 namespace functions { const function_base *const NAME = &NAME##_obj; }
1077
1078 #endif