Skip to main content

ptx_parser/unparser/instruction/
vset.rs

1//! Original PTX specification:
2//!
3//! // 32-bit scalar operation, with optional secondary operation
4//! vset.atype.btype.cmp       d, a{.asel}, b{.bsel};
5//! vset.atype.btype.cmp.op2   d, a{.asel}, b{.bsel}, c;
6//! // 32-bit scalar operation, with optional data merge
7//! vset.atype.btype.cmp  d.dsel, a{.asel}, b{.bsel}, c;
8//! .atype = .btype = { .u32, .s32 };
9//! .cmp   = { .eq, .ne, .lt, .le, .gt, .ge };
10//! .dsel  = .asel  = .bsel  = { .b0, .b1, .b2, .b3, .h0, .h1 };
11//! .op2   = { .add, .min, .max };
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::vset::section_0::*;
21
22    impl PtxUnparser for VsetAtypeBtypeCmp {
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, "vset");
28            match &self.atype {
29                Atype::U32 => {
30                    push_directive(tokens, "u32");
31                }
32                Atype::S32 => {
33                    push_directive(tokens, "s32");
34                }
35            }
36            match &self.btype {
37                Btype::U32 => {
38                    push_directive(tokens, "u32");
39                }
40                Btype::S32 => {
41                    push_directive(tokens, "s32");
42                }
43            }
44            match &self.cmp {
45                Cmp::Eq => {
46                    push_directive(tokens, "eq");
47                }
48                Cmp::Ne => {
49                    push_directive(tokens, "ne");
50                }
51                Cmp::Lt => {
52                    push_directive(tokens, "lt");
53                }
54                Cmp::Le => {
55                    push_directive(tokens, "le");
56                }
57                Cmp::Gt => {
58                    push_directive(tokens, "gt");
59                }
60                Cmp::Ge => {
61                    push_directive(tokens, "ge");
62                }
63            }
64            if spaced {
65                tokens.push(PtxToken::Space);
66            }
67            self.d.unparse_tokens_mode(tokens, spaced);
68            tokens.push(PtxToken::Comma);
69            if spaced {
70                tokens.push(PtxToken::Space);
71            }
72            self.a.unparse_tokens_mode(tokens, spaced);
73            if let Some(asel_0) = self.asel.as_ref() {
74                match asel_0 {
75                    Asel::B0 => {
76                        push_directive(tokens, "b0");
77                    }
78                    Asel::B1 => {
79                        push_directive(tokens, "b1");
80                    }
81                    Asel::B2 => {
82                        push_directive(tokens, "b2");
83                    }
84                    Asel::B3 => {
85                        push_directive(tokens, "b3");
86                    }
87                    Asel::H0 => {
88                        push_directive(tokens, "h0");
89                    }
90                    Asel::H1 => {
91                        push_directive(tokens, "h1");
92                    }
93                }
94            }
95            tokens.push(PtxToken::Comma);
96            if spaced {
97                tokens.push(PtxToken::Space);
98            }
99            self.b.unparse_tokens_mode(tokens, spaced);
100            if let Some(bsel_1) = self.bsel.as_ref() {
101                match bsel_1 {
102                    Bsel::B0 => {
103                        push_directive(tokens, "b0");
104                    }
105                    Bsel::B1 => {
106                        push_directive(tokens, "b1");
107                    }
108                    Bsel::B2 => {
109                        push_directive(tokens, "b2");
110                    }
111                    Bsel::B3 => {
112                        push_directive(tokens, "b3");
113                    }
114                    Bsel::H0 => {
115                        push_directive(tokens, "h0");
116                    }
117                    Bsel::H1 => {
118                        push_directive(tokens, "h1");
119                    }
120                }
121            }
122            tokens.push(PtxToken::Semicolon);
123            if spaced {
124                tokens.push(PtxToken::Newline);
125            }
126        }
127    }
128
129    impl PtxUnparser for VsetAtypeBtypeCmpOp2 {
130        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
131            self.unparse_tokens_mode(tokens, false);
132        }
133        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
134            push_opcode(tokens, "vset");
135            match &self.atype {
136                Atype::U32 => {
137                    push_directive(tokens, "u32");
138                }
139                Atype::S32 => {
140                    push_directive(tokens, "s32");
141                }
142            }
143            match &self.btype {
144                Btype::U32 => {
145                    push_directive(tokens, "u32");
146                }
147                Btype::S32 => {
148                    push_directive(tokens, "s32");
149                }
150            }
151            match &self.cmp {
152                Cmp::Eq => {
153                    push_directive(tokens, "eq");
154                }
155                Cmp::Ne => {
156                    push_directive(tokens, "ne");
157                }
158                Cmp::Lt => {
159                    push_directive(tokens, "lt");
160                }
161                Cmp::Le => {
162                    push_directive(tokens, "le");
163                }
164                Cmp::Gt => {
165                    push_directive(tokens, "gt");
166                }
167                Cmp::Ge => {
168                    push_directive(tokens, "ge");
169                }
170            }
171            match &self.op2 {
172                Op2::Add => {
173                    push_directive(tokens, "add");
174                }
175                Op2::Min => {
176                    push_directive(tokens, "min");
177                }
178                Op2::Max => {
179                    push_directive(tokens, "max");
180                }
181            }
182            if spaced {
183                tokens.push(PtxToken::Space);
184            }
185            self.d.unparse_tokens_mode(tokens, spaced);
186            tokens.push(PtxToken::Comma);
187            if spaced {
188                tokens.push(PtxToken::Space);
189            }
190            self.a.unparse_tokens_mode(tokens, spaced);
191            if let Some(asel_2) = self.asel.as_ref() {
192                match asel_2 {
193                    Asel::B0 => {
194                        push_directive(tokens, "b0");
195                    }
196                    Asel::B1 => {
197                        push_directive(tokens, "b1");
198                    }
199                    Asel::B2 => {
200                        push_directive(tokens, "b2");
201                    }
202                    Asel::B3 => {
203                        push_directive(tokens, "b3");
204                    }
205                    Asel::H0 => {
206                        push_directive(tokens, "h0");
207                    }
208                    Asel::H1 => {
209                        push_directive(tokens, "h1");
210                    }
211                }
212            }
213            tokens.push(PtxToken::Comma);
214            if spaced {
215                tokens.push(PtxToken::Space);
216            }
217            self.b.unparse_tokens_mode(tokens, spaced);
218            if let Some(bsel_3) = self.bsel.as_ref() {
219                match bsel_3 {
220                    Bsel::B0 => {
221                        push_directive(tokens, "b0");
222                    }
223                    Bsel::B1 => {
224                        push_directive(tokens, "b1");
225                    }
226                    Bsel::B2 => {
227                        push_directive(tokens, "b2");
228                    }
229                    Bsel::B3 => {
230                        push_directive(tokens, "b3");
231                    }
232                    Bsel::H0 => {
233                        push_directive(tokens, "h0");
234                    }
235                    Bsel::H1 => {
236                        push_directive(tokens, "h1");
237                    }
238                }
239            }
240            tokens.push(PtxToken::Comma);
241            if spaced {
242                tokens.push(PtxToken::Space);
243            }
244            self.c.unparse_tokens_mode(tokens, spaced);
245            tokens.push(PtxToken::Semicolon);
246            if spaced {
247                tokens.push(PtxToken::Newline);
248            }
249        }
250    }
251
252    impl PtxUnparser for VsetAtypeBtypeCmp1 {
253        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
254            self.unparse_tokens_mode(tokens, false);
255        }
256        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
257            push_opcode(tokens, "vset");
258            match &self.atype {
259                Atype::U32 => {
260                    push_directive(tokens, "u32");
261                }
262                Atype::S32 => {
263                    push_directive(tokens, "s32");
264                }
265            }
266            match &self.btype {
267                Btype::U32 => {
268                    push_directive(tokens, "u32");
269                }
270                Btype::S32 => {
271                    push_directive(tokens, "s32");
272                }
273            }
274            match &self.cmp {
275                Cmp::Eq => {
276                    push_directive(tokens, "eq");
277                }
278                Cmp::Ne => {
279                    push_directive(tokens, "ne");
280                }
281                Cmp::Lt => {
282                    push_directive(tokens, "lt");
283                }
284                Cmp::Le => {
285                    push_directive(tokens, "le");
286                }
287                Cmp::Gt => {
288                    push_directive(tokens, "gt");
289                }
290                Cmp::Ge => {
291                    push_directive(tokens, "ge");
292                }
293            }
294            if spaced {
295                tokens.push(PtxToken::Space);
296            }
297            self.d.unparse_tokens_mode(tokens, spaced);
298            match &self.dsel {
299                Dsel::B0 => {
300                    push_directive(tokens, "b0");
301                }
302                Dsel::B1 => {
303                    push_directive(tokens, "b1");
304                }
305                Dsel::B2 => {
306                    push_directive(tokens, "b2");
307                }
308                Dsel::B3 => {
309                    push_directive(tokens, "b3");
310                }
311                Dsel::H0 => {
312                    push_directive(tokens, "h0");
313                }
314                Dsel::H1 => {
315                    push_directive(tokens, "h1");
316                }
317            }
318            tokens.push(PtxToken::Comma);
319            if spaced {
320                tokens.push(PtxToken::Space);
321            }
322            self.a.unparse_tokens_mode(tokens, spaced);
323            if let Some(asel_4) = self.asel.as_ref() {
324                match asel_4 {
325                    Asel::B0 => {
326                        push_directive(tokens, "b0");
327                    }
328                    Asel::B1 => {
329                        push_directive(tokens, "b1");
330                    }
331                    Asel::B2 => {
332                        push_directive(tokens, "b2");
333                    }
334                    Asel::B3 => {
335                        push_directive(tokens, "b3");
336                    }
337                    Asel::H0 => {
338                        push_directive(tokens, "h0");
339                    }
340                    Asel::H1 => {
341                        push_directive(tokens, "h1");
342                    }
343                }
344            }
345            tokens.push(PtxToken::Comma);
346            if spaced {
347                tokens.push(PtxToken::Space);
348            }
349            self.b.unparse_tokens_mode(tokens, spaced);
350            if let Some(bsel_5) = self.bsel.as_ref() {
351                match bsel_5 {
352                    Bsel::B0 => {
353                        push_directive(tokens, "b0");
354                    }
355                    Bsel::B1 => {
356                        push_directive(tokens, "b1");
357                    }
358                    Bsel::B2 => {
359                        push_directive(tokens, "b2");
360                    }
361                    Bsel::B3 => {
362                        push_directive(tokens, "b3");
363                    }
364                    Bsel::H0 => {
365                        push_directive(tokens, "h0");
366                    }
367                    Bsel::H1 => {
368                        push_directive(tokens, "h1");
369                    }
370                }
371            }
372            tokens.push(PtxToken::Comma);
373            if spaced {
374                tokens.push(PtxToken::Space);
375            }
376            self.c.unparse_tokens_mode(tokens, spaced);
377            tokens.push(PtxToken::Semicolon);
378            if spaced {
379                tokens.push(PtxToken::Newline);
380            }
381        }
382    }
383}