aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/arm/arm-mve-builtins-shapes.cc
blob: 0bd91b24147a0f545770f44c93b82b9bc6d03183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
/* ACLE support for Arm MVE (function shapes)
   Copyright (C) 2023 Free Software Foundation, Inc.

   This file is part of GCC.

   GCC is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GCC is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GCC; see the file COPYING3.  If not see
   <http://www.gnu.org/licenses/>.  */

#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "rtl.h"
#include "memmodel.h"
#include "insn-codes.h"
#include "optabs.h"
#include "arm-mve-builtins.h"
#include "arm-mve-builtins-shapes.h"

/* In the comments below, _t0 represents the first type suffix
   (e.g. "_s8") and _t1 represents the second.  T0/T1 represent the
   type full names (e.g. int8x16_t). Square brackets enclose
   characters that are present in only the full name, not the
   overloaded name.  Governing predicate arguments and predicate
   suffixes are not shown, since they depend on the predication type,
   which is a separate piece of information from the shape.  */

namespace arm_mve {

/* If INSTANCE has a predicate, add it to the list of argument types
   in ARGUMENT_TYPES.  RETURN_TYPE is the type returned by the
   function.  */
static void
apply_predication (const function_instance &instance, tree return_type,
		   vec<tree> &argument_types)
{
  if (instance.pred != PRED_none)
    {
      /* When predicate is PRED_m, insert a first argument
	 ("inactive") with the same type as return_type.  */
      if (instance.has_inactive_argument ())
	argument_types.quick_insert (0, return_type);
      argument_types.quick_push (get_mve_pred16_t ());
    }
}

/* Parse and move past an element type in FORMAT and return it as a type
   suffix.  The format is:

   [01]    - the element type in type suffix 0 or 1 of INSTANCE.
   h<elt>  - a half-sized version of <elt>
   s<bits> - a signed type with the given number of bits
   s[01]   - a signed type with the same width as type suffix 0 or 1
   u<bits> - an unsigned type with the given number of bits
   u[01]   - an unsigned type with the same width as type suffix 0 or 1
   w<elt>  - a double-sized version of <elt>
   x<bits> - a type with the given number of bits and same signedness
             as the next argument.

   Future intrinsics will extend this format.  */
static type_suffix_index
parse_element_type (const function_instance &instance, const char *&format)
{
  int ch = *format++;


  if (ch == 's' || ch == 'u')
    {
      type_class_index tclass = (ch == 'f' ? TYPE_float
				 : ch == 's' ? TYPE_signed
				 : TYPE_unsigned);
      char *end;
      unsigned int bits = strtol (format, &end, 10);
      format = end;
      if (bits == 0 || bits == 1)
	bits = instance.type_suffix (bits).element_bits;
      return find_type_suffix (tclass, bits);
    }

  if (ch == 'h')
    {
      type_suffix_index suffix = parse_element_type (instance, format);
      return find_type_suffix (type_suffixes[suffix].tclass,
			       type_suffixes[suffix].element_bits / 2);
    }

   if (ch == 'w')
    {
      type_suffix_index suffix = parse_element_type (instance, format);
      return find_type_suffix (type_suffixes[suffix].tclass,
			       type_suffixes[suffix].element_bits * 2);
    }

  if (ch == 'x')
    {
      const char *next = format;
      next = strstr (format, ",");
      next+=2;
      type_suffix_index suffix = parse_element_type (instance, next);
      type_class_index tclass = type_suffixes[suffix].tclass;
      char *end;
      unsigned int bits = strtol (format, &end, 10);
      format = end;
      return find_type_suffix (tclass, bits);
    }

  if (ch == '0' || ch == '1')
    return instance.type_suffix_ids[ch - '0'];

  gcc_unreachable ();
}

/* Read and return a type from FORMAT for function INSTANCE.  Advance
   FORMAT beyond the type string.  The format is:

   p       - predicates with type mve_pred16_t
   s<elt>  - a scalar type with the given element suffix
   t<elt>  - a vector or tuple type with given element suffix [*1]
   v<elt>  - a vector with the given element suffix

   where <elt> has the format described above parse_element_type.

   Future intrinsics will extend this format.

   [*1] the vectors_per_tuple function indicates whether the type should
        be a tuple, and if so, how many vectors it should contain.  */
static tree
parse_type (const function_instance &instance, const char *&format)
{
  int ch = *format++;

  if (ch == 'p')
    return get_mve_pred16_t ();

  if (ch == 's')
    {
      type_suffix_index suffix = parse_element_type (instance, format);
      return scalar_types[type_suffixes[suffix].vector_type];
    }

  if (ch == 't')
    {
      type_suffix_index suffix = parse_element_type (instance, format);
      vector_type_index vector_type = type_suffixes[suffix].vector_type;
      unsigned int num_vectors = instance.vectors_per_tuple ();
      return acle_vector_types[num_vectors - 1][vector_type];
    }

  if (ch == 'v')
    {
      type_suffix_index suffix = parse_element_type (instance, format);
      return acle_vector_types[0][type_suffixes[suffix].vector_type];
    }

  gcc_unreachable ();
}

/* Read a type signature for INSTANCE from FORMAT.  Add the argument
   types to ARGUMENT_TYPES and return the return type.  Assert there
   are no more than MAX_ARGS arguments.

   The format is a comma-separated list of types (as for parse_type),
   with the first type being the return type and the rest being the
   argument types.  */
static tree
parse_signature (const function_instance &instance, const char *format,
		 vec<tree> &argument_types, unsigned int max_args)
{
  tree return_type = parse_type (instance, format);
  unsigned int args = 0;
  while (format[0] == ',')
    {
      gcc_assert (args < max_args);
      format += 1;
      tree argument_type = parse_type (instance, format);
      argument_types.quick_push (argument_type);
      args += 1;
    }
  gcc_assert (format[0] == 0);
  return return_type;
}

/* Add one function instance for GROUP, using mode suffix MODE_SUFFIX_ID,
   the type suffixes at index TI and the predication suffix at index PI.
   The other arguments are as for build_all.  */
static void
build_one (function_builder &b, const char *signature,
	   const function_group_info &group, mode_suffix_index mode_suffix_id,
	   unsigned int ti, unsigned int pi, bool preserve_user_namespace,
	   bool force_direct_overloads)
{
  /* Current functions take at most five arguments.  Match
     parse_signature parameter below.  */
  auto_vec<tree, 5> argument_types;
  function_instance instance (group.base_name, *group.base, *group.shape,
			      mode_suffix_id, group.types[ti],
			      group.preds[pi]);
  tree return_type = parse_signature (instance, signature, argument_types, 5);
  apply_predication (instance, return_type, argument_types);
  b.add_unique_function (instance, return_type, argument_types,
			 preserve_user_namespace, group.requires_float,
			 force_direct_overloads);
}

/* Add a function instance for every type and predicate combination in
   GROUP, except if requested to use only the predicates listed in
   RESTRICT_TO_PREDS.  Take the function base name from GROUP and the
   mode suffix from MODE_SUFFIX_ID. Use SIGNATURE to construct the
   function signature, then use apply_predication to add in the
   predicate.  */
static void
build_all (function_builder &b, const char *signature,
	   const function_group_info &group, mode_suffix_index mode_suffix_id,
	   bool preserve_user_namespace,
	   bool force_direct_overloads = false,
	   const predication_index *restrict_to_preds = NULL)
{
  for (unsigned int pi = 0; group.preds[pi] != NUM_PREDS; ++pi)
    {
      unsigned int pi2 = 0;

      if (restrict_to_preds)
	for (; restrict_to_preds[pi2] != NUM_PREDS; ++pi2)
	  if (restrict_to_preds[pi2] == group.preds[pi])
	    break;

      if (restrict_to_preds == NULL || restrict_to_preds[pi2] != NUM_PREDS)
	for (unsigned int ti = 0;
	     ti == 0 || group.types[ti][0] != NUM_TYPE_SUFFIXES; ++ti)
	  build_one (b, signature, group, mode_suffix_id, ti, pi,
		     preserve_user_namespace, force_direct_overloads);
    }
}

/* Add a function instance for every type and predicate combination in
   GROUP, except if requested to use only the predicates listed in
   RESTRICT_TO_PREDS, and only for 16-bit and 32-bit integers.  Take
   the function base name from GROUP and the mode suffix from
   MODE_SUFFIX_ID. Use SIGNATURE to construct the function signature,
   then use apply_predication to add in the predicate.  */
static void
build_16_32 (function_builder &b, const char *signature,
	     const function_group_info &group, mode_suffix_index mode_suffix_id,
	     bool preserve_user_namespace,
	     bool force_direct_overloads = false,
	     const predication_index *restrict_to_preds = NULL)
{
  for (unsigned int pi = 0; group.preds[pi] != NUM_PREDS; ++pi)
    {
      unsigned int pi2 = 0;

      if (restrict_to_preds)
	for (; restrict_to_preds[pi2] != NUM_PREDS; ++pi2)
	  if (restrict_to_preds[pi2] == group.preds[pi])
	    break;

      if (restrict_to_preds == NULL || restrict_to_preds[pi2] != NUM_PREDS)
	for (unsigned int ti = 0;
	     ti == 0 || group.types[ti][0] != NUM_TYPE_SUFFIXES; ++ti)
	  {
	    unsigned int element_bits = type_suffixes[group.types[ti][0]].element_bits;
	    type_class_index tclass = type_suffixes[group.types[ti][0]].tclass;
	    if ((tclass == TYPE_signed || tclass == TYPE_unsigned)
		&& (element_bits == 16 || element_bits == 32))
	      build_one (b, signature, group, mode_suffix_id, ti, pi,
			 preserve_user_namespace, force_direct_overloads);
	  }
    }
}

/* Declare the function shape NAME, pointing it to an instance
   of class <NAME>_def.  */
#define SHAPE(NAME) \
  static CONSTEXPR const NAME##_def NAME##_obj; \
  namespace shapes { const function_shape *const NAME = &NAME##_obj; }

/* Base class for functions that are not overloaded.  */
struct nonoverloaded_base : public function_shape
{
  bool
  explicit_type_suffix_p (unsigned int, enum predication_index, enum mode_suffix_index) const override
  {
    return true;
  }

