1#![allow(unused)]
15
16use crate::parser::{
17 PtxParseError, PtxParser, PtxTokenStream, Span,
18 util::{
19 between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
20 pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
21 },
22};
23use crate::r#type::common::*;
24use crate::{alt, ok, seq_n};
25
26pub mod section_0 {
27 use super::*;
28 use crate::r#type::instruction::vset2::section_0::*;
29
30 impl PtxParser for Asel {
35 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
36 alt!(
37 map(string_p(".h00"), |_, _span| Asel::H00),
38 map(string_p(".h01"), |_, _span| Asel::H01),
39 map(string_p(".h02"), |_, _span| Asel::H02),
40 map(string_p(".h03"), |_, _span| Asel::H03),
41 map(string_p(".h10"), |_, _span| Asel::H10),
42 map(string_p(".h11"), |_, _span| Asel::H11),
43 map(string_p(".h12"), |_, _span| Asel::H12),
44 map(string_p(".h13"), |_, _span| Asel::H13),
45 map(string_p(".h20"), |_, _span| Asel::H20),
46 map(string_p(".h21"), |_, _span| Asel::H21),
47 map(string_p(".h22"), |_, _span| Asel::H22),
48 map(string_p(".h23"), |_, _span| Asel::H23),
49 map(string_p(".h30"), |_, _span| Asel::H30),
50 map(string_p(".h31"), |_, _span| Asel::H31),
51 map(string_p(".h32"), |_, _span| Asel::H32),
52 map(string_p(".h33"), |_, _span| Asel::H33)
53 )
54 }
55 }
56
57 impl PtxParser for Atype {
58 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
59 alt!(
60 map(string_p(".u32"), |_, _span| Atype::U32),
61 map(string_p(".s32"), |_, _span| Atype::S32)
62 )
63 }
64 }
65
66 impl PtxParser for Bsel {
67 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
68 alt!(
69 map(string_p(".h00"), |_, _span| Bsel::H00),
70 map(string_p(".h01"), |_, _span| Bsel::H01),
71 map(string_p(".h02"), |_, _span| Bsel::H02),
72 map(string_p(".h03"), |_, _span| Bsel::H03),
73 map(string_p(".h10"), |_, _span| Bsel::H10),
74 map(string_p(".h11"), |_, _span| Bsel::H11),
75 map(string_p(".h12"), |_, _span| Bsel::H12),
76 map(string_p(".h13"), |_, _span| Bsel::H13),
77 map(string_p(".h20"), |_, _span| Bsel::H20),
78 map(string_p(".h21"), |_, _span| Bsel::H21),
79 map(string_p(".h22"), |_, _span| Bsel::H22),
80 map(string_p(".h23"), |_, _span| Bsel::H23),
81 map(string_p(".h30"), |_, _span| Bsel::H30),
82 map(string_p(".h31"), |_, _span| Bsel::H31),
83 map(string_p(".h32"), |_, _span| Bsel::H32),
84 map(string_p(".h33"), |_, _span| Bsel::H33)
85 )
86 }
87 }
88
89 impl PtxParser for Btype {
90 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
91 alt!(
92 map(string_p(".u32"), |_, _span| Btype::U32),
93 map(string_p(".s32"), |_, _span| Btype::S32)
94 )
95 }
96 }
97
98 impl PtxParser for Cmp {
99 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
100 alt!(
101 map(string_p(".eq"), |_, _span| Cmp::Eq),
102 map(string_p(".ne"), |_, _span| Cmp::Ne),
103 map(string_p(".lt"), |_, _span| Cmp::Lt),
104 map(string_p(".le"), |_, _span| Cmp::Le),
105 map(string_p(".gt"), |_, _span| Cmp::Gt),
106 map(string_p(".ge"), |_, _span| Cmp::Ge)
107 )
108 }
109 }
110
111 impl PtxParser for Mask {
112 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
113 alt!(
114 map(string_p(".h10"), |_, _span| Mask::H10),
115 map(string_p(".h0"), |_, _span| Mask::H0),
116 map(string_p(".h1"), |_, _span| Mask::H1)
117 )
118 }
119 }
120
121 impl PtxParser for Vset2AtypeBtypeCmp {
122 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
123 try_map(
124 seq_n!(
125 string_p("vset2"),
126 Atype::parse(),
127 Btype::parse(),
128 Cmp::parse(),
129 GeneralOperand::parse(),
130 optional(Mask::parse()),
131 comma_p(),
132 GeneralOperand::parse(),
133 optional(Asel::parse()),
134 comma_p(),
135 GeneralOperand::parse(),
136 optional(Bsel::parse()),
137 comma_p(),
138 GeneralOperand::parse(),
139 semicolon_p()
140 ),
141 |(_, atype, btype, cmp, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
142 ok!(Vset2AtypeBtypeCmp {
143 atype = atype,
144 btype = btype,
145 cmp = cmp,
146 d = d,
147 mask = mask,
148 a = a,
149 asel = asel,
150 b = b,
151 bsel = bsel,
152 c = c,
153
154 })
155 },
156 )
157 }
158 }
159
160 impl PtxParser for Vset2AtypeBtypeCmpAdd {
161 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
162 try_map(
163 seq_n!(
164 string_p("vset2"),
165 Atype::parse(),
166 Btype::parse(),
167 Cmp::parse(),
168 string_p(".add"),
169 GeneralOperand::parse(),
170 optional(Mask::parse()),
171 comma_p(),
172 GeneralOperand::parse(),
173 optional(Asel::parse()),
174 comma_p(),
175 GeneralOperand::parse(),
176 optional(Bsel::parse()),
177 comma_p(),
178 GeneralOperand::parse(),
179 semicolon_p()
180 ),
181 |(_, atype, btype, cmp, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
182 ok!(Vset2AtypeBtypeCmpAdd {
183 atype = atype,
184 btype = btype,
185 cmp = cmp,
186 add = add,
187 d = d,
188 mask = mask,
189 a = a,
190 asel = asel,
191 b = b,
192 bsel = bsel,
193 c = c,
194
195 })
196 },
197 )
198 }
199 }
200}