1#![allow(unused)]
36
37use crate::parser::{
38 PtxParseError, PtxParser, PtxTokenStream, Span,
39 util::{
40 between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
41 pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
42 },
43};
44use crate::r#type::common::*;
45use crate::{alt, ok, seq_n};
46
47pub mod section_0 {
48 use super::*;
49 use crate::r#type::instruction::multimem_ld_reduce::section_0::*;
50
51 impl PtxParser for Ldsem {
56 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
57 alt!(
58 map(string_p(".relaxed"), |_, _span| Ldsem::Relaxed),
59 map(string_p(".acquire"), |_, _span| Ldsem::Acquire)
60 )
61 }
62 }
63
64 impl PtxParser for Op {
65 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
66 alt!(
67 map(string_p(".min"), |_, _span| Op::Min),
68 map(string_p(".max"), |_, _span| Op::Max),
69 map(string_p(".add"), |_, _span| Op::Add),
70 map(string_p(".and"), |_, _span| Op::And),
71 map(string_p(".xor"), |_, _span| Op::Xor),
72 map(string_p(".or"), |_, _span| Op::Or)
73 )
74 }
75 }
76
77 impl PtxParser for Redsem {
78 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
79 alt!(
80 map(string_p(".relaxed"), |_, _span| Redsem::Relaxed),
81 map(string_p(".release"), |_, _span| Redsem::Release)
82 )
83 }
84 }
85
86 impl PtxParser for Scope {
87 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
88 alt!(
89 map(string_p(".cluster"), |_, _span| Scope::Cluster),
90 map(string_p(".cta"), |_, _span| Scope::Cta),
91 map(string_p(".gpu"), |_, _span| Scope::Gpu),
92 map(string_p(".sys"), |_, _span| Scope::Sys)
93 )
94 }
95 }
96
97 impl PtxParser for Ss {
98 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
99 alt!(map(string_p(".global"), |_, _span| Ss::Global))
100 }
101 }
102
103 impl PtxParser for Stsem {
104 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
105 alt!(
106 map(string_p(".relaxed"), |_, _span| Stsem::Relaxed),
107 map(string_p(".release"), |_, _span| Stsem::Release)
108 )
109 }
110 }
111
112 impl PtxParser for Type {
113 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
114 alt!(
115 map(string_p(".b32"), |_, _span| Type::B32),
116 map(string_p(".b64"), |_, _span| Type::B64),
117 map(string_p(".u32"), |_, _span| Type::U32),
118 map(string_p(".u64"), |_, _span| Type::U64),
119 map(string_p(".s32"), |_, _span| Type::S32),
120 map(string_p(".s64"), |_, _span| Type::S64)
121 )
122 }
123 }
124
125 impl PtxParser for MultimemLdReduceLdsemScopeSsOpType {
126 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
127 try_map(
128 seq_n!(
129 string_p("multimem"),
130 string_p(".ld_reduce"),
131 optional(Ldsem::parse()),
132 optional(Scope::parse()),
133 optional(Ss::parse()),
134 Op::parse(),
135 Type::parse(),
136 GeneralOperand::parse(),
137 comma_p(),
138 AddressOperand::parse(),
139 semicolon_p()
140 ),
141 |(_, ld_reduce, ldsem, scope, ss, op, type_, d, _, a, _), span| {
142 ok!(MultimemLdReduceLdsemScopeSsOpType {
143 ld_reduce = ld_reduce,
144 ldsem = ldsem,
145 scope = scope,
146 ss = ss,
147 op = op,
148 type_ = type_,
149 d = d,
150 a = a,
151
152 })
153 },
154 )
155 }
156 }
157
158 impl PtxParser for MultimemLdReduceWeakSsOpType {
159 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
160 try_map(
161 seq_n!(
162 string_p("multimem"),
163 string_p(".ld_reduce"),
164 string_p(".weak"),
165 optional(Ss::parse()),
166 Op::parse(),
167 Type::parse(),
168 GeneralOperand::parse(),
169 comma_p(),
170 AddressOperand::parse(),
171 semicolon_p()
172 ),
173 |(_, ld_reduce, weak, ss, op, type_, d, _, a, _), span| {
174 ok!(MultimemLdReduceWeakSsOpType {
175 ld_reduce = ld_reduce,
176 weak = weak,
177 ss = ss,
178 op = op,
179 type_ = type_,
180 d = d,
181 a = a,
182
183 })
184 },
185 )
186 }
187 }
188
189 impl PtxParser for MultimemStStsemScopeSsType {
190 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
191 try_map(
192 seq_n!(
193 string_p("multimem"),
194 string_p(".st"),
195 optional(Stsem::parse()),
196 optional(Scope::parse()),
197 optional(Ss::parse()),
198 Type::parse(),
199 AddressOperand::parse(),
200 comma_p(),
201 GeneralOperand::parse(),
202 semicolon_p()
203 ),
204 |(_, st, stsem, scope, ss, type_, a, _, b, _), span| {
205 ok!(MultimemStStsemScopeSsType {
206 st = st,
207 stsem = stsem,
208 scope = scope,
209 ss = ss,
210 type_ = type_,
211 a = a,
212 b = b,
213
214 })
215 },
216 )
217 }
218 }
219
220 impl PtxParser for MultimemStWeakSsType {
221 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
222 try_map(
223 seq_n!(
224 string_p("multimem"),
225 string_p(".st"),
226 string_p(".weak"),
227 optional(Ss::parse()),
228 Type::parse(),
229 AddressOperand::parse(),
230 comma_p(),
231 GeneralOperand::parse(),
232 semicolon_p()
233 ),
234 |(_, st, weak, ss, type_, a, _, b, _), span| {
235 ok!(MultimemStWeakSsType {
236 st = st,
237 weak = weak,
238 ss = ss,
239 type_ = type_,
240 a = a,
241 b = b,
242
243 })
244 },
245 )
246 }
247 }
248
249 impl PtxParser for MultimemRedRedsemScopeSsOpType {
250 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
251 try_map(
252 seq_n!(
253 string_p("multimem"),
254 string_p(".red"),
255 optional(Redsem::parse()),
256 optional(Scope::parse()),
257 optional(Ss::parse()),
258 Op::parse(),
259 Type::parse(),
260 AddressOperand::parse(),
261 comma_p(),
262 GeneralOperand::parse(),
263 semicolon_p()
264 ),
265 |(_, red, redsem, scope, ss, op, type_, a, _, b, _), span| {
266 ok!(MultimemRedRedsemScopeSsOpType {
267 red = red,
268 redsem = redsem,
269 scope = scope,
270 ss = ss,
271 op = op,
272 type_ = type_,
273 a = a,
274 b = b,
275
276 })
277 },
278 )
279 }
280 }
281}
282
283pub mod section_1 {
284 use super::*;
285 use crate::r#type::instruction::multimem_ld_reduce::section_1::*;
286
287 impl PtxParser for AccPrec {
292 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
293 alt!(
294 map(string_p(".acc::f32"), |_, _span| AccPrec::AccF32),
295 map(string_p(".acc::f16"), |_, _span| AccPrec::AccF16)
296 )
297 }
298 }
299
300 impl PtxParser for Ldsem {
301 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
302 alt!(
303 map(string_p(".relaxed"), |_, _span| Ldsem::Relaxed),
304 map(string_p(".acquire"), |_, _span| Ldsem::Acquire)
305 )
306 }
307 }
308
309 impl PtxParser for Op {
310 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
311 alt!(
312 map(string_p(".min"), |_, _span| Op::Min),
313 map(string_p(".max"), |_, _span| Op::Max),
314 map(string_p(".add"), |_, _span| Op::Add)
315 )
316 }
317 }
318
319 impl PtxParser for Redop {
320 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
321 alt!(map(string_p(".add"), |_, _span| Redop::Add))
322 }
323 }
324
325 impl PtxParser for Redsem {
326 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
327 alt!(
328 map(string_p(".relaxed"), |_, _span| Redsem::Relaxed),
329 map(string_p(".release"), |_, _span| Redsem::Release)
330 )
331 }
332 }
333
334 impl PtxParser for Redtype {
335 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
336 alt!(
337 map(string_p(".bf16x2"), |_, _span| Redtype::Bf16x2),
338 map(string_p(".f16x2"), |_, _span| Redtype::F16x2),
339 map(string_p(".bf16"), |_, _span| Redtype::Bf16),
340 map(string_p(".f16"), |_, _span| Redtype::F16),
341 map(string_p(".f32"), |_, _span| Redtype::F32),
342 map(string_p(".f64"), |_, _span| Redtype::F64)
343 )
344 }
345 }
346
347 impl PtxParser for Scope {
348 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
349 alt!(
350 map(string_p(".cluster"), |_, _span| Scope::Cluster),
351 map(string_p(".cta"), |_, _span| Scope::Cta),
352 map(string_p(".gpu"), |_, _span| Scope::Gpu),
353 map(string_p(".sys"), |_, _span| Scope::Sys)
354 )
355 }
356 }
357
358 impl PtxParser for Ss {
359 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
360 alt!(map(string_p(".global"), |_, _span| Ss::Global))
361 }
362 }
363
364 impl PtxParser for Stsem {
365 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
366 alt!(
367 map(string_p(".relaxed"), |_, _span| Stsem::Relaxed),
368 map(string_p(".release"), |_, _span| Stsem::Release)
369 )
370 }
371 }
372
373 impl PtxParser for Type {
374 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
375 alt!(
376 map(string_p(".bf16x2"), |_, _span| Type::Bf16x2),
377 map(string_p(".e5m2x2"), |_, _span| Type::E5m2x2),
378 map(string_p(".e5m2x4"), |_, _span| Type::E5m2x4),
379 map(string_p(".e4m3x2"), |_, _span| Type::E4m3x2),
380 map(string_p(".e4m3x4"), |_, _span| Type::E4m3x4),
381 map(string_p(".f16x2"), |_, _span| Type::F16x2),
382 map(string_p(".bf16"), |_, _span| Type::Bf16),
383 map(string_p(".e5m2"), |_, _span| Type::E5m2),
384 map(string_p(".e4m3"), |_, _span| Type::E4m3),
385 map(string_p(".f16"), |_, _span| Type::F16),
386 map(string_p(".f32"), |_, _span| Type::F32),
387 map(string_p(".f64"), |_, _span| Type::F64)
388 )
389 }
390 }
391
392 impl PtxParser for Vec {
393 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
394 alt!(
395 map(string_p(".v2"), |_, _span| Vec::V2),
396 map(string_p(".v4"), |_, _span| Vec::V4),
397 map(string_p(".v8"), |_, _span| Vec::V8)
398 )
399 }
400 }
401
402 impl PtxParser for MultimemLdReduceLdsemScopeSsOpAccPrecVecType {
403 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
404 try_map(
405 seq_n!(
406 string_p("multimem"),
407 string_p(".ld_reduce"),
408 optional(Ldsem::parse()),
409 optional(Scope::parse()),
410 optional(Ss::parse()),
411 Op::parse(),
412 optional(AccPrec::parse()),
413 optional(Vec::parse()),
414 Type::parse(),
415 GeneralOperand::parse(),
416 comma_p(),
417 AddressOperand::parse(),
418 semicolon_p()
419 ),
420 |(_, ld_reduce, ldsem, scope, ss, op, acc_prec, vec, type_, d, _, a, _), span| {
421 ok!(MultimemLdReduceLdsemScopeSsOpAccPrecVecType {
422 ld_reduce = ld_reduce,
423 ldsem = ldsem,
424 scope = scope,
425 ss = ss,
426 op = op,
427 acc_prec = acc_prec,
428 vec = vec,
429 type_ = type_,
430 d = d,
431 a = a,
432
433 })
434 },
435 )
436 }
437 }
438
439 impl PtxParser for MultimemLdReduceWeakSsOpAccPrecVecType {
440 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
441 try_map(
442 seq_n!(
443 string_p("multimem"),
444 string_p(".ld_reduce"),
445 string_p(".weak"),
446 optional(Ss::parse()),
447 Op::parse(),
448 optional(AccPrec::parse()),
449 optional(Vec::parse()),
450 Type::parse(),
451 GeneralOperand::parse(),
452 comma_p(),
453 AddressOperand::parse(),
454 semicolon_p()
455 ),
456 |(_, ld_reduce, weak, ss, op, acc_prec, vec, type_, d, _, a, _), span| {
457 ok!(MultimemLdReduceWeakSsOpAccPrecVecType {
458 ld_reduce = ld_reduce,
459 weak = weak,
460 ss = ss,
461 op = op,
462 acc_prec = acc_prec,
463 vec = vec,
464 type_ = type_,
465 d = d,
466 a = a,
467
468 })
469 },
470 )
471 }
472 }
473
474 impl PtxParser for MultimemStStsemScopeSsVecType {
475 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
476 try_map(
477 seq_n!(
478 string_p("multimem"),
479 string_p(".st"),
480 optional(Stsem::parse()),
481 optional(Scope::parse()),
482 optional(Ss::parse()),
483 optional(Vec::parse()),
484 Type::parse(),
485 AddressOperand::parse(),
486 comma_p(),
487 GeneralOperand::parse(),
488 semicolon_p()
489 ),
490 |(_, st, stsem, scope, ss, vec, type_, a, _, b, _), span| {
491 ok!(MultimemStStsemScopeSsVecType {
492 st = st,
493 stsem = stsem,
494 scope = scope,
495 ss = ss,
496 vec = vec,
497 type_ = type_,
498 a = a,
499 b = b,
500
501 })
502 },
503 )
504 }
505 }
506
507 impl PtxParser for MultimemStWeakSsVecType {
508 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
509 try_map(
510 seq_n!(
511 string_p("multimem"),
512 string_p(".st"),
513 string_p(".weak"),
514 optional(Ss::parse()),
515 optional(Vec::parse()),
516 Type::parse(),
517 AddressOperand::parse(),
518 comma_p(),
519 GeneralOperand::parse(),
520 semicolon_p()
521 ),
522 |(_, st, weak, ss, vec, type_, a, _, b, _), span| {
523 ok!(MultimemStWeakSsVecType {
524 st = st,
525 weak = weak,
526 ss = ss,
527 vec = vec,
528 type_ = type_,
529 a = a,
530 b = b,
531
532 })
533 },
534 )
535 }
536 }
537
538 impl PtxParser for MultimemRedRedsemScopeSsRedopVecRedtype {
539 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
540 try_map(
541 seq_n!(
542 string_p("multimem"),
543 string_p(".red"),
544 optional(Redsem::parse()),
545 optional(Scope::parse()),
546 optional(Ss::parse()),
547 Redop::parse(),
548 optional(Vec::parse()),
549 Redtype::parse(),
550 AddressOperand::parse(),
551 comma_p(),
552 GeneralOperand::parse(),
553 semicolon_p()
554 ),
555 |(_, red, redsem, scope, ss, redop, vec, redtype, a, _, b, _), span| {
556 ok!(MultimemRedRedsemScopeSsRedopVecRedtype {
557 red = red,
558 redsem = redsem,
559 scope = scope,
560 ss = ss,
561 redop = redop,
562 vec = vec,
563 redtype = redtype,
564 a = a,
565 b = b,
566
567 })
568 },
569 )
570 }
571 }
572}