  bool
  explicit_mode_suffix_p (enum predication_index, enum mode_suffix_index) const override
  {
    return true;
  }

  bool
  skip_overload_p (enum predication_index, enum mode_suffix_index) const override
  {
    return false;
  }

  tree
  resolve (function_resolver &) const override
  {
    gcc_unreachable ();
  }
};

/* Base class for overloaded functions.  Bit N of EXPLICIT_MASK is true
   if type suffix N appears in the overloaded name.  */
template<unsigned int EXPLICIT_MASK>
struct overloaded_base : public function_shape
{
  bool
  explicit_type_suffix_p (unsigned int i, enum predication_index, enum mode_suffix_index) const override
  {
    return (EXPLICIT_MASK >> i) & 1;
  }

  bool
  explicit_mode_suffix_p (enum predication_index, enum mode_suffix_index) const override
  {
    return false;
  }

  bool
  skip_overload_p (enum predication_index, enum mode_suffix_index) const override
  {
    return false;
  }
};

/* <T0>_t vfoo[_t0](<T0>_t, <T0>_t)

   i.e. the standard shape for binary operations that operate on
   uniform types.

   Example: vandq.
   int8x16_t [__arm_]vandq[_s8](int8x16_t a, int8x16_t b)
   int8x16_t [__arm_]vandq_m[_s8](int8x16_t inactive, int8x16_t a, int8x16_t b, mve_pred16_t p)
   int8x16_t [__arm_]vandq_x[_s8](int8x16_t a, int8x16_t b, mve_pred16_t p)  */
struct binary_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v0,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_uniform (2);
  }
};
SHAPE (binary)

