ptx_parser/parser/instruction/
vset.rs

1//! Original PTX specification:
2//!
3//! // 32-bit scalar operation, with optional secondary operation
4//! vset.atype.btype.cmp       d, a{.asel}, b{.bsel};
5//! vset.atype.btype.cmp.op2   d, a{.asel}, b{.bsel}, c;
6//! // 32-bit scalar operation, with optional data merge
7//! vset.atype.btype.cmp  d.dsel, a{.asel}, b{.bsel}, c;
8//! .atype = .btype = { .u32, .s32 };
9//! .cmp   = { .eq, .ne, .lt, .le, .gt, .ge };
10//! .dsel  = .asel  = .bsel  = { .b0, .b1, .b2, .b3, .h0, .h1 };
11//! .op2   = { .add, .min, .max };
12
13#![allow(unused)]
14
15use crate::parser::{
16    PtxParseError, PtxParser, PtxTokenStream, Span,
17    util::{
18        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
19        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
20    },
21};
22use crate::r#type::common::*;
23use crate::{alt, ok, seq_n};
24
25pub mod section_0 {
26    use super::*;
27    use crate::r#type::instruction::vset::section_0::*;
28
29    // ============================================================================
30    // Generated enum parsers
31    // ============================================================================
32
33    impl PtxParser for Asel {
34        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
35            alt!(
36                map(string_p(".b0"), |_, _span| Asel::B0),
37                map(string_p(".b1"), |_, _span| Asel::B1),
38                map(string_p(".b2"), |_, _span| Asel::B2),
39                map(string_p(".b3"), |_, _span| Asel::B3),
40                map(string_p(".h0"), |_, _span| Asel::H0),
41                map(string_p(".h1"), |_, _span| Asel::H1)
42            )
43        }
44    }
45
46    impl PtxParser for Atype {
47        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
48            alt!(
49                map(string_p(".u32"), |_, _span| Atype::U32),
50                map(string_p(".s32"), |_, _span| Atype::S32)
51            )
52        }
53    }
54
55    impl PtxParser for Bsel {
56        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
57            alt!(
58                map(string_p(".b0"), |_, _span| Bsel::B0),
59                map(string_p(".b1"), |_, _span| Bsel::B1),
60                map(string_p(".b2"), |_, _span| Bsel::B2),
61                map(string_p(".b3"), |_, _span| Bsel::B3),
62                map(string_p(".h0"), |_, _span| Bsel::H0),
63                map(string_p(".h1"), |_, _span| Bsel::H1)
64            )
65        }
66    }
67
68    impl PtxParser for Btype {
69        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
70            alt!(
71                map(string_p(".u32"), |_, _span| Btype::U32),
72                map(string_p(".s32"), |_, _span| Btype::S32)
73            )
74        }
75    }
76
77    impl PtxParser for Cmp {
78        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
79            alt!(
80                map(string_p(".eq"), |_, _span| Cmp::Eq),
81                map(string_p(".ne"), |_, _span| Cmp::Ne),
82                map(string_p(".lt"), |_, _span| Cmp::Lt),
83                map(string_p(".le"), |_, _span| Cmp::Le),
84                map(string_p(".gt"), |_, _span| Cmp::Gt),
85                map(string_p(".ge"), |_, _span| Cmp::Ge)
86            )
87        }
88    }
89
90    impl PtxParser for Dsel {
91        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
92            alt!(
93                map(string_p(".b0"), |_, _span| Dsel::B0),
94                map(string_p(".b1"), |_, _span| Dsel::B1),
95                map(string_p(".b2"), |_, _span| Dsel::B2),
96                map(string_p(".b3"), |_, _span| Dsel::B3),
97                map(string_p(".h0"), |_, _span| Dsel::H0),
98                map(string_p(".h1"), |_, _span| Dsel::H1)
99            )
100        }
101    }
102
103    impl PtxParser for Op2 {
104        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
105            alt!(
106                map(string_p(".add"), |_, _span| Op2::Add),
107                map(string_p(".min"), |_, _span| Op2::Min),
108                map(string_p(".max"), |_, _span| Op2::Max)
109            )
110        }
111    }
112
113    impl PtxParser for VsetAtypeBtypeCmp {
114        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
115            try_map(
116                seq_n!(
117                    string_p("vset"),
118                    Atype::parse(),
119                    Btype::parse(),
120                    Cmp::parse(),
121                    GeneralOperand::parse(),
122                    comma_p(),
123                    GeneralOperand::parse(),
124                    optional(Asel::parse()),
125                    comma_p(),
126                    GeneralOperand::parse(),
127                    optional(Bsel::parse()),
128                    semicolon_p()
129                ),
130                |(_, atype, btype, cmp, d, _, a, asel, _, b, bsel, _), span| {
131                    ok!(VsetAtypeBtypeCmp {
132                        atype = atype,
133                        btype = btype,
134                        cmp = cmp,
135                        d = d,
136                        a = a,
137                        asel = asel,
138                        b = b,
139                        bsel = bsel,
140
141                    })
142                },
143            )
144        }
145    }
146
147    impl PtxParser for VsetAtypeBtypeCmpOp2 {
148        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
149            try_map(
150                seq_n!(
151                    string_p("vset"),
152                    Atype::parse(),
153                    Btype::parse(),
154                    Cmp::parse(),
155                    Op2::parse(),
156                    GeneralOperand::parse(),
157                    comma_p(),
158                    GeneralOperand::parse(),
159                    optional(Asel::parse()),
160                    comma_p(),
161                    GeneralOperand::parse(),
162                    optional(Bsel::parse()),
163                    comma_p(),
164                    GeneralOperand::parse(),
165                    semicolon_p()
166                ),
167                |(_, atype, btype, cmp, op2, d, _, a, asel, _, b, bsel, _, c, _), span| {
168                    ok!(VsetAtypeBtypeCmpOp2 {
169                        atype = atype,
170                        btype = btype,
171                        cmp = cmp,
172                        op2 = op2,
173                        d = d,
174                        a = a,
175                        asel = asel,
176                        b = b,
177                        bsel = bsel,
178                        c = c,
179
180                    })
181                },
182            )
183        }
184    }
185
186    impl PtxParser for VsetAtypeBtypeCmp1 {
187        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
188            try_map(
189                seq_n!(
190                    string_p("vset"),
191                    Atype::parse(),
192                    Btype::parse(),
193                    Cmp::parse(),
194                    GeneralOperand::parse(),
195                    Dsel::parse(),
196                    comma_p(),
197                    GeneralOperand::parse(),
198                    optional(Asel::parse()),
199                    comma_p(),
200                    GeneralOperand::parse(),
201                    optional(Bsel::parse()),
202                    comma_p(),
203                    GeneralOperand::parse(),
204                    semicolon_p()
205                ),
206                |(_, atype, btype, cmp, d, dsel, _, a, asel, _, b, bsel, _, c, _), span| {
207                    ok!(VsetAtypeBtypeCmp1 {
208                        atype = atype,
209                        btype = btype,
210                        cmp = cmp,
211                        d = d,
212                        dsel = dsel,
213                        a = a,
214                        asel = asel,
215                        b = b,
216                        bsel = bsel,
217                        c = c,
218
219                    })
220                },
221            )
222        }
223    }
224}