ptx_parser/unparser/instruction/
add.rs

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