/* <T0>_t vfoo[_n_t0](<T0>_t, const int)

   Shape for vector shift right operations that take a vector first
   argument and an integer, and produce a vector.

   Check that 'imm' is in the [1..#bits] range.

   Example: vrshrq.
   int8x16_t [__arm_]vrshrq[_n_s8](int8x16_t a, const int imm)
   int8x16_t [__arm_]vrshrq_m[_n_s8](int8x16_t inactive, int8x16_t a, const int imm, mve_pred16_t p)
   int8x16_t [__arm_]vrshrq_x[_n_s8](int8x16_t a, const int imm, mve_pred16_t p)  */
struct binary_rshift_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "v0,v0,ss32", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_uniform (1, 1);
  }

  bool
  check (function_checker &c) const override
  {
    unsigned int bits = c.type_suffix (0).element_bits;
    return c.require_immediate_range (1, 1, bits);
  }
};
SHAPE (binary_rshift)


/* <uT0>_t vfoo[_t0](<uT0>_t, <T0>_t)

   i.e. binary operations that take a vector of unsigned elements as first argument and a
   vector of signed elements as second argument, and produce a vector of unsigned elements.

   Example: vminaq.
   uint8x16_t [__arm_]vminaq[_s8](uint8x16_t a, int8x16_t b)
   uint8x16_t [__arm_]vminaq_m[_s8](uint8x16_t a, int8x16_t b, mve_pred16_t p)  */
