ptx_parser/type/instruction/atom.rs
1//! Original PTX specification:
2//!
3//! // Atomic operation with scalar type:
4//! atom{.sem}{.scope}{.space}.op{.level::cache_hint}.type d, [a], b{, cache-policy};
5//! atom{.sem}{.scope}{.space}.op.type d, [a], b, c;
6//! atom{.sem}{.scope}{.space}.cas.b16 d, [a], b, c;
7//! atom{.sem}{.scope}{.space}.cas.b128 d, [a], b, c;
8//! atom{.sem}{.scope}{.space}.exch{.level::cache_hint}.b128 d, [a], b {, cache-policy};
9//! atom{.sem}{.scope}{.space}.add.noftz{.level::cache_hint}.f16 d, [a], b{, cache-policy};
10//! atom{.sem}{.scope}{.space}.add.noftz{.level::cache_hint}.f16x2 d, [a], b{, cache-policy};
11//! atom{.sem}{.scope}{.space}.add.noftz{.level::cache_hint}.bf16 d, [a], b{, cache-policy};
12//! atom{.sem}{.scope}{.space}.add.noftz{.level::cache_hint}.bf16x2 d, [a], b{, cache-policy};
13//! .space = { .global, .shared, .shared::cta, .shared::cluster};
14//! .sem = { .relaxed, .acquire, .release, .acq_rel };
15//! .scope = { .cta, .cluster, .gpu, .sys };
16//! .op = { .and, .or, .xor, .cas, .exch, .add, .inc, .dec, .min, .max };
17//! .level::cache_hint = { .L2::cache_hint };
18//! .type = { .b32, .b64, .u32, .u64, .s32, .s64, .f32, .f64 };
19//! -------------------------------------------------------------
20//! // Atomic operation with vector type:
21//! atom{.sem}{.scope}{.global}.add{.level::cache_hint}.vec_32_bit.f32 d, [a], b{, cache-policy};
22//! atom{.sem}{.scope}{.global}.op.noftz{.level::cache_hint}.vec_16_bit.half_word_type d, [a], b{, cache-policy};
23//! atom{.sem}{.scope}{.global}.op.noftz{.level::cache_hint}.vec_32_bit.packed_type d, [a], b{, cache-policy};
24//! .sem = { .relaxed, .acquire, .release, .acq_rel };
25//! .scope = { .cta, .cluster, .gpu, .sys };
26//! .op = { .add, .min, .max };
27//! .half_word_type = { .f16, .bf16 };
28//! .packed_type = { .f16x2, .bf16x2 };
29//! .vec_16_bit = { .v2, .v4, .v8 };
30//! .vec_32_bit = { .v2, .v4 };
31//! .level::cache_hint = { .L2::cache_hint };
32
33#![allow(unused)]
34use crate::r#type::common::*;
35
36pub mod section_0 {
37 use crate::Spanned;
38 use crate::parser::Span;
39 use crate::r#type::common::*;
40
41 use serde::Serialize;
42
43 #[derive(Debug, Clone, PartialEq, Serialize)]
44 pub enum Sem {
45 Relaxed, // .relaxed
46 Acquire, // .acquire
47 Release, // .release
48 AcqRel, // .acq_rel
49 }
50
51 #[derive(Debug, Clone, PartialEq, Serialize)]
52 pub enum Scope {
53 Cluster, // .cluster
54 Cta, // .cta
55 Gpu, // .gpu
56 Sys, // .sys
57 }
58
59 #[derive(Debug, Clone, PartialEq, Serialize)]
60 pub enum Space {
61 SharedCluster, // .shared::cluster
62 SharedCta, // .shared::cta
63 Global, // .global
64 Shared, // .shared
65 }
66
67 #[derive(Debug, Clone, PartialEq, Serialize)]
68 pub enum Op {
69 Exch, // .exch
70 And, // .and
71 Xor, // .xor
72 Cas, // .cas
73 Add, // .add
74 Inc, // .inc
75 Dec, // .dec
76 Min, // .min
77 Max, // .max
78 Or, // .or
79 }
80
81 #[derive(Debug, Clone, PartialEq, Serialize)]
82 pub enum LevelCacheHint {
83 L2CacheHint, // .L2::cache_hint
84 }
85
86 #[derive(Debug, Clone, PartialEq, Serialize)]
87 pub enum Type {
88 B32, // .b32
89 B64, // .b64
90 U32, // .u32
91 U64, // .u64
92 S32, // .s32
93 S64, // .s64
94 F32, // .f32
95 F64, // .f64
96 }
97
98 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
99 pub struct AtomSemScopeSpaceOpLevelCacheHintType {
100 pub sem: Option<Sem>, // {.sem}
101 pub scope: Option<Scope>, // {.scope}
102 pub space: Option<Space>, // {.space}
103 pub op: Op, // .op
104 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
105 pub type_: Type, // .type
106 pub d: GeneralOperand, // d
107 pub a: AddressOperand, // [a]
108 pub b: GeneralOperand, // b
109 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
110 pub span: Span,
111 }
112
113 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
114 pub struct AtomSemScopeSpaceOpType {
115 pub sem: Option<Sem>, // {.sem}
116 pub scope: Option<Scope>, // {.scope}
117 pub space: Option<Space>, // {.space}
118 pub op: Op, // .op
119 pub type_: Type, // .type
120 pub d: GeneralOperand, // d
121 pub a: AddressOperand, // [a]
122 pub b: GeneralOperand, // b
123 pub c: GeneralOperand, // c
124 pub span: Span,
125 }
126
127 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
128 pub struct AtomSemScopeSpaceCasB16 {
129 pub sem: Option<Sem>, // {.sem}
130 pub scope: Option<Scope>, // {.scope}
131 pub space: Option<Space>, // {.space}
132 pub cas: (), // .cas
133 pub b16: (), // .b16
134 pub d: GeneralOperand, // d
135 pub a: AddressOperand, // [a]
136 pub b: GeneralOperand, // b
137 pub c: GeneralOperand, // c
138 pub span: Span,
139 }
140
141 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
142 pub struct AtomSemScopeSpaceCasB128 {
143 pub sem: Option<Sem>, // {.sem}
144 pub scope: Option<Scope>, // {.scope}
145 pub space: Option<Space>, // {.space}
146 pub cas: (), // .cas
147 pub b128: (), // .b128
148 pub d: GeneralOperand, // d
149 pub a: AddressOperand, // [a]
150 pub b: GeneralOperand, // b
151 pub c: GeneralOperand, // c
152 pub span: Span,
153 }
154
155 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
156 pub struct AtomSemScopeSpaceExchLevelCacheHintB128 {
157 pub sem: Option<Sem>, // {.sem}
158 pub scope: Option<Scope>, // {.scope}
159 pub space: Option<Space>, // {.space}
160 pub exch: (), // .exch
161 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
162 pub b128: (), // .b128
163 pub d: GeneralOperand, // d
164 pub a: AddressOperand, // [a]
165 pub b: GeneralOperand, // b
166 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
167 pub span: Span,
168 }
169
170 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
171 pub struct AtomSemScopeSpaceAddNoftzLevelCacheHintF16 {
172 pub sem: Option<Sem>, // {.sem}
173 pub scope: Option<Scope>, // {.scope}
174 pub space: Option<Space>, // {.space}
175 pub add: (), // .add
176 pub noftz: (), // .noftz
177 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
178 pub f16: (), // .f16
179 pub d: GeneralOperand, // d
180 pub a: AddressOperand, // [a]
181 pub b: GeneralOperand, // b
182 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
183 pub span: Span,
184 }
185
186 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
187 pub struct AtomSemScopeSpaceAddNoftzLevelCacheHintF16x2 {
188 pub sem: Option<Sem>, // {.sem}
189 pub scope: Option<Scope>, // {.scope}
190 pub space: Option<Space>, // {.space}
191 pub add: (), // .add
192 pub noftz: (), // .noftz
193 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
194 pub f16x2: (), // .f16x2
195 pub d: GeneralOperand, // d
196 pub a: AddressOperand, // [a]
197 pub b: GeneralOperand, // b
198 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
199 pub span: Span,
200 }
201
202 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
203 pub struct AtomSemScopeSpaceAddNoftzLevelCacheHintBf16 {
204 pub sem: Option<Sem>, // {.sem}
205 pub scope: Option<Scope>, // {.scope}
206 pub space: Option<Space>, // {.space}
207 pub add: (), // .add
208 pub noftz: (), // .noftz
209 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
210 pub bf16: (), // .bf16
211 pub d: GeneralOperand, // d
212 pub a: AddressOperand, // [a]
213 pub b: GeneralOperand, // b
214 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
215 pub span: Span,
216 }
217
218 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
219 pub struct AtomSemScopeSpaceAddNoftzLevelCacheHintBf16x2 {
220 pub sem: Option<Sem>, // {.sem}
221 pub scope: Option<Scope>, // {.scope}
222 pub space: Option<Space>, // {.space}
223 pub add: (), // .add
224 pub noftz: (), // .noftz
225 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
226 pub bf16x2: (), // .bf16x2
227 pub d: GeneralOperand, // d
228 pub a: AddressOperand, // [a]
229 pub b: GeneralOperand, // b
230 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
231 pub span: Span,
232 }
233}
234
235pub mod section_1 {
236 use crate::Spanned;
237 use crate::parser::Span;
238 use crate::r#type::common::*;
239
240 use serde::Serialize;
241
242 #[derive(Debug, Clone, PartialEq, Serialize)]
243 pub enum Sem {
244 Relaxed, // .relaxed
245 Acquire, // .acquire
246 Release, // .release
247 AcqRel, // .acq_rel
248 }
249
250 #[derive(Debug, Clone, PartialEq, Serialize)]
251 pub enum Scope {
252 Cluster, // .cluster
253 Cta, // .cta
254 Gpu, // .gpu
255 Sys, // .sys
256 }
257
258 #[derive(Debug, Clone, PartialEq, Serialize)]
259 pub enum LevelCacheHint {
260 L2CacheHint, // .L2::cache_hint
261 }
262
263 #[derive(Debug, Clone, PartialEq, Serialize)]
264 pub enum Vec32Bit {
265 V2, // .v2
266 V4, // .v4
267 }
268
269 #[derive(Debug, Clone, PartialEq, Serialize)]
270 pub enum Op {
271 Add, // .add
272 Min, // .min
273 Max, // .max
274 }
275
276 #[derive(Debug, Clone, PartialEq, Serialize)]
277 pub enum Vec16Bit {
278 V2, // .v2
279 V4, // .v4
280 V8, // .v8
281 }
282
283 #[derive(Debug, Clone, PartialEq, Serialize)]
284 pub enum HalfWordType {
285 Bf16, // .bf16
286 F16, // .f16
287 }
288
289 #[derive(Debug, Clone, PartialEq, Serialize)]
290 pub enum PackedType {
291 Bf16x2, // .bf16x2
292 F16x2, // .f16x2
293 }
294
295 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
296 pub struct AtomSemScopeGlobalAddLevelCacheHintVec32BitF32 {
297 pub sem: Option<Sem>, // {.sem}
298 pub scope: Option<Scope>, // {.scope}
299 pub global: bool, // {.global}
300 pub add: (), // .add
301 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
302 pub vec_32_bit: Vec32Bit, // .vec_32_bit
303 pub f32: (), // .f32
304 pub d: GeneralOperand, // d
305 pub a: AddressOperand, // [a]
306 pub b: GeneralOperand, // b
307 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
308 pub span: Span,
309 }
310
311 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
312 pub struct AtomSemScopeGlobalOpNoftzLevelCacheHintVec16BitHalfWordType {
313 pub sem: Option<Sem>, // {.sem}
314 pub scope: Option<Scope>, // {.scope}
315 pub global: bool, // {.global}
316 pub op: Op, // .op
317 pub noftz: (), // .noftz
318 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
319 pub vec_16_bit: Vec16Bit, // .vec_16_bit
320 pub half_word_type: HalfWordType, // .half_word_type
321 pub d: GeneralOperand, // d
322 pub a: AddressOperand, // [a]
323 pub b: GeneralOperand, // b
324 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
325 pub span: Span,
326 }
327
328 #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
329 pub struct AtomSemScopeGlobalOpNoftzLevelCacheHintVec32BitPackedType {
330 pub sem: Option<Sem>, // {.sem}
331 pub scope: Option<Scope>, // {.scope}
332 pub global: bool, // {.global}
333 pub op: Op, // .op
334 pub noftz: (), // .noftz
335 pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
336 pub vec_32_bit: Vec32Bit, // .vec_32_bit
337 pub packed_type: PackedType, // .packed_type
338 pub d: GeneralOperand, // d
339 pub a: AddressOperand, // [a]
340 pub b: GeneralOperand, // b
341 pub cache_policy: Option<GeneralOperand>, // {, cache-policy}
342 pub span: Span,
343 }
344}
345
346// Re-export types with section suffixes to avoid naming conflicts
347// e.g., Type0 for section_0::Type, Type1 for section_1::Type
348pub use section_0::AtomSemScopeSpaceAddNoftzLevelCacheHintBf16;
349pub use section_0::AtomSemScopeSpaceAddNoftzLevelCacheHintBf16x2;
350pub use section_0::AtomSemScopeSpaceAddNoftzLevelCacheHintF16;
351pub use section_0::AtomSemScopeSpaceAddNoftzLevelCacheHintF16x2;
352pub use section_0::AtomSemScopeSpaceCasB16;
353pub use section_0::AtomSemScopeSpaceCasB128;
354pub use section_0::AtomSemScopeSpaceExchLevelCacheHintB128;
355pub use section_0::AtomSemScopeSpaceOpLevelCacheHintType;
356pub use section_0::AtomSemScopeSpaceOpType;
357pub use section_0::LevelCacheHint as LevelCacheHint0;
358pub use section_0::Op as Op0;
359pub use section_0::Scope as Scope0;
360pub use section_0::Sem as Sem0;
361pub use section_0::Space as Space0;
362pub use section_0::Type as Type0;
363pub use section_1::AtomSemScopeGlobalAddLevelCacheHintVec32BitF32;
364pub use section_1::AtomSemScopeGlobalOpNoftzLevelCacheHintVec16BitHalfWordType;
365pub use section_1::AtomSemScopeGlobalOpNoftzLevelCacheHintVec32BitPackedType;
366pub use section_1::HalfWordType as HalfWordType1;
367pub use section_1::LevelCacheHint as LevelCacheHint1;
368pub use section_1::Op as Op1;
369pub use section_1::PackedType as PackedType1;
370pub use section_1::Scope as Scope1;
371pub use section_1::Sem as Sem1;
372pub use section_1::Vec16Bit as Vec16Bit1;
373pub use section_1::Vec32Bit as Vec32Bit1;