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