1/*******************************************************************************
2* Copyright 2022 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef GPU_JIT_IR_GRF_PERMUTATION_HPP
18#define GPU_JIT_IR_GRF_PERMUTATION_HPP
19
20#include <array>
21
22#include "gpu/jit/utils/utils.hpp"
23
24namespace dnnl {
25namespace impl {
26namespace gpu {
27namespace jit {
28
29// Helper class to permute registers. Used to permute registers after applying
30// dpas -> dpasw transformation.
31class grf_permutation_t {
32public:
33 grf_permutation_t() { permutation_.fill(-1); }
34
35 int map(int off) const {
36 ir_assert(off >= 0 && off < max_regs);
37 if (permutation_[off] == -1) return off;
38 return permutation_[off];
39 }
40
41 bool is_empty() const { return is_empty_; }
42
43 void set_permute(int old_off, int new_off) {
44 ir_assert(old_off >= 0 && old_off < max_regs);
45 if (old_off == new_off || new_off == -1) return;
46 is_empty_ = false;
47 ir_assert(permutation_[old_off] == -1) << "Already assigned.";
48 permutation_[old_off] = new_off;
49 }
50
51 bool operator==(const grf_permutation_t &other) const {
52 for (int i = 0; i < max_regs; i++) {
53 if (permutation_[i] != other.permutation_[i]) return false;
54 }
55 return true;
56 }
57
58 bool operator!=(const grf_permutation_t &other) const {
59 return !operator==(other);
60 }
61
62private:
63 static const int max_regs = 256;
64
65 std::array<int, max_regs> permutation_;
66 bool is_empty_ = true;
67};
68
69} // namespace jit
70} // namespace gpu
71} // namespace impl
72} // namespace dnnl
73
74#endif
75