Skip to main content

ptx_parser/unparser/instruction/
vmad.rs

1//! Original PTX specification:
2//!
3//! // 32-bit scalar operation
4//! vmad.dtype.atype.btype{.sat}{.scale}     d, {-}a{.asel}, {-}b{.bsel},
5//! {-}c;
6//! vmad.dtype.atype.btype.po{.sat}{.scale}  d, a{.asel}, b{.bsel}, c;
7//! .dtype = .atype = .btype = { .u32, .s32 };
8//! .asel  = .bsel  = { .b0, .b1, .b2, .b3, .h0, .h1 };
9//! .scale = { .shr7, .shr15 };
10
11#![allow(unused)]
12
13use crate::lexer::PtxToken;
14use crate::unparser::{PtxUnparser, common::*};
15
16pub mod section_0 {
17    use super::*;
18    use crate::r#type::instruction::vmad::section_0::*;
19
20    impl PtxUnparser for VmadDtypeAtypeBtypeSatScale {
21        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
22            self.unparse_tokens_mode(tokens, false);
23        }
24        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
25            push_opcode(tokens, "vmad");
26            match &self.dtype {
27                Dtype::U32 => {
28                    push_directive(tokens, "u32");
29                }
30                Dtype::S32 => {
31                    push_directive(tokens, "s32");
32                }
33            }
34            match &self.atype {
35                Atype::U32 => {
36                    push_directive(tokens, "u32");
37                }
38                Atype::S32 => {
39                    push_directive(tokens, "s32");
40                }
41            }
42            match &self.btype {
43                Btype::U32 => {
44                    push_directive(tokens, "u32");
45                }
46                Btype::S32 => {
47                    push_directive(tokens, "s32");
48                }
49            }
50            if self.sat {
51                push_directive(tokens, "sat");
52            }
53            if let Some(scale_0) = self.scale.as_ref() {
54                match scale_0 {
55                    Scale::Shr15 => {
56                        push_directive(tokens, "shr15");
57                    }
58                    Scale::Shr7 => {
59                        push_directive(tokens, "shr7");
60                    }
61                }
62            }
63            if spaced {
64                tokens.push(PtxToken::Space);
65            }
66            self.d.unparse_tokens_mode(tokens, spaced);
67            tokens.push(PtxToken::Comma);
68            if self.a_op {
69                tokens.push(PtxToken::Minus);
70            }
71            if spaced {
72                tokens.push(PtxToken::Space);
73            }
74            self.a.unparse_tokens_mode(tokens, spaced);
75            if let Some(asel_1) = self.asel.as_ref() {
76                match asel_1 {
77                    Asel::B0 => {
78                        push_directive(tokens, "b0");
79                    }
80                    Asel::B1 => {
81                        push_directive(tokens, "b1");
82                    }
83                    Asel::B2 => {
84                        push_directive(tokens, "b2");
85                    }
86                    Asel::B3 => {
87                        push_directive(tokens, "b3");
88                    }
89                    Asel::H0 => {
90                        push_directive(tokens, "h0");
91                    }
92                    Asel::H1 => {
93                        push_directive(tokens, "h1");
94                    }
95                }
96            }
97            tokens.push(PtxToken::Comma);
98            if self.b_op {
99                tokens.push(PtxToken::Minus);
100            }
101            if spaced {
102                tokens.push(PtxToken::Space);
103            }
104            self.b.unparse_tokens_mode(tokens, spaced);
105            if let Some(bsel_2) = self.bsel.as_ref() {
106                match bsel_2 {
107                    Bsel::B0 => {
108                        push_directive(tokens, "b0");
109                    }
110                    Bsel::B1 => {
111                        push_directive(tokens, "b1");
112                    }
113                    Bsel::B2 => {
114                        push_directive(tokens, "b2");
115                    }
116                    Bsel::B3 => {
117                        push_directive(tokens, "b3");
118                    }
119                    Bsel::H0 => {
120                        push_directive(tokens, "h0");
121                    }
122                    Bsel::H1 => {
123                        push_directive(tokens, "h1");
124                    }
125                }
126            }
127            tokens.push(PtxToken::Comma);
128            if self.c_op {
129                tokens.push(PtxToken::Minus);
130            }
131            if spaced {
132                tokens.push(PtxToken::Space);
133            }
134            self.c.unparse_tokens_mode(tokens, spaced);
135            tokens.push(PtxToken::Semicolon);
136            if spaced {
137                tokens.push(PtxToken::Newline);
138            }
139        }
140    }
141
142    impl PtxUnparser for VmadDtypeAtypeBtypePoSatScale {
143        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
144            self.unparse_tokens_mode(tokens, false);
145        }
146        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
147            push_opcode(tokens, "vmad");
148            match &self.dtype {
149                Dtype::U32 => {
150                    push_directive(tokens, "u32");
151                }
152                Dtype::S32 => {
153                    push_directive(tokens, "s32");
154                }
155            }
156            match &self.atype {
157                Atype::U32 => {
158                    push_directive(tokens, "u32");
159                }
160                Atype::S32 => {
161                    push_directive(tokens, "s32");
162                }
163            }
164            match &self.btype {
165                Btype::U32 => {
166                    push_directive(tokens, "u32");
167                }
168                Btype::S32 => {
169                    push_directive(tokens, "s32");
170                }
171            }
172            push_directive(tokens, "po");
173            if self.sat {
174                push_directive(tokens, "sat");
175            }
176            if let Some(scale_3) = self.scale.as_ref() {
177                match scale_3 {
178                    Scale::Shr15 => {
179                        push_directive(tokens, "shr15");
180                    }
181                    Scale::Shr7 => {
182                        push_directive(tokens, "shr7");
183                    }
184                }
185            }
186            if spaced {
187                tokens.push(PtxToken::Space);
188            }
189            self.d.unparse_tokens_mode(tokens, spaced);
190            tokens.push(PtxToken::Comma);
191            if spaced {
192                tokens.push(PtxToken::Space);
193            }
194            self.a.unparse_tokens_mode(tokens, spaced);
195            if let Some(asel_4) = self.asel.as_ref() {
196                match asel_4 {
197                    Asel::B0 => {
198                        push_directive(tokens, "b0");
199                    }
200                    Asel::B1 => {
201                        push_directive(tokens, "b1");
202                    }
203                    Asel::B2 => {
204                        push_directive(tokens, "b2");
205                    }
206                    Asel::B3 => {
207                        push_directive(tokens, "b3");
208                    }
209                    Asel::H0 => {
210                        push_directive(tokens, "h0");
211                    }
212                    Asel::H1 => {
213                        push_directive(tokens, "h1");
214                    }
215                }
216            }
217            tokens.push(PtxToken::Comma);
218            if spaced {
219                tokens.push(PtxToken::Space);
220            }
221            self.b.unparse_tokens_mode(tokens, spaced);
222            if let Some(bsel_5) = self.bsel.as_ref() {
223                match bsel_5 {
224                    Bsel::B0 => {
225                        push_directive(tokens, "b0");
226                    }
227                    Bsel::B1 => {
228                        push_directive(tokens, "b1");
229                    }
230                    Bsel::B2 => {
231                        push_directive(tokens, "b2");
232                    }
233                    Bsel::B3 => {
234                        push_directive(tokens, "b3");
235                    }
236                    Bsel::H0 => {
237                        push_directive(tokens, "h0");
238                    }
239                    Bsel::H1 => {
240                        push_directive(tokens, "h1");
241                    }
242                }
243            }
244            tokens.push(PtxToken::Comma);
245            if spaced {
246                tokens.push(PtxToken::Space);
247            }
248            self.c.unparse_tokens_mode(tokens, spaced);
249            tokens.push(PtxToken::Semicolon);
250            if spaced {
251                tokens.push(PtxToken::Newline);
252            }
253        }
254    }
255}