ptx_parser/parser/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::parser::{
15    PtxParseError, PtxParser, PtxTokenStream, Span,
16    util::{
17        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
18        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
19    },
20};
21use crate::r#type::common::*;
22use crate::{alt, ok, seq_n};
23
24pub mod section_0 {
25    use super::*;
26    use crate::r#type::instruction::cvt_pack::section_0::*;
27
28    // ============================================================================
29    // Generated enum parsers
30    // ============================================================================
31
32    impl PtxParser for Abtype {
33        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
34            alt!(map(string_p(".s32"), |_, _span| Abtype::S32))
35        }
36    }
37
38    impl PtxParser for Converttype {
39        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
40            alt!(
41                map(string_p(".u16"), |_, _span| Converttype::U16),
42                map(string_p(".s16"), |_, _span| Converttype::S16)
43            )
44        }
45    }
46
47    impl PtxParser for CvtPackSatConverttypeAbtype {
48        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
49            try_map(
50                seq_n!(
51                    string_p("cvt"),
52                    string_p(".pack"),
53                    string_p(".sat"),
54                    Converttype::parse(),
55                    Abtype::parse(),
56                    GeneralOperand::parse(),
57                    comma_p(),
58                    GeneralOperand::parse(),
59                    comma_p(),
60                    GeneralOperand::parse(),
61                    semicolon_p()
62                ),
63                |(_, pack, sat, converttype, abtype, d, _, a, _, b, _), span| {
64                    ok!(CvtPackSatConverttypeAbtype {
65                        pack = pack,
66                        sat = sat,
67                        converttype = converttype,
68                        abtype = abtype,
69                        d = d,
70                        a = a,
71                        b = b,
72
73                    })
74                },
75            )
76        }
77    }
78}
79
80pub mod section_1 {
81    use super::*;
82    use crate::r#type::instruction::cvt_pack::section_1::*;
83
84    // ============================================================================
85    // Generated enum parsers
86    // ============================================================================
87
88    impl PtxParser for Abtype {
89        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
90            alt!(map(string_p(".s32"), |_, _span| Abtype::S32))
91        }
92    }
93
94    impl PtxParser for Converttype {
95        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
96            alt!(
97                map(string_p(".u2"), |_, _span| Converttype::U2),
98                map(string_p(".s2"), |_, _span| Converttype::S2),
99                map(string_p(".u4"), |_, _span| Converttype::U4),
100                map(string_p(".s4"), |_, _span| Converttype::S4),
101                map(string_p(".u8"), |_, _span| Converttype::U8),
102                map(string_p(".s8"), |_, _span| Converttype::S8)
103            )
104        }
105    }
106
107    impl PtxParser for Ctype {
108        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
109            alt!(map(string_p(".b32"), |_, _span| Ctype::B32))
110        }
111    }
112
113    impl PtxParser for CvtPackSatConverttypeAbtypeCtype {
114        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
115            try_map(
116                seq_n!(
117                    string_p("cvt"),
118                    string_p(".pack"),
119                    string_p(".sat"),
120                    Converttype::parse(),
121                    Abtype::parse(),
122                    Ctype::parse(),
123                    GeneralOperand::parse(),
124                    comma_p(),
125                    GeneralOperand::parse(),
126                    comma_p(),
127                    GeneralOperand::parse(),
128                    comma_p(),
129                    GeneralOperand::parse(),
130                    semicolon_p()
131                ),
132                |(_, pack, sat, converttype, abtype, ctype, d, _, a, _, b, _, c, _), span| {
133                    ok!(CvtPackSatConverttypeAbtypeCtype {
134                        pack = pack,
135                        sat = sat,
136                        converttype = converttype,
137                        abtype = abtype,
138                        ctype = ctype,
139                        d = d,
140                        a = a,
141                        b = b,
142                        c = c,
143
144                    })
145                },
146            )
147        }
148    }
149}