Skip to main content

ptx_parser/unparser/instruction/
bar.rs

1//! Original PTX specification:
2//!
3//! barrier{.cta}.sync{.aligned}      a{, b};
4//! barrier{.cta}.arrive{.aligned}    a, b;
5//! barrier{.cta}.red.popc{.aligned}.u32  d, a{, b}, {!}c;
6//! barrier{.cta}.red.op{.aligned}.pred   p, a{, b}, {!}c;
7//! bar{.cta}.sync      a{, b};
8//! bar{.cta}.arrive    a, b;
9//! bar{.cta}.red.popc.u32  d, a{, b}, {!}c;
10//! bar{.cta}.red.op.pred   p, a{, b}, {!}c;
11//! .op = { .and, .or };
12
13#![allow(unused)]
14
15use crate::lexer::PtxToken;
16use crate::unparser::{PtxUnparser, common::*};
17
18pub mod section_0 {
19    use super::*;
20    use crate::r#type::instruction::bar::section_0::*;
21
22    impl PtxUnparser for BarrierCtaSyncAligned {
23        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
24            self.unparse_tokens_mode(tokens, false);
25        }
26        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
27            push_opcode(tokens, "barrier");
28            if self.cta {
29                push_directive(tokens, "cta");
30            }
31            push_directive(tokens, "sync");
32            if self.aligned {
33                push_directive(tokens, "aligned");
34            }
35            if spaced {
36                tokens.push(PtxToken::Space);
37            }
38            self.a.unparse_tokens_mode(tokens, spaced);
39            if self.b.is_some() {
40                tokens.push(PtxToken::Comma);
41            }
42            if let Some(opt_0) = self.b.as_ref() {
43                if spaced {
44                    tokens.push(PtxToken::Space);
45                }
46                opt_0.unparse_tokens_mode(tokens, spaced);
47            }
48            tokens.push(PtxToken::Semicolon);
49            if spaced {
50                tokens.push(PtxToken::Newline);
51            }
52        }
53    }
54
55    impl PtxUnparser for BarrierCtaArriveAligned {
56        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
57            self.unparse_tokens_mode(tokens, false);
58        }
59        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
60            push_opcode(tokens, "barrier");
61            if self.cta {
62                push_directive(tokens, "cta");
63            }
64            push_directive(tokens, "arrive");
65            if self.aligned {
66                push_directive(tokens, "aligned");
67            }
68            if spaced {
69                tokens.push(PtxToken::Space);
70            }
71            self.a.unparse_tokens_mode(tokens, spaced);
72            tokens.push(PtxToken::Comma);
73            if spaced {
74                tokens.push(PtxToken::Space);
75            }
76            self.b.unparse_tokens_mode(tokens, spaced);
77            tokens.push(PtxToken::Semicolon);
78            if spaced {
79                tokens.push(PtxToken::Newline);
80            }
81        }
82    }
83
84    impl PtxUnparser for BarrierCtaRedPopcAlignedU32 {
85        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
86            self.unparse_tokens_mode(tokens, false);
87        }
88        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
89            push_opcode(tokens, "barrier");
90            if self.cta {
91                push_directive(tokens, "cta");
92            }
93            push_directive(tokens, "red");
94            push_directive(tokens, "popc");
95            if self.aligned {
96                push_directive(tokens, "aligned");
97            }
98            push_directive(tokens, "u32");
99            if spaced {
100                tokens.push(PtxToken::Space);
101            }
102            self.d.unparse_tokens_mode(tokens, spaced);
103            tokens.push(PtxToken::Comma);
104            if spaced {
105                tokens.push(PtxToken::Space);
106            }
107            self.a.unparse_tokens_mode(tokens, spaced);
108            if self.b.is_some() {
109                tokens.push(PtxToken::Comma);
110            }
111            if let Some(opt_1) = self.b.as_ref() {
112                if spaced {
113                    tokens.push(PtxToken::Space);
114                }
115                opt_1.unparse_tokens_mode(tokens, spaced);
116            }
117            tokens.push(PtxToken::Comma);
118            if self.c_op {
119                tokens.push(PtxToken::Exclaim);
120            }
121            if spaced {
122                tokens.push(PtxToken::Space);
123            }
124            self.c.unparse_tokens_mode(tokens, spaced);
125            tokens.push(PtxToken::Semicolon);
126            if spaced {
127                tokens.push(PtxToken::Newline);
128            }
129        }
130    }
131
132    impl PtxUnparser for BarrierCtaRedOpAlignedPred {
133        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
134            self.unparse_tokens_mode(tokens, false);
135        }
136        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
137            push_opcode(tokens, "barrier");
138            if self.cta {
139                push_directive(tokens, "cta");
140            }
141            push_directive(tokens, "red");
142            match &self.op {
143                Op::And => {
144                    push_directive(tokens, "and");
145                }
146                Op::Or => {
147                    push_directive(tokens, "or");
148                }
149            }
150            if self.aligned {
151                push_directive(tokens, "aligned");
152            }
153            push_directive(tokens, "pred");
154            if spaced {
155                tokens.push(PtxToken::Space);
156            }
157            self.p.unparse_tokens_mode(tokens, spaced);
158            tokens.push(PtxToken::Comma);
159            if spaced {
160                tokens.push(PtxToken::Space);
161            }
162            self.a.unparse_tokens_mode(tokens, spaced);
163            if self.b.is_some() {
164                tokens.push(PtxToken::Comma);
165            }
166            if let Some(opt_2) = self.b.as_ref() {
167                if spaced {
168                    tokens.push(PtxToken::Space);
169                }
170                opt_2.unparse_tokens_mode(tokens, spaced);
171            }
172            tokens.push(PtxToken::Comma);
173            if self.c_op {
174                tokens.push(PtxToken::Exclaim);
175            }
176            if spaced {
177                tokens.push(PtxToken::Space);
178            }
179            self.c.unparse_tokens_mode(tokens, spaced);
180            tokens.push(PtxToken::Semicolon);
181            if spaced {
182                tokens.push(PtxToken::Newline);
183            }
184        }
185    }
186
187    impl PtxUnparser for BarCtaSync {
188        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
189            self.unparse_tokens_mode(tokens, false);
190        }
191        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
192            push_opcode(tokens, "bar");
193            if self.cta {
194                push_directive(tokens, "cta");
195            }
196            push_directive(tokens, "sync");
197            if spaced {
198                tokens.push(PtxToken::Space);
199            }
200            self.a.unparse_tokens_mode(tokens, spaced);
201            if self.b.is_some() {
202                tokens.push(PtxToken::Comma);
203            }
204            if let Some(opt_3) = self.b.as_ref() {
205                if spaced {
206                    tokens.push(PtxToken::Space);
207                }
208                opt_3.unparse_tokens_mode(tokens, spaced);
209            }
210            tokens.push(PtxToken::Semicolon);
211            if spaced {
212                tokens.push(PtxToken::Newline);
213            }
214        }
215    }
216
217    impl PtxUnparser for BarCtaArrive {
218        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
219            self.unparse_tokens_mode(tokens, false);
220        }
221        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
222            push_opcode(tokens, "bar");
223            if self.cta {
224                push_directive(tokens, "cta");
225            }
226            push_directive(tokens, "arrive");
227            if spaced {
228                tokens.push(PtxToken::Space);
229            }
230            self.a.unparse_tokens_mode(tokens, spaced);
231            tokens.push(PtxToken::Comma);
232            if spaced {
233                tokens.push(PtxToken::Space);
234            }
235            self.b.unparse_tokens_mode(tokens, spaced);
236            tokens.push(PtxToken::Semicolon);
237            if spaced {
238                tokens.push(PtxToken::Newline);
239            }
240        }
241    }
242
243    impl PtxUnparser for BarCtaRedPopcU32 {
244        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
245            self.unparse_tokens_mode(tokens, false);
246        }
247        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
248            push_opcode(tokens, "bar");
249            if self.cta {
250                push_directive(tokens, "cta");
251            }
252            push_directive(tokens, "red");
253            push_directive(tokens, "popc");
254            push_directive(tokens, "u32");
255            if spaced {
256                tokens.push(PtxToken::Space);
257            }
258            self.d.unparse_tokens_mode(tokens, spaced);
259            tokens.push(PtxToken::Comma);
260            if spaced {
261                tokens.push(PtxToken::Space);
262            }
263            self.a.unparse_tokens_mode(tokens, spaced);
264            if self.b.is_some() {
265                tokens.push(PtxToken::Comma);
266            }
267            if let Some(opt_4) = self.b.as_ref() {
268                if spaced {
269                    tokens.push(PtxToken::Space);
270                }
271                opt_4.unparse_tokens_mode(tokens, spaced);
272            }
273            tokens.push(PtxToken::Comma);
274            if self.c_op {
275                tokens.push(PtxToken::Exclaim);
276            }
277            if spaced {
278                tokens.push(PtxToken::Space);
279            }
280            self.c.unparse_tokens_mode(tokens, spaced);
281            tokens.push(PtxToken::Semicolon);
282            if spaced {
283                tokens.push(PtxToken::Newline);
284            }
285        }
286    }
287
288    impl PtxUnparser for BarCtaRedOpPred {
289        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
290            self.unparse_tokens_mode(tokens, false);
291        }
292        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
293            push_opcode(tokens, "bar");
294            if self.cta {
295                push_directive(tokens, "cta");
296            }
297            push_directive(tokens, "red");
298            match &self.op {
299                Op::And => {
300                    push_directive(tokens, "and");
301                }
302                Op::Or => {
303                    push_directive(tokens, "or");
304                }
305            }
306            push_directive(tokens, "pred");
307            if spaced {
308                tokens.push(PtxToken::Space);
309            }
310            self.p.unparse_tokens_mode(tokens, spaced);
311            tokens.push(PtxToken::Comma);
312            if spaced {
313                tokens.push(PtxToken::Space);
314            }
315            self.a.unparse_tokens_mode(tokens, spaced);
316            if self.b.is_some() {
317                tokens.push(PtxToken::Comma);
318            }
319            if let Some(opt_5) = self.b.as_ref() {
320                if spaced {
321                    tokens.push(PtxToken::Space);
322                }
323                opt_5.unparse_tokens_mode(tokens, spaced);
324            }
325            tokens.push(PtxToken::Comma);
326            if self.c_op {
327                tokens.push(PtxToken::Exclaim);
328            }
329            if spaced {
330                tokens.push(PtxToken::Space);
331            }
332            self.c.unparse_tokens_mode(tokens, spaced);
333            tokens.push(PtxToken::Semicolon);
334            if spaced {
335                tokens.push(PtxToken::Newline);
336            }
337        }
338    }
339}