Skip to main content

ptx_parser/unparser/instruction/
max.rs

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