Skip to main content

ptx_parser/unparser/instruction/
mov.rs

1//! Original PTX specification:
2//!
3//! mov.type  d, a;
4//! // mov.type  d, sreg;
5//! // mov.type  d, avar;       // get address of variable
6//! // mov.type  d, avar+imm;   // get address of variable with offset
7//! mov.u32   d, fname;      // get address of device function
8//! mov.u64   d, fname;      // get address of device function
9//! mov.u32   d, kernel;     // get address of entry function
10//! mov.u64   d, kernel;     // get address of entry function
11//! .type = { .pred,
12//! .b16, .b32, .b64,
13//! .u16, .u32, .u64,
14//! .s16, .s32, .s64,
15//! .f32, .f64 };
16//! ----------------------------------------------
17//! mov.type  d, a;
18//! .type = { .b16, .b32, .b64, .b128 };
19
20#![allow(unused)]
21
22use crate::lexer::PtxToken;
23use crate::unparser::{PtxUnparser, common::*};
24
25pub mod section_0 {
26    use super::*;
27    use crate::r#type::instruction::mov::section_0::*;
28
29    impl PtxUnparser for MovType {
30        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
31            self.unparse_tokens_mode(tokens, false);
32        }
33        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
34            push_opcode(tokens, "mov");
35            match &self.type_ {
36                Type::Pred => {
37                    push_directive(tokens, "pred");
38                }
39                Type::B16 => {
40                    push_directive(tokens, "b16");
41                }
42                Type::B32 => {
43                    push_directive(tokens, "b32");
44                }
45                Type::B64 => {
46                    push_directive(tokens, "b64");
47                }
48                Type::U16 => {
49                    push_directive(tokens, "u16");
50                }
51                Type::U32 => {
52                    push_directive(tokens, "u32");
53                }
54                Type::U64 => {
55                    push_directive(tokens, "u64");
56                }
57                Type::S16 => {
58                    push_directive(tokens, "s16");
59                }
60                Type::S32 => {
61                    push_directive(tokens, "s32");
62                }
63                Type::S64 => {
64                    push_directive(tokens, "s64");
65                }
66                Type::F32 => {
67                    push_directive(tokens, "f32");
68                }
69                Type::F64 => {
70                    push_directive(tokens, "f64");
71                }
72            }
73            if spaced {
74                tokens.push(PtxToken::Space);
75            }
76            self.d.unparse_tokens_mode(tokens, spaced);
77            tokens.push(PtxToken::Comma);
78            if spaced {
79                tokens.push(PtxToken::Space);
80            }
81            self.a.unparse_tokens_mode(tokens, spaced);
82            tokens.push(PtxToken::Semicolon);
83            if spaced {
84                tokens.push(PtxToken::Newline);
85            }
86        }
87    }
88
89    impl PtxUnparser for MovU32 {
90        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
91            self.unparse_tokens_mode(tokens, false);
92        }
93        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
94            push_opcode(tokens, "mov");
95            push_directive(tokens, "u32");
96            if spaced {
97                tokens.push(PtxToken::Space);
98            }
99            self.d.unparse_tokens_mode(tokens, spaced);
100            tokens.push(PtxToken::Comma);
101            if spaced {
102                tokens.push(PtxToken::Space);
103            }
104            self.fname.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 MovU64 {
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, "mov");
118            push_directive(tokens, "u64");
119            if spaced {
120                tokens.push(PtxToken::Space);
121            }
122            self.d.unparse_tokens_mode(tokens, spaced);
123            tokens.push(PtxToken::Comma);
124            if spaced {
125                tokens.push(PtxToken::Space);
126            }
127            self.fname.unparse_tokens_mode(tokens, spaced);
128            tokens.push(PtxToken::Semicolon);
129            if spaced {
130                tokens.push(PtxToken::Newline);
131            }
132        }
133    }
134
135    impl PtxUnparser for MovU321 {
136        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
137            self.unparse_tokens_mode(tokens, false);
138        }
139        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
140            push_opcode(tokens, "mov");
141            push_directive(tokens, "u32");
142            if spaced {
143                tokens.push(PtxToken::Space);
144            }
145            self.d.unparse_tokens_mode(tokens, spaced);
146            tokens.push(PtxToken::Comma);
147            if spaced {
148                tokens.push(PtxToken::Space);
149            }
150            self.kernel.unparse_tokens_mode(tokens, spaced);
151            tokens.push(PtxToken::Semicolon);
152            if spaced {
153                tokens.push(PtxToken::Newline);
154            }
155        }
156    }
157
158    impl PtxUnparser for MovU641 {
159        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
160            self.unparse_tokens_mode(tokens, false);
161        }
162        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
163            push_opcode(tokens, "mov");
164            push_directive(tokens, "u64");
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.kernel.unparse_tokens_mode(tokens, spaced);
174            tokens.push(PtxToken::Semicolon);
175            if spaced {
176                tokens.push(PtxToken::Newline);
177            }
178        }
179    }
180}
181
182pub mod section_1 {
183    use super::*;
184    use crate::r#type::instruction::mov::section_1::*;
185
186    impl PtxUnparser for MovType1 {
187        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
188            self.unparse_tokens_mode(tokens, false);
189        }
190        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
191            push_opcode(tokens, "mov");
192            match &self.type_ {
193                Type::B128 => {
194                    push_directive(tokens, "b128");
195                }
196                Type::B16 => {
197                    push_directive(tokens, "b16");
198                }
199                Type::B32 => {
200                    push_directive(tokens, "b32");
201                }
202                Type::B64 => {
203                    push_directive(tokens, "b64");
204                }
205            }
206            if spaced {
207                tokens.push(PtxToken::Space);
208            }
209            self.d.unparse_tokens_mode(tokens, spaced);
210            tokens.push(PtxToken::Comma);
211            if spaced {
212                tokens.push(PtxToken::Space);
213            }
214            self.a.unparse_tokens_mode(tokens, spaced);
215            tokens.push(PtxToken::Semicolon);
216            if spaced {
217                tokens.push(PtxToken::Newline);
218            }
219        }
220    }
221}