1 /*========================== begin_copyright_notice ============================
2 
3 Copyright (C) 2017-2021 Intel Corporation
4 
5 SPDX-License-Identifier: MIT
6 
7 ============================= end_copyright_notice ===========================*/
8 
9 #ifndef _IGA_TYPES_SWSB_HPP
10 #define _IGA_TYPES_SWSB_HPP
11 
12 #include <stdint.h>
13 
14 namespace iga
15 {
16     enum class SWSB_STATUS
17     {
18         SUCCESS,
19         ERROR_SET_ON_VARIABLE_LENGTH_ONLY,
20         ERROR_INVALID_SBID_VALUE,
21         ERROR_ENCODE_MODE, // invalid encoding mode
22         UNKNOWN_INST_TYPE,
23         ERROR_DECODE,
24         NONE
25     };
26 
27     enum class SWSB_ENCODE_MODE : uint32_t
28     {
29         SWSBInvalidMode       = 0,
30         SingleDistPipe        = 1, // Xe: 1 distance pipe
31         ThreeDistPipe         = 2, // XeHP/XeHPG: 3 distance pipe
32         FourDistPipe          = 3, // XeHPC (early variant): 4 distance pipes
33         FourDistPipeReduction = 6, // XeHPC variation: 4 distance pipes with Long pipe reduction
34     };
35 
36     struct SWSB
37     {
38     public:
39         enum class DistType {
40             NO_DIST,
41             REG_DIST,
42             REG_DIST_ALL,
43             REG_DIST_FLOAT,
44             REG_DIST_INT,
45             REG_DIST_LONG,
46             REG_DIST_MATH,  // XeHPC
47         };
48 
49         enum class TokenType {
50             NOTOKEN,
51             SET,
52             SRC,
53             DST
54         };
55 
56         enum class InstType {
57             UNKNOWN,
58             DPAS,
59             MATH,
60             SEND,
61             OTHERS
62         };
63 
64         enum class SpecialToken {
65             NONE,
66             NOACCSBSET       // XeHPC
67         };
68 
69     public:
70         DistType     distType;
71         TokenType    tokenType;
72         uint32_t     minDist;     // distance to nearest register dependency
73         uint32_t     sbid;        // swsb id. the barrier identifier (sbid) applies to all wait's
74         SpecialToken spToken;
75 
SWSBiga::SWSB76         constexpr SWSB()
77             : distType(DistType::NO_DIST)
78             , tokenType(TokenType::NOTOKEN)
79             , minDist(0)
80             , sbid(0)
81             , spToken(SpecialToken::NONE)
82         { }
83 
SWSBiga::SWSB84         constexpr SWSB(DistType dt, TokenType tt, uint32_t dis, uint32_t id)
85             : distType(dt), tokenType(tt), minDist(dis), sbid(id), spToken(SpecialToken::NONE)
86         { }
87 
SWSBiga::SWSB88         constexpr SWSB(SpecialToken st)
89             : distType(DistType::NO_DIST), tokenType(TokenType::NOTOKEN), minDist(0), sbid(0), spToken(st)
90         { }
91 
operator ==iga::SWSB92         constexpr bool operator==(const SWSB& rhs) const {
93             return distType == rhs.distType && tokenType == rhs.tokenType &&
94                 sbid == rhs.sbid && minDist == rhs.minDist && spToken == rhs.spToken;
95         }
96 
operator !=iga::SWSB97         constexpr bool operator!=(const SWSB& rhs) const {
98             return !(*this == rhs);
99         }
100 
hasSWSBiga::SWSB101         constexpr bool hasSWSB() const {
102             return (distType != DistType::NO_DIST)   ||
103                    (tokenType != TokenType::NOTOKEN) ||
104                    (spToken != SpecialToken::NONE);
105         }
106 
hasBothDistAndTokeniga::SWSB107         constexpr bool hasBothDistAndToken() const {
108             return (distType != DistType::NO_DIST) &&
109                 (tokenType != TokenType::NOTOKEN);
110         }
111 
hasDistiga::SWSB112         constexpr bool hasDist() const {
113             return distType != DistType::NO_DIST;
114         }
115 
116         // if this swsb has token, not including SpecialToken
hasTokeniga::SWSB117         constexpr bool hasToken() const {
118             return tokenType != TokenType::NOTOKEN;
119         }
120 
hasSpecialTokeniga::SWSB121         constexpr bool hasSpecialToken() const {
122             return spToken != SpecialToken::NONE;
123         }
124 
isMathPipeInOrderiga::SWSB125         constexpr static bool isMathPipeInOrder(SWSB_ENCODE_MODE enMode) {
126             return
127                 enMode == SWSB_ENCODE_MODE::FourDistPipe ||
128                 enMode == SWSB_ENCODE_MODE::FourDistPipeReduction;
129         }
130 
131         /// decode swsb info to SWSB from the raw encoding into this object
132         SWSB_STATUS decode(
133             uint32_t swsbBits,
134             SWSB_ENCODE_MODE enMode,
135             InstType instTy);
136 
137         /// encode - encode swsb to bianry
138         uint32_t encode(SWSB_ENCODE_MODE enMode, InstType instTy) const;
139 
140         /// same as encode (for backwards compatibility)
getSWSBBinaryiga::SWSB141         uint32_t getSWSBBinary(SWSB_ENCODE_MODE enMode, InstType instTy) const {
142             return encode(enMode, instTy);
143         }
144 
145         /// verify - verify if the SWSB is in the correct combination
146         /// according to given instruction type and encoding mode
147         /// return true on pass, false on fail
148         bool verify(SWSB_ENCODE_MODE enMode, InstType instTy) const;
149 
150     private:
151         /// verifySpecialToken - a helper function to verify if the specialToken is valid
152         /// Should only be called when hasSpecialToken is true
153         /// return true on pass, false on fail
154         bool verifySpecialToken(SWSB_ENCODE_MODE enMode) const;
155 
156         // clear all fields
157         void clear();
158 
159         template<SWSB_ENCODE_MODE M>
160         SWSB_STATUS decode(uint32_t swsbBits, InstType instTy);
161 
162         template<SWSB_ENCODE_MODE M>
163         uint32_t encode(InstType instTy) const;
164 
165         template<SWSB_ENCODE_MODE M>
166         bool verify(InstType instTy) const;
167 
168     };
169 } // namespace iga
170 #endif //#ifndef _IGA_TYPES_SWSB_HPP
171