Skip to main content

ptx_parser/unparser/instruction/
cvta.rs

1//! Original PTX specification:
2//!
3//! // convert const, global, local, or shared address to generic address
4//! cvta.space.size  p, a;        // source address in register a
5//! // cvta.space.size  p, var;      // get generic address of var
6//! // cvta.space.size  p, var+imm;  // generic address of var+offset
7//! // convert generic address to const, global, local, or shared address
8//! cvta.to.space.size  p, a;
9//! .space = { .const, .global, .local, .shared, .shared::cta, .shared::cluster, .param, .param::entry };
10//! .size  = { .u32, .u64 };
11
12#![allow(unused)]
13
14use crate::lexer::PtxToken;
15use crate::unparser::{PtxUnparser, common::*};
16
17pub mod section_0 {
18    use super::*;
19    use crate::r#type::instruction::cvta::section_0::*;
20
21    impl PtxUnparser for CvtaSpaceSize {
22        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
23            self.unparse_tokens_mode(tokens, false);
24        }
25        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
26            push_opcode(tokens, "cvta");
27            match &self.space {
28                Space::SharedCluster => {
29                    push_directive(tokens, "shared::cluster");
30                }
31                Space::ParamEntry => {
32                    push_directive(tokens, "param::entry");
33                }
34                Space::SharedCta => {
35                    push_directive(tokens, "shared::cta");
36                }
37                Space::Global => {
38                    push_directive(tokens, "global");
39                }
40                Space::Shared => {
41                    push_directive(tokens, "shared");
42                }
43                Space::Const => {
44                    push_directive(tokens, "const");
45                }
46                Space::Local => {
47                    push_directive(tokens, "local");
48                }
49                Space::Param => {
50                    push_directive(tokens, "param");
51                }
52            }
53            match &self.size {
54                Size::U32 => {
55                    push_directive(tokens, "u32");
56                }
57                Size::U64 => {
58                    push_directive(tokens, "u64");
59                }
60            }
61            if spaced {
62                tokens.push(PtxToken::Space);
63            }
64            self.p.unparse_tokens_mode(tokens, spaced);
65            tokens.push(PtxToken::Comma);
66            if spaced {
67                tokens.push(PtxToken::Space);
68            }
69            self.a.unparse_tokens_mode(tokens, spaced);
70            tokens.push(PtxToken::Semicolon);
71            if spaced {
72                tokens.push(PtxToken::Newline);
73            }
74        }
75    }
76
77    impl PtxUnparser for CvtaToSpaceSize {
78        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
79            self.unparse_tokens_mode(tokens, false);
80        }
81        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
82            push_opcode(tokens, "cvta");
83            push_directive(tokens, "to");
84            match &self.space {
85                Space::SharedCluster => {
86                    push_directive(tokens, "shared::cluster");
87                }
88                Space::ParamEntry => {
89                    push_directive(tokens, "param::entry");
90                }
91                Space::SharedCta => {
92                    push_directive(tokens, "shared::cta");
93                }
94                Space::Global => {
95                    push_directive(tokens, "global");
96                }
97                Space::Shared => {
98                    push_directive(tokens, "shared");
99                }
100                Space::Const => {
101                    push_directive(tokens, "const");
102                }
103                Space::Local => {
104                    push_directive(tokens, "local");
105                }
106                Space::Param => {
107                    push_directive(tokens, "param");
108                }
109            }
110            match &self.size {
111                Size::U32 => {
112                    push_directive(tokens, "u32");
113                }
114                Size::U64 => {
115                    push_directive(tokens, "u64");
116                }
117            }
118            if spaced {
119                tokens.push(PtxToken::Space);
120            }
121            self.p.unparse_tokens_mode(tokens, spaced);
122            tokens.push(PtxToken::Comma);
123            if spaced {
124                tokens.push(PtxToken::Space);
125            }
126            self.a.unparse_tokens_mode(tokens, spaced);
127            tokens.push(PtxToken::Semicolon);
128            if spaced {
129                tokens.push(PtxToken::Newline);
130            }
131        }
132    }
133}