]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/vec-perm-indices.c
Remove vec_perm_const optab
[thirdparty/gcc.git] / gcc / vec-perm-indices.c
CommitLineData
f151c9e1
RS
1/* A representation of vector permutation indices.
2 Copyright (C) 2017 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#include "config.h"
21#include "system.h"
22#include "coretypes.h"
23#include "vec-perm-indices.h"
24#include "tree.h"
25#include "backend.h"
26#include "rtl.h"
27#include "memmodel.h"
28#include "emit-rtl.h"
29
30/* Switch to a new permutation vector that selects the same input elements
31 as ORIG, but with each element split into FACTOR pieces. For example,
32 if ORIG is { 1, 2, 0, 3 } and FACTOR is 2, the new permutation is
33 { 2, 3, 4, 5, 0, 1, 6, 7 }. */
34
35void
36vec_perm_indices::new_expanded_vector (const vec_perm_indices &orig,
37 unsigned int factor)
38{
39 truncate (0);
40 reserve (orig.length () * factor);
41 for (unsigned int i = 0; i < orig.length (); ++i)
42 {
43 element_type base = orig[i] * factor;
44 for (unsigned int j = 0; j < factor; ++j)
45 quick_push (base + j);
46 }
47}
48
49/* Return true if all elements of the permutation vector are in the range
50 [START, START + SIZE). */
51
52bool
53vec_perm_indices::all_in_range_p (element_type start, element_type size) const
54{
55 for (unsigned int i = 0; i < length (); ++i)
56 if ((*this)[i] < start || ((*this)[i] - start) >= size)
57 return false;
58 return true;
59}
60
61/* Try to read the contents of VECTOR_CST CST as a constant permutation
62 vector. Return true and add the elements to BUILDER on success,
63 otherwise return false without modifying BUILDER. */
64
65bool
66tree_to_vec_perm_builder (vec_perm_builder *builder, tree cst)
67{
68 unsigned int nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (cst));
69 for (unsigned int i = 0; i < nelts; ++i)
70 if (!tree_fits_shwi_p (vector_cst_elt (cst, i)))
71 return false;
72
73 builder->reserve (nelts);
74 for (unsigned int i = 0; i < nelts; ++i)
75 builder->quick_push (tree_to_shwi (vector_cst_elt (cst, i))
76 & (2 * nelts - 1));
77 return true;
78}
79
80/* Return a CONST_VECTOR of mode MODE that contains the elements of
81 INDICES. */
82
83rtx
84vec_perm_indices_to_rtx (machine_mode mode, const vec_perm_indices &indices)
85{
86 gcc_assert (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
87 && GET_MODE_NUNITS (mode) == indices.length ());
88 unsigned int nelts = indices.length ();
89 rtvec v = rtvec_alloc (nelts);
90 for (unsigned int i = 0; i < nelts; ++i)
91 RTVEC_ELT (v, i) = gen_int_mode (indices[i], GET_MODE_INNER (mode));
92 return gen_rtx_CONST_VECTOR (mode, v);
93}