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            push_opcode(tokens, "vmad");
23            match &self.dtype {
24                Dtype::U32 => {
25                    push_directive(tokens, "u32");
26                }
27                Dtype::S32 => {
28                    push_directive(tokens, "s32");
29                }
30            }
31            match &self.atype {
32                Atype::U32 => {
33                    push_directive(tokens, "u32");
34                }
35                Atype::S32 => {
36                    push_directive(tokens, "s32");
37                }
38            }
39            match &self.btype {
40                Btype::U32 => {
41                    push_directive(tokens, "u32");
42                }
43                Btype::S32 => {
44                    push_directive(tokens, "s32");
45                }
46            }
47            if self.sat {
48                push_directive(tokens, "sat");
49            }
50            if let Some(scale_0) = self.scale.as_ref() {
51                match scale_0 {
52                    Scale::Shr15 => {
53                        push_directive(tokens, "shr15");
54                    }
55                    Scale::Shr7 => {
56                        push_directive(tokens, "shr7");
57                    }
58                }
59            }
60            self.d.unparse_tokens(tokens);
61            tokens.push(PtxToken::Comma);
62            if self.a_op {
63                tokens.push(PtxToken::Minus);
64            }
65            self.a.unparse_tokens(tokens);
66            if let Some(asel_1) = self.asel.as_ref() {
67                match asel_1 {
68                    Asel::B0 => {
69                        push_directive(tokens, "b0");
70                    }
71                    Asel::B1 => {
72                        push_directive(tokens, "b1");
73                    }
74                    Asel::B2 => {
75                        push_directive(tokens, "b2");
76                    }
77                    Asel::B3 => {
78                        push_directive(tokens, "b3");
79                    }
80                    Asel::H0 => {
81                        push_directive(tokens, "h0");
82                    }
83                    Asel::H1 => {
84                        push_directive(tokens, "h1");
85                    }
86                }
87            }
88            tokens.push(PtxToken::Comma);
89            if self.b_op {
90                tokens.push(PtxToken::Minus);
91            }
92            self.b.unparse_tokens(tokens);
93            if let Some(bsel_2) = self.bsel.as_ref() {
94                match bsel_2 {
95                    Bsel::B0 => {
96                        push_directive(tokens, "b0");
97                    }
98                    Bsel::B1 => {
99                        push_directive(tokens, "b1");
100                    }
101                    Bsel::B2 => {
102                        push_directive(tokens, "b2");
103                    }
104                    Bsel::B3 => {
105                        push_directive(tokens, "b3");
106                    }
107                    Bsel::H0 => {
108                        push_directive(tokens, "h0");
109                    }
110                    Bsel::H1 => {
111                        push_directive(tokens, "h1");
112                    }
113                }
114            }
115            tokens.push(PtxToken::Comma);
116            if self.c_op {
117                tokens.push(PtxToken::Minus);
118            }
119            self.c.unparse_tokens(tokens);
120            tokens.push(PtxToken::Semicolon);
121        }
122    }
123
124    impl PtxUnparser for VmadDtypeAtypeBtypePoSatScale {
125        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
126            push_opcode(tokens, "vmad");
127            match &self.dtype {
128                Dtype::U32 => {
129                    push_directive(tokens, "u32");
130                }
131                Dtype::S32 => {
132                    push_directive(tokens, "s32");
133                }
134            }
135            match &self.atype {
136                Atype::U32 => {
137                    push_directive(tokens, "u32");
138                }
139                Atype::S32 => {
140                    push_directive(tokens, "s32");
141                }
142            }
143            match &self.btype {
144                Btype::U32 => {
145                    push_directive(tokens, "u32");
146                }
147                Btype::S32 => {
148                    push_directive(tokens, "s32");
149                }
150            }
151            push_directive(tokens, "po");
152            if self.sat {
153                push_directive(tokens, "sat");
154            }
155            if let Some(scale_3) = self.scale.as_ref() {
156                match scale_3 {
157                    Scale::Shr15 => {
158                        push_directive(tokens, "shr15");
159                    }
160                    Scale::Shr7 => {
161                        push_directive(tokens, "shr7");
162                    }
163                }
164            }
165            self.d.unparse_tokens(tokens);
166            tokens.push(PtxToken::Comma);
167            self.a.unparse_tokens(tokens);
168            if let Some(asel_4) = self.asel.as_ref() {
169                match asel_4 {
170                    Asel::B0 => {
171                        push_directive(tokens, "b0");
172                    }
173                    Asel::B1 => {
174                        push_directive(tokens, "b1");
175                    }
176                    Asel::B2 => {
177                        push_directive(tokens, "b2");
178                    }
179                    Asel::B3 => {
180                        push_directive(tokens, "b3");
181                    }
182                    Asel::H0 => {
183                        push_directive(tokens, "h0");
184                    }
185                    Asel::H1 => {
186                        push_directive(tokens, "h1");
187                    }
188                }
189            }
190            tokens.push(PtxToken::Comma);
191            self.b.unparse_tokens(tokens);
192            if let Some(bsel_5) = self.bsel.as_ref() {
193                match bsel_5 {
194                    Bsel::B0 => {
195                        push_directive(tokens, "b0");
196                    }
197                    Bsel::B1 => {
198                        push_directive(tokens, "b1");
199                    }
200                    Bsel::B2 => {
201                        push_directive(tokens, "b2");
202                    }
203                    Bsel::B3 => {
204                        push_directive(tokens, "b3");
205                    }
206                    Bsel::H0 => {
207                        push_directive(tokens, "h0");
208                    }
209                    Bsel::H1 => {
210                        push_directive(tokens, "h1");
211                    }
212                }
213            }
214            tokens.push(PtxToken::Comma);
215            self.c.unparse_tokens(tokens);
216            tokens.push(PtxToken::Semicolon);
217        }
218    }
219}