Skip to main content

ptx_parser/unparser/instruction/
mul.rs

1//! Original PTX specification:
2//!
3//! mul.mode.type  d, a, b;
4//! .mode = { .hi, .lo, .wide };
5//! .type = { .u16, .u32, .u64,
6//! .s16, .s32, .s64 };
7//! --------------------------------------------
8//! mul{.rnd}{.ftz}{.sat}.f32  d, a, b;
9//! mul{.rnd}{.ftz}.f32x2      d, a, b;
10//! mul{.rnd}.f64              d, a, b;
11//! .rnd = { .rn, .rz, .rm, .rp };
12//! --------------------------------------------
13//! mul{.rnd}{.ftz}{.sat}.f16   d, a, b;
14//! mul{.rnd}{.ftz}{.sat}.f16x2 d, a, b;
15//! mul{.rnd}.bf16   d, a, b;
16//! mul{.rnd}.bf16x2 d, a, b;
17//! .rnd = { .rn };
18
19#![allow(unused)]
20
21use crate::lexer::PtxToken;
22use crate::unparser::{PtxUnparser, common::*};
23
24pub mod section_0 {
25    use super::*;
26    use crate::r#type::instruction::mul::section_0::*;
27
28    impl PtxUnparser for MulModeType {
29        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
30            self.unparse_tokens_mode(tokens, false);
31        }
32        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
33            push_opcode(tokens, "mul");
34            match &self.mode {
35                Mode::Wide => {
36                    push_directive(tokens, "wide");
37                }
38                Mode::Hi => {
39                    push_directive(tokens, "hi");
40                }
41                Mode::Lo => {
42                    push_directive(tokens, "lo");
43                }
44            }
45            match &self.type_ {
46                Type::U16 => {
47                    push_directive(tokens, "u16");
48                }
49                Type::U32 => {
50                    push_directive(tokens, "u32");
51                }
52                Type::U64 => {
53                    push_directive(tokens, "u64");
54                }
55                Type::S16 => {
56                    push_directive(tokens, "s16");
57                }
58                Type::S32 => {
59                    push_directive(tokens, "s32");
60                }
61                Type::S64 => {
62                    push_directive(tokens, "s64");
63                }
64            }
65            if spaced {
66                tokens.push(PtxToken::Space);
67            }
68            self.d.unparse_tokens_mode(tokens, spaced);
69            tokens.push(PtxToken::Comma);
70            if spaced {
71                tokens.push(PtxToken::Space);
72            }
73            self.a.unparse_tokens_mode(tokens, spaced);
74            tokens.push(PtxToken::Comma);
75            if spaced {
76                tokens.push(PtxToken::Space);
77            }
78            self.b.unparse_tokens_mode(tokens, spaced);
79            tokens.push(PtxToken::Semicolon);
80            if spaced {
81                tokens.push(PtxToken::Newline);
82            }
83        }
84    }
85}
86
87pub mod section_1 {
88    use super::*;
89    use crate::r#type::instruction::mul::section_1::*;
90
91    impl PtxUnparser for MulRndFtzSatF32 {
92        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
93            self.unparse_tokens_mode(tokens, false);
94        }
95        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
96            push_opcode(tokens, "mul");
97            if let Some(rnd_0) = self.rnd.as_ref() {
98                match rnd_0 {
99                    Rnd::Rn => {
100                        push_directive(tokens, "rn");
101                    }
102                    Rnd::Rz => {
103                        push_directive(tokens, "rz");
104                    }
105                    Rnd::Rm => {
106                        push_directive(tokens, "rm");
107                    }
108                    Rnd::Rp => {
109                        push_directive(tokens, "rp");
110                    }
111                }
112            }
113            if self.ftz {
114                push_directive(tokens, "ftz");
115            }
116            if self.sat {
117                push_directive(tokens, "sat");
118            }
119            push_directive(tokens, "f32");
120            if spaced {
121                tokens.push(PtxToken::Space);
122            }
123            self.d.unparse_tokens_mode(tokens, spaced);
124            tokens.push(PtxToken::Comma);
125            if spaced {
126                tokens.push(PtxToken::Space);
127            }
128            self.a.unparse_tokens_mode(tokens, spaced);
129            tokens.push(PtxToken::Comma);
130            if spaced {
131                tokens.push(PtxToken::Space);
132            }
133            self.b.unparse_tokens_mode(tokens, spaced);
134            tokens.push(PtxToken::Semicolon);
135            if spaced {
136                tokens.push(PtxToken::Newline);
137            }
138        }
139    }
140
141    impl PtxUnparser for MulRndFtzF32x2 {
142        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
143            self.unparse_tokens_mode(tokens, false);
144        }
145        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
146            push_opcode(tokens, "mul");
147            if let Some(rnd_1) = self.rnd.as_ref() {
148                match rnd_1 {
149                    Rnd::Rn => {
150                        push_directive(tokens, "rn");
151                    }
152                    Rnd::Rz => {
153                        push_directive(tokens, "rz");
154                    }
155                    Rnd::Rm => {
156                        push_directive(tokens, "rm");
157                    }
158                    Rnd::Rp => {
159                        push_directive(tokens, "rp");
160                    }
161                }
162            }
163            if self.ftz {
164                push_directive(tokens, "ftz");
165            }
166            push_directive(tokens, "f32x2");
167            if spaced {
168                tokens.push(PtxToken::Space);
169            }
170            self.d.unparse_tokens_mode(tokens, spaced);
171            tokens.push(PtxToken::Comma);
172            if spaced {
173                tokens.push(PtxToken::Space);
174            }
175            self.a.unparse_tokens_mode(tokens, spaced);
176            tokens.push(PtxToken::Comma);
177            if spaced {
178                tokens.push(PtxToken::Space);
179            }
180            self.b.unparse_tokens_mode(tokens, spaced);
181            tokens.push(PtxToken::Semicolon);
182            if spaced {
183                tokens.push(PtxToken::Newline);
184            }
185        }
186    }
187
188    impl PtxUnparser for MulRndF64 {
189        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
190            self.unparse_tokens_mode(tokens, false);
191        }
192        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
193            push_opcode(tokens, "mul");
194            if let Some(rnd_2) = self.rnd.as_ref() {
195                match rnd_2 {
196                    Rnd::Rn => {
197                        push_directive(tokens, "rn");
198                    }
199                    Rnd::Rz => {
200                        push_directive(tokens, "rz");
201                    }
202                    Rnd::Rm => {
203                        push_directive(tokens, "rm");
204                    }
205                    Rnd::Rp => {
206                        push_directive(tokens, "rp");
207                    }
208                }
209            }
210            push_directive(tokens, "f64");
211            if spaced {
212                tokens.push(PtxToken::Space);
213            }
214            self.d.unparse_tokens_mode(tokens, spaced);
215            tokens.push(PtxToken::Comma);
216            if spaced {
217                tokens.push(PtxToken::Space);
218            }
219            self.a.unparse_tokens_mode(tokens, spaced);
220            tokens.push(PtxToken::Comma);
221            if spaced {
222                tokens.push(PtxToken::Space);
223            }
224            self.b.unparse_tokens_mode(tokens, spaced);
225            tokens.push(PtxToken::Semicolon);
226            if spaced {
227                tokens.push(PtxToken::Newline);
228            }
229        }
230    }
231}
232
233pub mod section_2 {
234    use super::*;
235    use crate::r#type::instruction::mul::section_2::*;
236
237    impl PtxUnparser for MulRndFtzSatF16 {
238        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
239            self.unparse_tokens_mode(tokens, false);
240        }
241        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
242            push_opcode(tokens, "mul");
243            if let Some(rnd_3) = self.rnd.as_ref() {
244                match rnd_3 {
245                    Rnd::Rn => {
246                        push_directive(tokens, "rn");
247                    }
248                }
249            }
250            if self.ftz {
251                push_directive(tokens, "ftz");
252            }
253            if self.sat {
254                push_directive(tokens, "sat");
255            }
256            push_directive(tokens, "f16");
257            if spaced {
258                tokens.push(PtxToken::Space);
259            }
260            self.d.unparse_tokens_mode(tokens, spaced);
261            tokens.push(PtxToken::Comma);
262            if spaced {
263                tokens.push(PtxToken::Space);
264            }
265            self.a.unparse_tokens_mode(tokens, spaced);
266            tokens.push(PtxToken::Comma);
267            if spaced {
268                tokens.push(PtxToken::Space);
269            }
270            self.b.unparse_tokens_mode(tokens, spaced);
271            tokens.push(PtxToken::Semicolon);
272            if spaced {
273                tokens.push(PtxToken::Newline);
274            }
275        }
276    }
277
278    impl PtxUnparser for MulRndFtzSatF16x2 {
279        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
280            self.unparse_tokens_mode(tokens, false);
281        }
282        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
283            push_opcode(tokens, "mul");
284            if let Some(rnd_4) = self.rnd.as_ref() {
285                match rnd_4 {
286                    Rnd::Rn => {
287                        push_directive(tokens, "rn");
288                    }
289                }
290            }
291            if self.ftz {
292                push_directive(tokens, "ftz");
293            }
294            if self.sat {
295                push_directive(tokens, "sat");
296            }
297            push_directive(tokens, "f16x2");
298            if spaced {
299                tokens.push(PtxToken::Space);
300            }
301            self.d.unparse_tokens_mode(tokens, spaced);
302            tokens.push(PtxToken::Comma);
303            if spaced {
304                tokens.push(PtxToken::Space);
305            }
306            self.a.unparse_tokens_mode(tokens, spaced);
307            tokens.push(PtxToken::Comma);
308            if spaced {
309                tokens.push(PtxToken::Space);
310            }
311            self.b.unparse_tokens_mode(tokens, spaced);
312            tokens.push(PtxToken::Semicolon);
313            if spaced {
314                tokens.push(PtxToken::Newline);
315            }
316        }
317    }
318
319    impl PtxUnparser for MulRndBf16 {
320        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
321            self.unparse_tokens_mode(tokens, false);
322        }
323        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
324            push_opcode(tokens, "mul");
325            if let Some(rnd_5) = self.rnd.as_ref() {
326                match rnd_5 {
327                    Rnd::Rn => {
328                        push_directive(tokens, "rn");
329                    }
330                }
331            }
332            push_directive(tokens, "bf16");
333            if spaced {
334                tokens.push(PtxToken::Space);
335            }
336            self.d.unparse_tokens_mode(tokens, spaced);
337            tokens.push(PtxToken::Comma);
338            if spaced {
339                tokens.push(PtxToken::Space);
340            }
341            self.a.unparse_tokens_mode(tokens, spaced);
342            tokens.push(PtxToken::Comma);
343            if spaced {
344                tokens.push(PtxToken::Space);
345            }
346            self.b.unparse_tokens_mode(tokens, spaced);
347            tokens.push(PtxToken::Semicolon);
348            if spaced {
349                tokens.push(PtxToken::Newline);
350            }
351        }
352    }
353
354    impl PtxUnparser for MulRndBf16x2 {
355        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
356            self.unparse_tokens_mode(tokens, false);
357        }
358        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
359            push_opcode(tokens, "mul");
360            if let Some(rnd_6) = self.rnd.as_ref() {
361                match rnd_6 {
362                    Rnd::Rn => {
363                        push_directive(tokens, "rn");
364                    }
365                }
366            }
367            push_directive(tokens, "bf16x2");
368            if spaced {
369                tokens.push(PtxToken::Space);
370            }
371            self.d.unparse_tokens_mode(tokens, spaced);
372            tokens.push(PtxToken::Comma);
373            if spaced {
374                tokens.push(PtxToken::Space);
375            }
376            self.a.unparse_tokens_mode(tokens, spaced);
377            tokens.push(PtxToken::Comma);
378            if spaced {
379                tokens.push(PtxToken::Space);
380            }
381            self.b.unparse_tokens_mode(tokens, spaced);
382            tokens.push(PtxToken::Semicolon);
383            if spaced {
384                tokens.push(PtxToken::Newline);
385            }
386        }
387    }
388}