Skip to main content

ptx_parser/unparser/instruction/
slct.rs

1//! Original PTX specification:
2//!
3//! slct.dtype.s32        d, a, b, c;
4//! slct{.ftz}.dtype.f32  d, a, b, c;
5//! .dtype = { .b16, .b32, .b64,
6//! .u16, .u32, .u64,
7//! .s16, .s32, .s64,
8//! .f32, .f64 };
9
10#![allow(unused)]
11
12use crate::lexer::PtxToken;
13use crate::unparser::{PtxUnparser, common::*};
14
15pub mod section_0 {
16    use super::*;
17    use crate::r#type::instruction::slct::section_0::*;
18
19    impl PtxUnparser for SlctDtypeS32 {
20        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
21            self.unparse_tokens_mode(tokens, false);
22        }
23        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
24            push_opcode(tokens, "slct");
25            match &self.dtype {
26                Dtype::B16 => {
27                    push_directive(tokens, "b16");
28                }
29                Dtype::B32 => {
30                    push_directive(tokens, "b32");
31                }
32                Dtype::B64 => {
33                    push_directive(tokens, "b64");
34                }
35                Dtype::U16 => {
36                    push_directive(tokens, "u16");
37                }
38                Dtype::U32 => {
39                    push_directive(tokens, "u32");
40                }
41                Dtype::U64 => {
42                    push_directive(tokens, "u64");
43                }
44                Dtype::S16 => {
45                    push_directive(tokens, "s16");
46                }
47                Dtype::S32 => {
48                    push_directive(tokens, "s32");
49                }
50                Dtype::S64 => {
51                    push_directive(tokens, "s64");
52                }
53                Dtype::F32 => {
54                    push_directive(tokens, "f32");
55                }
56                Dtype::F64 => {
57                    push_directive(tokens, "f64");
58                }
59            }
60            push_directive(tokens, "s32");
61            if spaced {
62                tokens.push(PtxToken::Space);
63            }
64            self.d.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::Comma);
71            if spaced {
72                tokens.push(PtxToken::Space);
73            }
74            self.b.unparse_tokens_mode(tokens, spaced);
75            tokens.push(PtxToken::Comma);
76            if spaced {
77                tokens.push(PtxToken::Space);
78            }
79            self.c.unparse_tokens_mode(tokens, spaced);
80            tokens.push(PtxToken::Semicolon);
81            if spaced {
82                tokens.push(PtxToken::Newline);
83            }
84        }
85    }
86
87    impl PtxUnparser for SlctFtzDtypeF32 {
88        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
89            self.unparse_tokens_mode(tokens, false);
90        }
91        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
92            push_opcode(tokens, "slct");
93            if self.ftz {
94                push_directive(tokens, "ftz");
95            }
96            match &self.dtype {
97                Dtype::B16 => {
98                    push_directive(tokens, "b16");
99                }
100                Dtype::B32 => {
101                    push_directive(tokens, "b32");
102                }
103                Dtype::B64 => {
104                    push_directive(tokens, "b64");
105                }
106                Dtype::U16 => {
107                    push_directive(tokens, "u16");
108                }
109                Dtype::U32 => {
110                    push_directive(tokens, "u32");
111                }
112                Dtype::U64 => {
113                    push_directive(tokens, "u64");
114                }
115                Dtype::S16 => {
116                    push_directive(tokens, "s16");
117                }
118                Dtype::S32 => {
119                    push_directive(tokens, "s32");
120                }
121                Dtype::S64 => {
122                    push_directive(tokens, "s64");
123                }
124                Dtype::F32 => {
125                    push_directive(tokens, "f32");
126                }
127                Dtype::F64 => {
128                    push_directive(tokens, "f64");
129                }
130            }
131            push_directive(tokens, "f32");
132            if spaced {
133                tokens.push(PtxToken::Space);
134            }
135            self.d.unparse_tokens_mode(tokens, spaced);
136            tokens.push(PtxToken::Comma);
137            if spaced {
138                tokens.push(PtxToken::Space);
139            }
140            self.a.unparse_tokens_mode(tokens, spaced);
141            tokens.push(PtxToken::Comma);
142            if spaced {
143                tokens.push(PtxToken::Space);
144            }
145            self.b.unparse_tokens_mode(tokens, spaced);
146            tokens.push(PtxToken::Comma);
147            if spaced {
148                tokens.push(PtxToken::Space);
149            }
150            self.c.unparse_tokens_mode(tokens, spaced);
151            tokens.push(PtxToken::Semicolon);
152            if spaced {
153                tokens.push(PtxToken::Newline);
154            }
155        }
156    }
157}