struct binary_maxamina_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "vu0,vu0,vs0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (i)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    /* Check that the first argument has the expeected unsigned
       type.  */
    type_suffix_index return_type
      = find_type_suffix (TYPE_unsigned, type_suffixes[type].element_bits);
    if (!r.require_matching_vector_type (0, return_type))
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }
};
SHAPE (binary_maxamina)

/* <uS0>_t vfoo[_<t0>](<uS0>_t, <T0>_t)

   Example: vmaxavq.
   uint8_t [__arm_]vmaxavq[_s8](uint8_t a, int8x16_t b)
   uint8_t [__arm_]vmaxavq_p[_s8](uint8_t a, int8x16_t b, mve_pred16_t p)  */
struct binary_maxavminav_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "su0,su0,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| !r.require_derived_scalar_type (0, TYPE_unsigned)
	|| (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }
};
SHAPE (binary_maxavminav)

/* <S0>_t vfoo[_<t0>](<S0>_t, <T0>_t)

   Example: vmaxvq.
   int8_t [__arm_]vmaxvq[_s8](int8_t a, int8x16_t b)
   int8_t [__arm_]vmaxvq_p[_s8](int8_t a, int8x16_t b, mve_pred16_t p)  */
struct binary_maxvminv_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "s0,s0,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| !r.require_derived_scalar_type (0, r.SAME_TYPE_CLASS)
	|| (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }
};
SHAPE (binary_maxvminv)

/* <T0:half>_t vfoo[_t0](<T0:half>_t, <T0>_t)

   Example: vmovnbq.
   int8x16_t [__arm_]vmovnbq[_s16](int8x16_t a, int16x8_t b)
   int8x16_t [__arm_]vmovnbq_m[_s16](int8x16_t a, int16x8_t b, mve_pred16_t p)  */
struct binary_move_narrow_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "vh0,vh0,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    type_suffix_index narrow_suffix
      = find_type_suffix (type_suffixes[type].tclass,
			  type_suffixes[type].element_bits / 2);


    if (!r.require_matching_vector_type (0, narrow_suffix))
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }
};
SHAPE (binary_move_narrow)

/* <uT0:half>_t vfoo[_t0](<uT0:half>_t, <T0>_t)

   Example: vqmovunbq.
   uint8x16_t [__arm_]vqmovunbq[_s16](uint8x16_t a, int16x8_t b)
   uint8x16_t [__arm_]vqmovunbq_m[_s16](uint8x16_t a, int16x8_t b, mve_pred16_t p)  */
struct binary_move_narrow_unsigned_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "vhu0,vhu0,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    type_suffix_index narrow_suffix
      = find_type_suffix (TYPE_unsigned,
			  type_suffixes[type].element_bits / 2);

    if (!r.require_matching_vector_type (0, narrow_suffix))
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }
};
SHAPE (binary_move_narrow_unsigned)

