1#![allow(unused)]
12
13use crate::parser::{
14 PtxParseError, PtxParser, PtxTokenStream, Span,
15 util::{
16 between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
17 pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
18 },
19};
20use crate::r#type::common::*;
21use crate::{alt, ok, seq_n};
22
23pub mod section_0 {
24 use super::*;
25 use crate::r#type::instruction::vmad::section_0::*;
26
27 impl PtxParser for Asel {
32 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
33 alt!(
34 map(string_p(".b0"), |_, _span| Asel::B0),
35 map(string_p(".b1"), |_, _span| Asel::B1),
36 map(string_p(".b2"), |_, _span| Asel::B2),
37 map(string_p(".b3"), |_, _span| Asel::B3),
38 map(string_p(".h0"), |_, _span| Asel::H0),
39 map(string_p(".h1"), |_, _span| Asel::H1)
40 )
41 }
42 }
43
44 impl PtxParser for Atype {
45 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
46 alt!(
47 map(string_p(".u32"), |_, _span| Atype::U32),
48 map(string_p(".s32"), |_, _span| Atype::S32)
49 )
50 }
51 }
52
53 impl PtxParser for Bsel {
54 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
55 alt!(
56 map(string_p(".b0"), |_, _span| Bsel::B0),
57 map(string_p(".b1"), |_, _span| Bsel::B1),
58 map(string_p(".b2"), |_, _span| Bsel::B2),
59 map(string_p(".b3"), |_, _span| Bsel::B3),
60 map(string_p(".h0"), |_, _span| Bsel::H0),
61 map(string_p(".h1"), |_, _span| Bsel::H1)
62 )
63 }
64 }
65
66 impl PtxParser for Btype {
67 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
68 alt!(
69 map(string_p(".u32"), |_, _span| Btype::U32),
70 map(string_p(".s32"), |_, _span| Btype::S32)
71 )
72 }
73 }
74
75 impl PtxParser for Dtype {
76 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
77 alt!(
78 map(string_p(".u32"), |_, _span| Dtype::U32),
79 map(string_p(".s32"), |_, _span| Dtype::S32)
80 )
81 }
82 }
83
84 impl PtxParser for Scale {
85 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
86 alt!(
87 map(string_p(".shr15"), |_, _span| Scale::Shr15),
88 map(string_p(".shr7"), |_, _span| Scale::Shr7)
89 )
90 }
91 }
92
93 impl PtxParser for VmadDtypeAtypeBtypeSatScale {
94 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
95 try_map(
96 seq_n!(
97 string_p("vmad"),
98 Dtype::parse(),
99 Atype::parse(),
100 Btype::parse(),
101 map(optional(string_p(".sat")), |value, _| value.is_some()),
102 optional(Scale::parse()),
103 GeneralOperand::parse(),
104 comma_p(),
105 map(optional(minus_p()), |value, _| value.is_some()),
106 GeneralOperand::parse(),
107 optional(Asel::parse()),
108 comma_p(),
109 map(optional(minus_p()), |value, _| value.is_some()),
110 GeneralOperand::parse(),
111 optional(Bsel::parse()),
112 comma_p(),
113 map(optional(minus_p()), |value, _| value.is_some()),
114 GeneralOperand::parse(),
115 semicolon_p()
116 ),
117 |(
118 _,
119 dtype,
120 atype,
121 btype,
122 sat,
123 scale,
124 d,
125 _,
126 a_op,
127 a,
128 asel,
129 _,
130 b_op,
131 b,
132 bsel,
133 _,
134 c_op,
135 c,
136 _,
137 ),
138 span| {
139 ok!(VmadDtypeAtypeBtypeSatScale {
140 dtype = dtype,
141 atype = atype,
142 btype = btype,
143 sat = sat,
144 scale = scale,
145 d = d,
146 a_op = a_op,
147 a = a,
148 asel = asel,
149 b_op = b_op,
150 b = b,
151 bsel = bsel,
152 c_op = c_op,
153 c = c,
154
155 })
156 },
157 )
158 }
159 }
160
161 impl PtxParser for VmadDtypeAtypeBtypePoSatScale {
162 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
163 try_map(
164 seq_n!(
165 string_p("vmad"),
166 Dtype::parse(),
167 Atype::parse(),
168 Btype::parse(),
169 string_p(".po"),
170 map(optional(string_p(".sat")), |value, _| value.is_some()),
171 optional(Scale::parse()),
172 GeneralOperand::parse(),
173 comma_p(),
174 GeneralOperand::parse(),
175 optional(Asel::parse()),
176 comma_p(),
177 GeneralOperand::parse(),
178 optional(Bsel::parse()),
179 comma_p(),
180 GeneralOperand::parse(),
181 semicolon_p()
182 ),
183 |(_, dtype, atype, btype, po, sat, scale, d, _, a, asel, _, b, bsel, _, c, _),
184 span| {
185 ok!(VmadDtypeAtypeBtypePoSatScale {
186 dtype = dtype,
187 atype = atype,
188 btype = btype,
189 po = po,
190 sat = sat,
191 scale = scale,
192 d = d,
193 a = a,
194 asel = asel,
195 b = b,
196 bsel = bsel,
197 c = c,
198
199 })
200 },
201 )
202 }
203 }
204}