GCC Middle and Back End API Reference
vec-perm-indices.h
Go to the documentation of this file.
1/* A representation of vector permutation indices.
2 Copyright (C) 2017-2026 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_VEC_PERN_INDICES_H
21#define GCC_VEC_PERN_INDICES_H 1
22
23#include "int-vector-builder.h"
24
25/* A vector_builder for building constant permutation vectors.
26 The elements do not need to be clamped to a particular range
27 of input elements. */
29
30/* This class represents a constant permutation vector, such as that used
31 as the final operand to a VEC_PERM_EXPR.
32
33 Permutation vectors select indices modulo the number of input elements,
34 and the class canonicalizes each permutation vector for a particular
35 number of input vectors and for a particular number of elements per
36 input. For example, the gimple statements:
37
38 _1 = VEC_PERM_EXPR <a, a, { 0, 2, 4, 6, 0, 2, 4, 6 }>;
39 _2 = VEC_PERM_EXPR <a, a, { 0, 2, 4, 6, 8, 10, 12, 14 }>;
40 _3 = VEC_PERM_EXPR <a, a, { 0, 2, 20, 22, 24, 2, 4, 14 }>;
41
42 effectively have only a single vector input "a". If "a" has 8
43 elements, the indices select elements modulo 8, which makes all three
44 VEC_PERM_EXPRs equivalent. The canonical form is for the indices to be
45 in the range [0, number of input elements - 1], so the class treats the
46 second and third permutation vectors as though they had been the first.
47
48 The class copes with cases in which the input and output vectors have
49 different numbers of elements. */
51{
53
54public:
56 vec_perm_indices (const vec_perm_builder &, unsigned int, poly_uint64);
57
58 void new_vector (const vec_perm_builder &b, unsigned int ni, poly_uint64 ne)
59 {
60 new_vector (b, ni, false, false, ne);
61 }
62 void new_vector (const vec_perm_builder &, unsigned int, bool, bool,
64 void new_expanded_vector (const vec_perm_indices &, unsigned int);
65 bool new_shrunk_vector (const vec_perm_indices &, unsigned int);
66 void rotate_inputs (int delta);
67
68 /* Return the underlying vector encoding. */
69 const vec_perm_builder &encoding () const { return m_encoding; }
70
71 /* Return the number of output elements. This is called length ()
72 so that we present a more vec-like interface. */
73 poly_uint64 length () const { return m_encoding.full_nelts (); }
74
75 /* Return the number of input vectors being permuted. */
76 unsigned int ninputs () const { return m_ninputs; }
77
78 /* Return whether the input N is known bitwise zero. */
79 bool input_bitwise_zero_p (unsigned n) const
80 {
81 return (n == 0 ? m_input0_bitwise_zero_p
82 : (n == 1 ? m_input1_bitwise_zero_p : false));
83 }
84
85 /* Return the number of elements in each input vector. */
87
88 /* Return the total number of input elements. */
90
92 element_type operator[] (unsigned int i) const;
93 bool series_p (unsigned int, unsigned int, element_type, element_type) const;
95 bool all_from_input_p (unsigned int) const;
96
97private:
99
101 unsigned int m_ninputs;
105};
106
110rtx vec_perm_indices_to_rtx (machine_mode, const vec_perm_indices &);
111
112inline
120
121/* Construct a permutation vector that selects between NINPUTS vector
122 inputs that have NELTS_PER_INPUT elements each. Take the elements of
123 the new vector from ELEMENTS, clamping each one to be in range. */
124
125inline
127 unsigned int ninputs,
129{
130 new_vector (elements, ninputs, false, false, nelts_per_input);
131}
132
133/* Return the canonical value for permutation vector element ELT,
134 taking into account the current number of input elements. */
135
138{
139 element_type limit = input_nelts (), elem_within_input;
140 HOST_WIDE_INT input;
141 if (!can_div_trunc_p (elt, limit, &input, &elem_within_input))
142 return elt;
143
144 /* Treat negative elements as counting from the end. This only matters
145 if the vector size is not a power of 2. */
146 if (known_lt (elem_within_input, 0))
147 return elem_within_input + limit;
148
149 return elem_within_input;
150}
151
152/* Return the value of vector element I, which might or might not be
153 explicitly encoded. */
154
157{
158 return clamp (m_encoding.elt (i));
159}
160
161/* Return true if the permutation vector only selects elements from
162 input I. */
163
164inline bool
169
170#endif
Definition int-vector-builder.h:31
Definition vec-perm-indices.h:51
bool input_bitwise_zero_p(unsigned n) const
Definition vec-perm-indices.h:79
void new_vector(const vec_perm_builder &b, unsigned int ni, poly_uint64 ne)
Definition vec-perm-indices.h:58
bool m_input1_bitwise_zero_p
Definition vec-perm-indices.h:103
bool series_p(unsigned int, unsigned int, element_type, element_type) const
Definition vec-perm-indices.cc:197
bool m_input0_bitwise_zero_p
Definition vec-perm-indices.h:102
poly_uint64 m_nelts_per_input
Definition vec-perm-indices.h:104
poly_int64 element_type
Definition vec-perm-indices.h:52
bool all_in_range_p(element_type, element_type) const
Definition vec-perm-indices.cc:244
unsigned int ninputs() const
Definition vec-perm-indices.h:76
void rotate_inputs(int delta)
Definition vec-perm-indices.cc:175
const vec_perm_builder & encoding() const
Definition vec-perm-indices.h:69
poly_uint64 nelts_per_input() const
Definition vec-perm-indices.h:86
bool all_from_input_p(unsigned int) const
Definition vec-perm-indices.h:165
vec_perm_indices(const vec_perm_indices &)
void new_expanded_vector(const vec_perm_indices &, unsigned int)
Definition vec-perm-indices.cc:91
poly_uint64 input_nelts() const
Definition vec-perm-indices.h:89
unsigned int m_ninputs
Definition vec-perm-indices.h:101
poly_uint64 length() const
Definition vec-perm-indices.h:73
element_type operator[](unsigned int i) const
Definition vec-perm-indices.h:156
bool new_shrunk_vector(const vec_perm_indices &, unsigned int)
Definition vec-perm-indices.cc:121
vec_perm_indices()
Definition vec-perm-indices.h:113
vec_perm_builder m_encoding
Definition vec-perm-indices.h:100
element_type clamp(element_type) const
Definition vec-perm-indices.h:137
struct rtx_def * rtx
Definition coretypes.h:57
union tree_node * tree
Definition coretypes.h:97
poly_int< NUM_POLY_INT_COEFFS, unsigned HOST_WIDE_INT > poly_uint64
Definition poly-int-types.h:25
poly_int< NUM_POLY_INT_COEFFS, HOST_WIDE_INT > poly_int64
Definition poly-int-types.h:24
i
Definition poly-int.h:776
#define known_lt(A, B)
Ca const poly_int< N, Cb > & b
Definition poly-int.h:771
#define false
Definition system.h:894
bool tree_to_vec_perm_builder(vec_perm_builder *, tree)
Definition vec-perm-indices.cc:296
bool tree_to_vec_perm_indices(vec_perm_indices *, tree, tree, tree)
Definition vec-perm-indices.cc:316
int_vector_builder< poly_int64 > vec_perm_builder
Definition vec-perm-indices.h:28
tree vec_perm_indices_to_tree(tree, const vec_perm_indices &)
Definition vec-perm-indices.cc:332
rtx vec_perm_indices_to_rtx(machine_mode, const vec_perm_indices &)
Definition vec-perm-indices.cc:347