/* <T0>_t vfoo[_t0](<T0>_t, <T0>_t)
   <T0>_t vfoo[_n_t0](<T0>_t, <S0>_t)

   i.e. the standard shape for binary operations that operate on
   uniform types.

   Example: vaddq.
   int8x16_t [__arm_]vaddq[_s8](int8x16_t a, int8x16_t b)
   int8x16_t [__arm_]vaddq[_n_s8](int8x16_t a, int8_t b)
   int8x16_t [__arm_]vaddq_m[_s8](int8x16_t inactive, int8x16_t a, int8x16_t b, mve_pred16_t p)
   int8x16_t [__arm_]vaddq_m[_n_s8](int8x16_t inactive, int8x16_t a, int8_t b, mve_pred16_t p)
   int8x16_t [__arm_]vaddq_x[_s8](int8x16_t a, int8x16_t b, mve_pred16_t p)
   int8x16_t [__arm_]vaddq_x[_n_s8](int8x16_t a, int8_t b, mve_pred16_t p)  */
struct binary_opt_n_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v0,v0", group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v0,s0", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_uniform_opt_n (2);
  }
};
SHAPE (binary_opt_n)

/* <T0>_t vfoo[t0](<T0>_t, <T0>_t)
   <T0>_t vfoo[_n_t0](<T0>_t, <S0>_t)

   Where the _n form only supports s16/s32/u16/u32 types as for vorrq.

   Example: vorrq.
   int16x8_t [__arm_]vorrq[_s16](int16x8_t a, int16x8_t b)
   int16x8_t [__arm_]vorrq_m[_s16](int16x8_t inactive, int16x8_t a, int16x8_t b, mve_pred16_t p)
   int16x8_t [__arm_]vorrq_x[_s16](int16x8_t a, int16x8_t b, mve_pred16_t p)
   int16x8_t [__arm_]vorrq[_n_s16](int16x8_t a, const int16_t imm)
   int16x8_t [__arm_]vorrq_m_n[_s16](int16x8_t a, const int16_t imm, mve_pred16_t p)  */
struct binary_orrq_def : public overloaded_base<0>
{
  bool
  explicit_mode_suffix_p (enum predication_index pred, enum mode_suffix_index mode) const override
  {
    return (mode == MODE_n
	    && pred == PRED_m);
  }

  bool
  skip_overload_p (enum predication_index pred, enum mode_suffix_index mode) const override
  {
    switch (mode)
      {
      case MODE_none:
	return false;

	/* For MODE_n, share the overloaded instance with MODE_none, except for PRED_m.  */
      case MODE_n:
	return pred != PRED_m;

      default:
	gcc_unreachable ();
      }
  }

  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "v0,v0,v0", group, MODE_none, preserve_user_namespace);
    build_16_32 (b, "v0,v0,s0", group, MODE_n, preserve_user_namespace, false, preds_m_or_none);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (0)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    return r.finish_opt_n_resolution (i, 0, type);
  }
};
SHAPE (binary_orrq)

/* <T0>_t vfoo[t0](<T0>_t, <T0>_t)
   <T0>_t vfoo[_n_t0](<T0>_t, int32_t)

   Shape for rounding shift left operations.

   Example: vrshlq.
   int8x16_t [__arm_]vrshlq[_n_s8](int8x16_t a, int32_t b)
   int8x16_t [__arm_]vrshlq_m_n[_s8](int8x16_t a, int32_t b, mve_pred16_t p)
   int8x16_t [__arm_]vrshlq[_s8](int8x16_t a, int8x16_t b)
   int8x16_t [__arm_]vrshlq_m[_s8](int8x16_t inactive, int8x16_t a, int8x16_t b, mve_pred16_t p)
   int8x16_t [__arm_]vrshlq_x[_s8](int8x16_t a, int8x16_t b, mve_pred16_t p)  */
struct binary_round_lshift_def : public overloaded_base<0>
{
  bool
  explicit_mode_suffix_p (enum predication_index pred, enum mode_suffix_index mode) const override
  {
    return ((mode == MODE_n)
	    && (pred == PRED_m));
  }

