Skip to main content

ptx_parser/unparser/instruction/
fma.rs

1//! Original PTX specification:
2//!
3//! fma.rnd{.ftz}{.sat}.f32  d, a, b, c;
4//! fma.rnd{.ftz}.f32x2      d, a, b, c;
5//! fma.rnd.f64              d, a, b, c;
6//! .rnd = { .rn, .rz, .rm, .rp };
7//! ---------------------------------------------
8//! fma.rnd{.ftz}{.sat}.f16     d, a, b, c;
9//! fma.rnd{.ftz}{.sat}.f16x2   d, a, b, c;
10//! fma.rnd{.ftz}.relu.f16      d, a, b, c;
11//! fma.rnd{.ftz}.relu.f16x2    d, a, b, c;
12//! fma.rnd{.relu}.bf16         d, a, b, c;
13//! fma.rnd{.relu}.bf16x2       d, a, b, c;
14//! fma.rnd.oob{.relu}.type     d, a, b, c;
15//! .rnd = { .rn };
16//! ---------------------------------------------
17//! fma.rnd{.sat}.f32.abtype  d, a, b, c;
18//! .abtype = { .f16, .bf16};
19//! .rnd    = { .rn, .rz, .rm, .rp };
20
21#![allow(unused)]
22
23use crate::lexer::PtxToken;
24use crate::unparser::{PtxUnparser, common::*};
25
26pub mod section_0 {
27    use super::*;
28    use crate::r#type::instruction::fma::section_0::*;
29
30    impl PtxUnparser for FmaRndFtzSatF32 {
31        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
32            self.unparse_tokens_mode(tokens, false);
33        }
34        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
35            push_opcode(tokens, "fma");
36            match &self.rnd {
37                Rnd::Rn => {
38                    push_directive(tokens, "rn");
39                }
40                Rnd::Rz => {
41                    push_directive(tokens, "rz");
42                }
43                Rnd::Rm => {
44                    push_directive(tokens, "rm");
45                }
46                Rnd::Rp => {
47                    push_directive(tokens, "rp");
48                }
49            }
50            if self.ftz {
51                push_directive(tokens, "ftz");
52            }
53            if self.sat {
54                push_directive(tokens, "sat");
55            }
56            push_directive(tokens, "f32");
57            if spaced {
58                tokens.push(PtxToken::Space);
59            }
60            self.d.unparse_tokens_mode(tokens, spaced);
61            tokens.push(PtxToken::Comma);
62            if spaced {
63                tokens.push(PtxToken::Space);
64            }
65            self.a.unparse_tokens_mode(tokens, spaced);
66            tokens.push(PtxToken::Comma);
67            if spaced {
68                tokens.push(PtxToken::Space);
69            }
70            self.b.unparse_tokens_mode(tokens, spaced);
71            tokens.push(PtxToken::Comma);
72            if spaced {
73                tokens.push(PtxToken::Space);
74            }
75            self.c.unparse_tokens_mode(tokens, spaced);
76            tokens.push(PtxToken::Semicolon);
77            if spaced {
78                tokens.push(PtxToken::Newline);
79            }
80        }
81    }
82
83    impl PtxUnparser for FmaRndFtzF32x2 {
84        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
85            self.unparse_tokens_mode(tokens, false);
86        }
87        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
88            push_opcode(tokens, "fma");
89            match &self.rnd {
90                Rnd::Rn => {
91                    push_directive(tokens, "rn");
92                }
93                Rnd::Rz => {
94                    push_directive(tokens, "rz");
95                }
96                Rnd::Rm => {
97                    push_directive(tokens, "rm");
98                }
99                Rnd::Rp => {
100                    push_directive(tokens, "rp");
101                }
102            }
103            if self.ftz {
104                push_directive(tokens, "ftz");
105            }
106            push_directive(tokens, "f32x2");
107            if spaced {
108                tokens.push(PtxToken::Space);
109            }
110            self.d.unparse_tokens_mode(tokens, spaced);
111            tokens.push(PtxToken::Comma);
112            if spaced {
113                tokens.push(PtxToken::Space);
114            }
115            self.a.unparse_tokens_mode(tokens, spaced);
116            tokens.push(PtxToken::Comma);
117            if spaced {
118                tokens.push(PtxToken::Space);
119            }
120            self.b.unparse_tokens_mode(tokens, spaced);
121            tokens.push(PtxToken::Comma);
122            if spaced {
123                tokens.push(PtxToken::Space);
124            }
125            self.c.unparse_tokens_mode(tokens, spaced);
126            tokens.push(PtxToken::Semicolon);
127            if spaced {
128                tokens.push(PtxToken::Newline);
129            }
130        }
131    }
132
133    impl PtxUnparser for FmaRndF64 {
134        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
135            self.unparse_tokens_mode(tokens, false);
136        }
137        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
138            push_opcode(tokens, "fma");
139            match &self.rnd {
140                Rnd::Rn => {
141                    push_directive(tokens, "rn");
142                }
143                Rnd::Rz => {
144                    push_directive(tokens, "rz");
145                }
146                Rnd::Rm => {
147                    push_directive(tokens, "rm");
148                }
149                Rnd::Rp => {
150                    push_directive(tokens, "rp");
151                }
152            }
153            push_directive(tokens, "f64");
154            if spaced {
155                tokens.push(PtxToken::Space);
156            }
157            self.d.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            tokens.push(PtxToken::Comma);
164            if spaced {
165                tokens.push(PtxToken::Space);
166            }
167            self.b.unparse_tokens_mode(tokens, spaced);
168            tokens.push(PtxToken::Comma);
169            if spaced {
170                tokens.push(PtxToken::Space);
171            }
172            self.c.unparse_tokens_mode(tokens, spaced);
173            tokens.push(PtxToken::Semicolon);
174            if spaced {
175                tokens.push(PtxToken::Newline);
176            }
177        }
178    }
179}
180
181pub mod section_1 {
182    use super::*;
183    use crate::r#type::instruction::fma::section_1::*;
184
185    impl PtxUnparser for FmaRndFtzSatF16 {
186        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
187            self.unparse_tokens_mode(tokens, false);
188        }
189        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
190            push_opcode(tokens, "fma");
191            match &self.rnd {
192                Rnd::Rn => {
193                    push_directive(tokens, "rn");
194                }
195            }
196            if self.ftz {
197                push_directive(tokens, "ftz");
198            }
199            if self.sat {
200                push_directive(tokens, "sat");
201            }
202            push_directive(tokens, "f16");
203            if spaced {
204                tokens.push(PtxToken::Space);
205            }
206            self.d.unparse_tokens_mode(tokens, spaced);
207            tokens.push(PtxToken::Comma);
208            if spaced {
209                tokens.push(PtxToken::Space);
210            }
211            self.a.unparse_tokens_mode(tokens, spaced);
212            tokens.push(PtxToken::Comma);
213            if spaced {
214                tokens.push(PtxToken::Space);
215            }
216            self.b.unparse_tokens_mode(tokens, spaced);
217            tokens.push(PtxToken::Comma);
218            if spaced {
219                tokens.push(PtxToken::Space);
220            }
221            self.c.unparse_tokens_mode(tokens, spaced);
222            tokens.push(PtxToken::Semicolon);
223            if spaced {
224                tokens.push(PtxToken::Newline);
225            }
226        }
227    }
228
229    impl PtxUnparser for FmaRndFtzSatF16x2 {
230        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
231            self.unparse_tokens_mode(tokens, false);
232        }
233        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
234            push_opcode(tokens, "fma");
235            match &self.rnd {
236                Rnd::Rn => {
237                    push_directive(tokens, "rn");
238                }
239            }
240            if self.ftz {
241                push_directive(tokens, "ftz");
242            }
243            if self.sat {
244                push_directive(tokens, "sat");
245            }
246            push_directive(tokens, "f16x2");
247            if spaced {
248                tokens.push(PtxToken::Space);
249            }
250            self.d.unparse_tokens_mode(tokens, spaced);
251            tokens.push(PtxToken::Comma);
252            if spaced {
253                tokens.push(PtxToken::Space);
254            }
255            self.a.unparse_tokens_mode(tokens, spaced);
256            tokens.push(PtxToken::Comma);
257            if spaced {
258                tokens.push(PtxToken::Space);
259            }
260            self.b.unparse_tokens_mode(tokens, spaced);
261            tokens.push(PtxToken::Comma);
262            if spaced {
263                tokens.push(PtxToken::Space);
264            }
265            self.c.unparse_tokens_mode(tokens, spaced);
266            tokens.push(PtxToken::Semicolon);
267            if spaced {
268                tokens.push(PtxToken::Newline);
269            }
270        }
271    }
272
273    impl PtxUnparser for FmaRndFtzReluF16 {
274        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
275            self.unparse_tokens_mode(tokens, false);
276        }
277        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
278            push_opcode(tokens, "fma");
279            match &self.rnd {
280                Rnd::Rn => {
281                    push_directive(tokens, "rn");
282                }
283            }
284            if self.ftz {
285                push_directive(tokens, "ftz");
286            }
287            push_directive(tokens, "relu");
288            push_directive(tokens, "f16");
289            if spaced {
290                tokens.push(PtxToken::Space);
291            }
292            self.d.unparse_tokens_mode(tokens, spaced);
293            tokens.push(PtxToken::Comma);
294            if spaced {
295                tokens.push(PtxToken::Space);
296            }
297            self.a.unparse_tokens_mode(tokens, spaced);
298            tokens.push(PtxToken::Comma);
299            if spaced {
300                tokens.push(PtxToken::Space);
301            }
302            self.b.unparse_tokens_mode(tokens, spaced);
303            tokens.push(PtxToken::Comma);
304            if spaced {
305                tokens.push(PtxToken::Space);
306            }
307            self.c.unparse_tokens_mode(tokens, spaced);
308            tokens.push(PtxToken::Semicolon);
309            if spaced {
310                tokens.push(PtxToken::Newline);
311            }
312        }
313    }
314
315    impl PtxUnparser for FmaRndFtzReluF16x2 {
316        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
317            self.unparse_tokens_mode(tokens, false);
318        }
319        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
320            push_opcode(tokens, "fma");
321            match &self.rnd {
322                Rnd::Rn => {
323                    push_directive(tokens, "rn");
324                }
325            }
326            if self.ftz {
327                push_directive(tokens, "ftz");
328            }
329            push_directive(tokens, "relu");
330            push_directive(tokens, "f16x2");
331            if spaced {
332                tokens.push(PtxToken::Space);
333            }
334            self.d.unparse_tokens_mode(tokens, spaced);
335            tokens.push(PtxToken::Comma);
336            if spaced {
337                tokens.push(PtxToken::Space);
338            }
339            self.a.unparse_tokens_mode(tokens, spaced);
340            tokens.push(PtxToken::Comma);
341            if spaced {
342                tokens.push(PtxToken::Space);
343            }
344            self.b.unparse_tokens_mode(tokens, spaced);
345            tokens.push(PtxToken::Comma);
346            if spaced {
347                tokens.push(PtxToken::Space);
348            }
349            self.c.unparse_tokens_mode(tokens, spaced);
350            tokens.push(PtxToken::Semicolon);
351            if spaced {
352                tokens.push(PtxToken::Newline);
353            }
354        }
355    }
356
357    impl PtxUnparser for FmaRndReluBf16 {
358        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
359            self.unparse_tokens_mode(tokens, false);
360        }
361        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
362            push_opcode(tokens, "fma");
363            match &self.rnd {
364                Rnd::Rn => {
365                    push_directive(tokens, "rn");
366                }
367            }
368            if self.relu {
369                push_directive(tokens, "relu");
370            }
371            push_directive(tokens, "bf16");
372            if spaced {
373                tokens.push(PtxToken::Space);
374            }
375            self.d.unparse_tokens_mode(tokens, spaced);
376            tokens.push(PtxToken::Comma);
377            if spaced {
378                tokens.push(PtxToken::Space);
379            }
380            self.a.unparse_tokens_mode(tokens, spaced);
381            tokens.push(PtxToken::Comma);
382            if spaced {
383                tokens.push(PtxToken::Space);
384            }
385            self.b.unparse_tokens_mode(tokens, spaced);
386            tokens.push(PtxToken::Comma);
387            if spaced {
388                tokens.push(PtxToken::Space);
389            }
390            self.c.unparse_tokens_mode(tokens, spaced);
391            tokens.push(PtxToken::Semicolon);
392            if spaced {
393                tokens.push(PtxToken::Newline);
394            }
395        }
396    }
397
398    impl PtxUnparser for FmaRndReluBf16x2 {
399        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
400            self.unparse_tokens_mode(tokens, false);
401        }
402        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
403            push_opcode(tokens, "fma");
404            match &self.rnd {
405                Rnd::Rn => {
406                    push_directive(tokens, "rn");
407                }
408            }
409            if self.relu {
410                push_directive(tokens, "relu");
411            }
412            push_directive(tokens, "bf16x2");
413            if spaced {
414                tokens.push(PtxToken::Space);
415            }
416            self.d.unparse_tokens_mode(tokens, spaced);
417            tokens.push(PtxToken::Comma);
418            if spaced {
419                tokens.push(PtxToken::Space);
420            }
421            self.a.unparse_tokens_mode(tokens, spaced);
422            tokens.push(PtxToken::Comma);
423            if spaced {
424                tokens.push(PtxToken::Space);
425            }
426            self.b.unparse_tokens_mode(tokens, spaced);
427            tokens.push(PtxToken::Comma);
428            if spaced {
429                tokens.push(PtxToken::Space);
430            }
431            self.c.unparse_tokens_mode(tokens, spaced);
432            tokens.push(PtxToken::Semicolon);
433            if spaced {
434                tokens.push(PtxToken::Newline);
435            }
436        }
437    }
438
439    impl PtxUnparser for FmaRndOobReluType {
440        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
441            self.unparse_tokens_mode(tokens, false);
442        }
443        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
444            push_opcode(tokens, "fma");
445            match &self.rnd {
446                Rnd::Rn => {
447                    push_directive(tokens, "rn");
448                }
449            }
450            push_directive(tokens, "oob");
451            if self.relu {
452                push_directive(tokens, "relu");
453            }
454            push_directive(tokens, "type");
455            if spaced {
456                tokens.push(PtxToken::Space);
457            }
458            self.d.unparse_tokens_mode(tokens, spaced);
459            tokens.push(PtxToken::Comma);
460            if spaced {
461                tokens.push(PtxToken::Space);
462            }
463            self.a.unparse_tokens_mode(tokens, spaced);
464            tokens.push(PtxToken::Comma);
465            if spaced {
466                tokens.push(PtxToken::Space);
467            }
468            self.b.unparse_tokens_mode(tokens, spaced);
469            tokens.push(PtxToken::Comma);
470            if spaced {
471                tokens.push(PtxToken::Space);
472            }
473            self.c.unparse_tokens_mode(tokens, spaced);
474            tokens.push(PtxToken::Semicolon);
475            if spaced {
476                tokens.push(PtxToken::Newline);
477            }
478        }
479    }
480}
481
482pub mod section_2 {
483    use super::*;
484    use crate::r#type::instruction::fma::section_2::*;
485
486    impl PtxUnparser for FmaRndSatF32Abtype {
487        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
488            self.unparse_tokens_mode(tokens, false);
489        }
490        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
491            push_opcode(tokens, "fma");
492            match &self.rnd {
493                Rnd::Rn => {
494                    push_directive(tokens, "rn");
495                }
496                Rnd::Rz => {
497                    push_directive(tokens, "rz");
498                }
499                Rnd::Rm => {
500                    push_directive(tokens, "rm");
501                }
502                Rnd::Rp => {
503                    push_directive(tokens, "rp");
504                }
505            }
506            if self.sat {
507                push_directive(tokens, "sat");
508            }
509            push_directive(tokens, "f32");
510            match &self.abtype {
511                Abtype::Bf16 => {
512                    push_directive(tokens, "bf16");
513                }
514                Abtype::F16 => {
515                    push_directive(tokens, "f16");
516                }
517            }
518            if spaced {
519                tokens.push(PtxToken::Space);
520            }
521            self.d.unparse_tokens_mode(tokens, spaced);
522            tokens.push(PtxToken::Comma);
523            if spaced {
524                tokens.push(PtxToken::Space);
525            }
526            self.a.unparse_tokens_mode(tokens, spaced);
527            tokens.push(PtxToken::Comma);
528            if spaced {
529                tokens.push(PtxToken::Space);
530            }
531            self.b.unparse_tokens_mode(tokens, spaced);
532            tokens.push(PtxToken::Comma);
533            if spaced {
534                tokens.push(PtxToken::Space);
535            }
536            self.c.unparse_tokens_mode(tokens, spaced);
537            tokens.push(PtxToken::Semicolon);
538            if spaced {
539                tokens.push(PtxToken::Newline);
540            }
541        }
542    }
543}