Skip to main content

ptx_parser/unparser/instruction/
cvt_pack.rs

1//! Original PTX specification:
2//!
3//! cvt.pack.sat.convertType.abType  d, a, b;
4//! .convertType  = { .u16, .s16 };
5//! .abType       = { .s32 };
6//! ----------------------------------------------------------------
7//! cvt.pack.sat.convertType.abType.cType  d, a, b, c;
8//! .convertType  = { .u2, .s2, .u4, .s4, .u8, .s8 };
9//! .abType       = { .s32 };
10//! .cType        = { .b32 };
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::cvt_pack::section_0::*;
20
21    impl PtxUnparser for CvtPackSatConverttypeAbtype {
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, "cvt");
27            push_directive(tokens, "pack");
28            push_directive(tokens, "sat");
29            match &self.converttype {
30                Converttype::U16 => {
31                    push_directive(tokens, "u16");
32                }
33                Converttype::S16 => {
34                    push_directive(tokens, "s16");
35                }
36            }
37            match &self.abtype {
38                Abtype::S32 => {
39                    push_directive(tokens, "s32");
40                }
41            }
42            if spaced {
43                tokens.push(PtxToken::Space);
44            }
45            self.d.unparse_tokens_mode(tokens, spaced);
46            tokens.push(PtxToken::Comma);
47            if spaced {
48                tokens.push(PtxToken::Space);
49            }
50            self.a.unparse_tokens_mode(tokens, spaced);
51            tokens.push(PtxToken::Comma);
52            if spaced {
53                tokens.push(PtxToken::Space);
54            }
55            self.b.unparse_tokens_mode(tokens, spaced);
56            tokens.push(PtxToken::Semicolon);
57            if spaced {
58                tokens.push(PtxToken::Newline);
59            }
60        }
61    }
62}
63
64pub mod section_1 {
65    use super::*;
66    use crate::r#type::instruction::cvt_pack::section_1::*;
67
68    impl PtxUnparser for CvtPackSatConverttypeAbtypeCtype {
69        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
70            self.unparse_tokens_mode(tokens, false);
71        }
72        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
73            push_opcode(tokens, "cvt");
74            push_directive(tokens, "pack");
75            push_directive(tokens, "sat");
76            match &self.converttype {
77                Converttype::U2 => {
78                    push_directive(tokens, "u2");
79                }
80                Converttype::S2 => {
81                    push_directive(tokens, "s2");
82                }
83                Converttype::U4 => {
84                    push_directive(tokens, "u4");
85                }
86                Converttype::S4 => {
87                    push_directive(tokens, "s4");
88                }
89                Converttype::U8 => {
90                    push_directive(tokens, "u8");
91                }
92                Converttype::S8 => {
93                    push_directive(tokens, "s8");
94                }
95            }
96            match &self.abtype {
97                Abtype::S32 => {
98                    push_directive(tokens, "s32");
99                }
100            }
101            match &self.ctype {
102                Ctype::B32 => {
103                    push_directive(tokens, "b32");
104                }
105            }
106            if spaced {
107                tokens.push(PtxToken::Space);
108            }
109            self.d.unparse_tokens_mode(tokens, spaced);
110            tokens.push(PtxToken::Comma);
111            if spaced {
112                tokens.push(PtxToken::Space);
113            }
114            self.a.unparse_tokens_mode(tokens, spaced);
115            tokens.push(PtxToken::Comma);
116            if spaced {
117                tokens.push(PtxToken::Space);
118            }
119            self.b.unparse_tokens_mode(tokens, spaced);
120            tokens.push(PtxToken::Comma);
121            if spaced {
122                tokens.push(PtxToken::Space);
123            }
124            self.c.unparse_tokens_mode(tokens, spaced);
125            tokens.push(PtxToken::Semicolon);
126            if spaced {
127                tokens.push(PtxToken::Newline);
128            }
129        }
130    }
131}