  bool
  skip_overload_p (enum predication_index pred, enum mode_suffix_index mode) const override
  {
    switch (mode)
      {
      case MODE_none:
	return false;

	/* For MODE_n, share the overloaded instance with MODE_none, except for PRED_m.  */
      case MODE_n:
	return pred != PRED_m;

      default:
	gcc_unreachable ();
      }
  }

  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "v0,v0,vs0", group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v0,ss32", group, MODE_n, preserve_user_namespace, false, preds_m_or_none);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (0)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    return r.finish_opt_n_resolution (i, 0, type, TYPE_signed);
  }
};
SHAPE (binary_round_lshift)

/* <T0>_t vfoo[_t0](<T0>_t, <T0>_t)
   <T0>_t vfoo_n[_t0](<T0>_t, const int)

   i.e. the standard shape for left shift operations that operate on
   vector types.

   For the MODE_n versions, check that 'imm' is in the [0..#bits-1] range.

   Example: vshlq.
   int8x16_t [__arm_]vshlq[_s8](int8x16_t a, int8x16_t b)
   int8x16_t [__arm_]vshlq_m[_s8](int8x16_t inactive, int8x16_t a, int8x16_t b, mve_pred16_t p)
   int8x16_t [__arm_]vshlq_x[_s8](int8x16_t a, int8x16_t b, mve_pred16_t p)
   int8x16_t [__arm_]vshlq_n[_s8](int8x16_t a, const int imm)
   int8x16_t [__arm_]vshlq_m_n[_s8](int8x16_t inactive, int8x16_t a, const int imm, mve_pred16_t p)
   int8x16_t [__arm_]vshlq_x_n[_s8](int8x16_t a, const int imm, mve_pred16_t p)  */
struct binary_lshift_def : public overloaded_base<0>
{
  bool
  explicit_mode_suffix_p (enum predication_index, enum mode_suffix_index) const override
  {
    return true;
  }

  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "v0,v0,vs0", group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v0,ss32", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (0)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    return r.finish_opt_n_resolution (i, 0, type, TYPE_signed);
  }

  bool
  check (function_checker &c) const override
  {
    if (c.mode_suffix_id != MODE_n)
      return true;

    unsigned int bits = c.type_suffix (0).element_bits;
    return c.require_immediate_range (1, 0, bits - 1);
  }
};
SHAPE (binary_lshift)

/* Used with the above form, but only for the MODE_r case which does
   not always support the same set of predicates as MODE_none and
   MODE_n.  For vqshlq they are the same, but for vshlq they are not.

   <T0>_t vfoo_r[_t0](<T0>_t, int32_t)

   i.e. the standard shape for shift operations that operate on
   vector types.
   Example: vshlq.
   int8x16_t [__arm_]vshlq_r[_s8](int8x16_t a, int32_t b)
   int8x16_t [__arm_]vshlq_m_r[_s8](int8x16_t a, int32_t b, mve_pred16_t p)  */
struct binary_lshift_r_def : public overloaded_base<0>
{
  bool
  explicit_mode_suffix_p (enum predication_index, enum mode_suffix_index) const override
  {
    return true;
  }

  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_r, preserve_user_namespace);
    build_all (b, "v0,v0,ss32", group, MODE_r, preserve_user_namespace, false, preds_m_or_none);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (0)) == NUM_TYPE_SUFFIXES)
      return error_mark_node;

    return r.finish_opt_n_resolution (i, 0, type, TYPE_signed);
  }
};
SHAPE (binary_lshift_r)

/* <T0:half>_t vfoo[_n_t0](<T0:half>_t, <T0>_t, const int)

   Narrowing right shifts.
   Check that 'imm' is in the [1..#bits/2] range.

   Example: vqrshrnbq.
   int8x16_t [__arm_]vqrshrnbq[_n_s16](int8x16_t a, int16x8_t b, const int imm)
   int8x16_t [__arm_]vqrshrnbq_m[_n_s16](int8x16_t a, int16x8_t b, const int imm, mve_pred16_t p)  */
struct binary_rshift_narrow_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "vh0,vh0,v0,ss32", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (3, i, nargs)
	|| (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES
	|| !r.require_integer_immediate (i))
      return error_mark_node;

    type_suffix_index narrow_suffix
      = find_type_suffix (type_suffixes[type].tclass,
			  type_suffixes[type].element_bits / 2);

    if (!r.require_matching_vector_type (0, narrow_suffix))
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }

  bool
  check (function_checker &c) const override
  {
    unsigned int bits = c.type_suffix (0).element_bits;
    return c.require_immediate_range (2, 1, bits / 2);
  }
};
SHAPE (binary_rshift_narrow)

/* <uT0:half>_t vfoo[_n_t0](<uT0:half>_t, <T0>_t, const int)

   Vector saturating rounding shift right and narrow.
   Check that 'imm' is in the [1..#bits/2] range.

   Example: vqshrunbq.
   uint8x16_t [__arm_]vqshrunbq[_n_s16](uint8x16_t a, int16x8_t b, const int imm)
   uint8x16_t [__arm_]vqshrunbq_m[_n_s16](uint8x16_t a, int16x8_t b, const int imm, mve_pred16_t p)  */
struct binary_rshift_narrow_unsigned_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "vhu0,vhu0,v0,ss32", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    if (!r.check_gp_argument (3, i, nargs)
	|| (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES
	|| !r.require_integer_immediate (i))
      return error_mark_node;

    type_suffix_index narrow_suffix
      = find_type_suffix (TYPE_unsigned,
			  type_suffixes[type].element_bits / 2);

    if (!r.require_matching_vector_type (0, narrow_suffix))
      return error_mark_node;

    return r.resolve_to (r.mode_suffix_id, type);
  }

  bool
  check (function_checker &c) const override
  {
    unsigned int bits = c.type_suffix (0).element_bits;
    return c.require_immediate_range (2, 1, bits / 2);
  }

};
SHAPE (binary_rshift_narrow_unsigned)

/* <T0:twice>_t vfoo[_n_t0](<T0>_t, const int)

   Check that 'imm' is in the [1..#bits] range.

   Example: vshllbq.
   int16x8_t [__arm_]vshllbq[_n_s8](int8x16_t a, const int imm)
   int16x8_t [__arm_]vshllbq_m[_n_s8](int16x8_t inactive, int8x16_t a, const int imm, mve_pred16_t p)
   int16x8_t [__arm_]vshllbq_x[_n_s8](int8x16_t a, const int imm, mve_pred16_t p)  */
struct binary_widen_n_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "vw0,v0,s0", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    unsigned int i, nargs;
    type_suffix_index type;
    tree res;
    if (!r.check_gp_argument (2, i, nargs)
	|| (type = r.infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES
	|| !r.require_integer_immediate (i))
      return error_mark_node;

    type_suffix_index wide_suffix
      = find_type_suffix (type_suffixes[type].tclass,
			  type_suffixes[type].element_bits * 2);

    /* Check the inactive argument has the wide type.  */
    if (((r.pred == PRED_m) && (r.infer_vector_type (0) == wide_suffix))
	|| r.pred == PRED_none
	|| r.pred == PRED_x)
      if ((res = r.lookup_form (r.mode_suffix_id, type)))
	return res;

    return r.report_no_such_form (type);
  }

  bool
  check (function_checker &c) const override
  {
    unsigned int bits = c.type_suffix (0).element_bits;
    return c.require_immediate_range (1, 1, bits);
  }

};
SHAPE (binary_widen_n)

/* Shape for comparison operations that operate on
   uniform types.

   Examples: vcmpq.
   mve_pred16_t [__arm_]vcmpeqq[_s16](int16x8_t a, int16x8_t b)
   mve_pred16_t [__arm_]vcmpeqq[_n_s16](int16x8_t a, int16_t b)
   mve_pred16_t [__arm_]vcmpeqq_m[_s16](int16x8_t a, int16x8_t b, mve_pred16_t p)
   mve_pred16_t [__arm_]vcmpeqq_m[_n_s16](int16x8_t a, int16_t b, mve_pred16_t p)  */
struct cmp_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "p,v0,v0", group, MODE_none, preserve_user_namespace);
    build_all (b, "p,v0,s0", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_uniform_opt_n (2);
  }
};
SHAPE (cmp)

/* <T0>xN_t vfoo[_t0](uint64_t, uint64_t)

   where there are N arguments in total.
   Example: vcreateq.
   int16x8_t [__arm_]vcreateq_s16(uint64_t a, uint64_t b)  */
struct create_def : public nonoverloaded_base
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    build_all (b, "v0,su64,su64", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_uniform (0, 2);
  }
};
SHAPE (create)

/* <T0>[xN]_t vfoo_t0().

   Example: vuninitializedq.
   int8x16_t [__arm_]vuninitializedq_s8(void)
   int8x16_t [__arm_]vuninitializedq(int8x16_t t)  */
struct inherent_def : public nonoverloaded_base
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    build_all (b, "t0", group, MODE_none, preserve_user_namespace);
  }
};
SHAPE (inherent)

/* <T0>_t vfoo[_t0](<T0>_t)

   i.e. the standard shape for unary operations that operate on
   uniform types.

   Example: vabsq.
   int8x16_t [__arm_]vabsq[_s8](int8x16_t a)
   int8x16_t [__arm_]vabsq_m[_s8](int8x16_t inactive, int8x16_t a, mve_pred16_t p)
   int8x16_t [__arm_]vabsq_x[_s8](int8x16_t a, mve_pred16_t p)  */
struct unary_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_unary ();
  }
};
SHAPE (unary)

/* <T0>_t foo_t0[_t1](<T1>_t)

   where the target type <t0> must be specified explicitly but the source
   type <t1> can be inferred.

   Example: vreinterpretq.
   int16x8_t [__arm_]vreinterpretq_s16[_s8](int8x16_t a)
   int32x4_t [__arm_]vreinterpretq_s32[_s8](int8x16_t a)
   int8x16_t [__arm_]vreinterpretq_s8[_s16](int16x8_t a)
   int8x16_t [__arm_]vreinterpretq_s8[_s32](int32x4_t a)  */
struct unary_convert_def : public overloaded_base<1>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "v0,v1", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_unary ();
  }
};
SHAPE (unary_convert)

/* [u]int32_t vfoo[_<t0>](<T0>_t)

   i.e. a version of "unary" which generates a scalar of type int32_t
   or uint32_t depending on the signedness of the elements of of input
   vector.

   Example: vaddvq
   int32_t [__arm_]vaddvq[_s16](int16x8_t a)
   int32_t [__arm_]vaddvq_p[_s16](int16x8_t a, mve_pred16_t p)  */
struct unary_int32_def : public overloaded_base<0>
{
  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_none, preserve_user_namespace);
    build_all (b, "sx32,v0", group, MODE_none, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_uniform (1);
  }
};
SHAPE (unary_int32)

/* <T0>_t vfoo[_n]_t0(<S0>_t)

   Example: vdupq.
   int16x8_t [__arm_]vdupq_n_s16(int16_t a)
   int16x8_t [__arm_]vdupq_m[_n_s16](int16x8_t inactive, int16_t a, mve_pred16_t p)
   int16x8_t [__arm_]vdupq_x_n_s16(int16_t a, mve_pred16_t p)  */
struct unary_n_def : public overloaded_base<0>
{
  bool
  explicit_type_suffix_p (unsigned int, enum predication_index pred,
			  enum mode_suffix_index) const override
  {
    return pred != PRED_m;
  }

  bool
  explicit_mode_suffix_p (enum predication_index pred,
			  enum mode_suffix_index mode) const override
  {
    return ((mode == MODE_n)
	    && (pred != PRED_m));
  }

  bool
  skip_overload_p (enum predication_index pred, enum mode_suffix_index mode)
    const override
  {
    switch (mode)
      {
      case MODE_n:
	return pred != PRED_m;

      default:
	gcc_unreachable ();
      }
  }

  void
  build (function_builder &b, const function_group_info &group,
	 bool preserve_user_namespace) const override
  {
    b.add_overloaded_functions (group, MODE_n, preserve_user_namespace);
    build_all (b, "v0,s0", group, MODE_n, preserve_user_namespace);
  }

  tree
  resolve (function_resolver &r) const override
  {
    return r.resolve_unary_n ();
  }
};
SHAPE (unary_n)

} /* end namespace arm_mve */

#undef SHAPE