1#![allow(unused)]
20
21use crate::parser::{
22 PtxParseError, PtxParser, PtxTokenStream, Span,
23 util::{
24 between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
25 pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
26 },
27};
28use crate::r#type::common::*;
29use crate::{alt, ok, seq_n};
30
31pub mod section_0 {
32 use super::*;
33 use crate::r#type::instruction::vop4::section_0::*;
34
35 impl PtxParser for Asel {
40 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
41 alt!(map(
42 |stream| {
43 stream.try_with_span(|stream| {
44 stream.with_partial_token_mode(|stream| {
45 stream.expect_string(".b")?;
46 let part0 = match stream
47 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
48 {
49 0 => N::_0,
50 1 => N::_1,
51 2 => N::_2,
52 3 => N::_3,
53 4 => N::_4,
54 5 => N::_5,
55 6 => N::_6,
56 7 => N::_7,
57 _ => unreachable!(),
58 };
59 let part1 = match stream
60 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
61 {
62 0 => N::_0,
63 1 => N::_1,
64 2 => N::_2,
65 3 => N::_3,
66 4 => N::_4,
67 5 => N::_5,
68 6 => N::_6,
69 7 => N::_7,
70 _ => unreachable!(),
71 };
72 let part2 = match stream
73 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
74 {
75 0 => N::_0,
76 1 => N::_1,
77 2 => N::_2,
78 3 => N::_3,
79 4 => N::_4,
80 5 => N::_5,
81 6 => N::_6,
82 7 => N::_7,
83 _ => unreachable!(),
84 };
85 let part3 = match stream
86 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
87 {
88 0 => N::_0,
89 1 => N::_1,
90 2 => N::_2,
91 3 => N::_3,
92 4 => N::_4,
93 5 => N::_5,
94 6 => N::_6,
95 7 => N::_7,
96 _ => unreachable!(),
97 };
98 Ok(((), part0, part1, part2, part3))
99 })
100 })
101 },
102 |(b, n, n1, n2, n3), _span| Asel::BNNNN(b, n, n1, n2, n3)
103 ))
104 }
105 }
106
107 impl PtxParser for Atype {
108 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
109 alt!(
110 map(string_p(".u32"), |_, _span| Atype::U32),
111 map(string_p(".s32"), |_, _span| Atype::S32)
112 )
113 }
114 }
115
116 impl PtxParser for Bsel {
117 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
118 alt!(map(
119 |stream| {
120 stream.try_with_span(|stream| {
121 stream.with_partial_token_mode(|stream| {
122 stream.expect_string(".b")?;
123 let part0 = match stream
124 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
125 {
126 0 => N::_0,
127 1 => N::_1,
128 2 => N::_2,
129 3 => N::_3,
130 4 => N::_4,
131 5 => N::_5,
132 6 => N::_6,
133 7 => N::_7,
134 _ => unreachable!(),
135 };
136 let part1 = match stream
137 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
138 {
139 0 => N::_0,
140 1 => N::_1,
141 2 => N::_2,
142 3 => N::_3,
143 4 => N::_4,
144 5 => N::_5,
145 6 => N::_6,
146 7 => N::_7,
147 _ => unreachable!(),
148 };
149 let part2 = match stream
150 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
151 {
152 0 => N::_0,
153 1 => N::_1,
154 2 => N::_2,
155 3 => N::_3,
156 4 => N::_4,
157 5 => N::_5,
158 6 => N::_6,
159 7 => N::_7,
160 _ => unreachable!(),
161 };
162 let part3 = match stream
163 .expect_strings(&["0", "1", "2", "3", "4", "5", "6", "7"])?
164 {
165 0 => N::_0,
166 1 => N::_1,
167 2 => N::_2,
168 3 => N::_3,
169 4 => N::_4,
170 5 => N::_5,
171 6 => N::_6,
172 7 => N::_7,
173 _ => unreachable!(),
174 };
175 Ok(((), part0, part1, part2, part3))
176 })
177 })
178 },
179 |(b, n, n1, n2, n3), _span| Bsel::BNNNN(b, n, n1, n2, n3)
180 ))
181 }
182 }
183
184 impl PtxParser for Btype {
185 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
186 alt!(
187 map(string_p(".u32"), |_, _span| Btype::U32),
188 map(string_p(".s32"), |_, _span| Btype::S32)
189 )
190 }
191 }
192
193 impl PtxParser for Dtype {
194 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
195 alt!(
196 map(string_p(".u32"), |_, _span| Dtype::U32),
197 map(string_p(".s32"), |_, _span| Dtype::S32)
198 )
199 }
200 }
201
202 impl PtxParser for Mask {
203 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
204 alt!(
205 map(string_p(".b3210"), |_, _span| Mask::B3210),
206 map(string_p(".b210"), |_, _span| Mask::B210),
207 map(string_p(".b310"), |_, _span| Mask::B310),
208 map(string_p(".b320"), |_, _span| Mask::B320),
209 map(string_p(".b321"), |_, _span| Mask::B321),
210 map(string_p(".b10"), |_, _span| Mask::B10),
211 map(string_p(".b20"), |_, _span| Mask::B20),
212 map(string_p(".b21"), |_, _span| Mask::B21),
213 map(string_p(".b30"), |_, _span| Mask::B30),
214 map(string_p(".b31"), |_, _span| Mask::B31),
215 map(string_p(".b32"), |_, _span| Mask::B32),
216 map(string_p(".b0"), |_, _span| Mask::B0),
217 map(string_p(".b1"), |_, _span| Mask::B1),
218 map(string_p(".b2"), |_, _span| Mask::B2),
219 map(string_p(".b3"), |_, _span| Mask::B3)
220 )
221 }
222 }
223
224 impl PtxParser for Vadd4DtypeAtypeBtypeSat {
225 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
226 try_map(
227 seq_n!(
228 string_p("vadd4"),
229 Dtype::parse(),
230 Atype::parse(),
231 Btype::parse(),
232 map(optional(string_p(".sat")), |value, _| value.is_some()),
233 GeneralOperand::parse(),
234 optional(Mask::parse()),
235 comma_p(),
236 GeneralOperand::parse(),
237 optional(Asel::parse()),
238 comma_p(),
239 GeneralOperand::parse(),
240 optional(Bsel::parse()),
241 comma_p(),
242 GeneralOperand::parse(),
243 semicolon_p()
244 ),
245 |(_, dtype, atype, btype, sat, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
246 ok!(Vadd4DtypeAtypeBtypeSat {
247 dtype = dtype,
248 atype = atype,
249 btype = btype,
250 sat = sat,
251 d = d,
252 mask = mask,
253 a = a,
254 asel = asel,
255 b = b,
256 bsel = bsel,
257 c = c,
258
259 })
260 },
261 )
262 }
263 }
264
265 impl PtxParser for Vsub4DtypeAtypeBtypeSat {
266 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
267 try_map(
268 seq_n!(
269 string_p("vsub4"),
270 Dtype::parse(),
271 Atype::parse(),
272 Btype::parse(),
273 map(optional(string_p(".sat")), |value, _| value.is_some()),
274 GeneralOperand::parse(),
275 optional(Mask::parse()),
276 comma_p(),
277 GeneralOperand::parse(),
278 optional(Asel::parse()),
279 comma_p(),
280 GeneralOperand::parse(),
281 optional(Bsel::parse()),
282 comma_p(),
283 GeneralOperand::parse(),
284 semicolon_p()
285 ),
286 |(_, dtype, atype, btype, sat, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
287 ok!(Vsub4DtypeAtypeBtypeSat {
288 dtype = dtype,
289 atype = atype,
290 btype = btype,
291 sat = sat,
292 d = d,
293 mask = mask,
294 a = a,
295 asel = asel,
296 b = b,
297 bsel = bsel,
298 c = c,
299
300 })
301 },
302 )
303 }
304 }
305
306 impl PtxParser for Vavrg4DtypeAtypeBtypeSat {
307 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
308 try_map(
309 seq_n!(
310 string_p("vavrg4"),
311 Dtype::parse(),
312 Atype::parse(),
313 Btype::parse(),
314 map(optional(string_p(".sat")), |value, _| value.is_some()),
315 GeneralOperand::parse(),
316 optional(Mask::parse()),
317 comma_p(),
318 GeneralOperand::parse(),
319 optional(Asel::parse()),
320 comma_p(),
321 GeneralOperand::parse(),
322 optional(Bsel::parse()),
323 comma_p(),
324 GeneralOperand::parse(),
325 semicolon_p()
326 ),
327 |(_, dtype, atype, btype, sat, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
328 ok!(Vavrg4DtypeAtypeBtypeSat {
329 dtype = dtype,
330 atype = atype,
331 btype = btype,
332 sat = sat,
333 d = d,
334 mask = mask,
335 a = a,
336 asel = asel,
337 b = b,
338 bsel = bsel,
339 c = c,
340
341 })
342 },
343 )
344 }
345 }
346
347 impl PtxParser for Vabsdiff4DtypeAtypeBtypeSat {
348 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
349 try_map(
350 seq_n!(
351 string_p("vabsdiff4"),
352 Dtype::parse(),
353 Atype::parse(),
354 Btype::parse(),
355 map(optional(string_p(".sat")), |value, _| value.is_some()),
356 GeneralOperand::parse(),
357 optional(Mask::parse()),
358 comma_p(),
359 GeneralOperand::parse(),
360 optional(Asel::parse()),
361 comma_p(),
362 GeneralOperand::parse(),
363 optional(Bsel::parse()),
364 comma_p(),
365 GeneralOperand::parse(),
366 semicolon_p()
367 ),
368 |(_, dtype, atype, btype, sat, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
369 ok!(Vabsdiff4DtypeAtypeBtypeSat {
370 dtype = dtype,
371 atype = atype,
372 btype = btype,
373 sat = sat,
374 d = d,
375 mask = mask,
376 a = a,
377 asel = asel,
378 b = b,
379 bsel = bsel,
380 c = c,
381
382 })
383 },
384 )
385 }
386 }
387
388 impl PtxParser for Vmin4DtypeAtypeBtypeSat {
389 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
390 try_map(
391 seq_n!(
392 string_p("vmin4"),
393 Dtype::parse(),
394 Atype::parse(),
395 Btype::parse(),
396 map(optional(string_p(".sat")), |value, _| value.is_some()),
397 GeneralOperand::parse(),
398 optional(Mask::parse()),
399 comma_p(),
400 GeneralOperand::parse(),
401 optional(Asel::parse()),
402 comma_p(),
403 GeneralOperand::parse(),
404 optional(Bsel::parse()),
405 comma_p(),
406 GeneralOperand::parse(),
407 semicolon_p()
408 ),
409 |(_, dtype, atype, btype, sat, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
410 ok!(Vmin4DtypeAtypeBtypeSat {
411 dtype = dtype,
412 atype = atype,
413 btype = btype,
414 sat = sat,
415 d = d,
416 mask = mask,
417 a = a,
418 asel = asel,
419 b = b,
420 bsel = bsel,
421 c = c,
422
423 })
424 },
425 )
426 }
427 }
428
429 impl PtxParser for Vmax4DtypeAtypeBtypeSat {
430 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
431 try_map(
432 seq_n!(
433 string_p("vmax4"),
434 Dtype::parse(),
435 Atype::parse(),
436 Btype::parse(),
437 map(optional(string_p(".sat")), |value, _| value.is_some()),
438 GeneralOperand::parse(),
439 optional(Mask::parse()),
440 comma_p(),
441 GeneralOperand::parse(),
442 optional(Asel::parse()),
443 comma_p(),
444 GeneralOperand::parse(),
445 optional(Bsel::parse()),
446 comma_p(),
447 GeneralOperand::parse(),
448 semicolon_p()
449 ),
450 |(_, dtype, atype, btype, sat, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
451 ok!(Vmax4DtypeAtypeBtypeSat {
452 dtype = dtype,
453 atype = atype,
454 btype = btype,
455 sat = sat,
456 d = d,
457 mask = mask,
458 a = a,
459 asel = asel,
460 b = b,
461 bsel = bsel,
462 c = c,
463
464 })
465 },
466 )
467 }
468 }
469
470 impl PtxParser for Vadd4DtypeAtypeBtypeAdd {
471 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
472 try_map(
473 seq_n!(
474 string_p("vadd4"),
475 Dtype::parse(),
476 Atype::parse(),
477 Btype::parse(),
478 string_p(".add"),
479 GeneralOperand::parse(),
480 optional(Mask::parse()),
481 comma_p(),
482 GeneralOperand::parse(),
483 optional(Asel::parse()),
484 comma_p(),
485 GeneralOperand::parse(),
486 optional(Bsel::parse()),
487 comma_p(),
488 GeneralOperand::parse(),
489 semicolon_p()
490 ),
491 |(_, dtype, atype, btype, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
492 ok!(Vadd4DtypeAtypeBtypeAdd {
493 dtype = dtype,
494 atype = atype,
495 btype = btype,
496 add = add,
497 d = d,
498 mask = mask,
499 a = a,
500 asel = asel,
501 b = b,
502 bsel = bsel,
503 c = c,
504
505 })
506 },
507 )
508 }
509 }
510
511 impl PtxParser for Vsub4DtypeAtypeBtypeAdd {
512 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
513 try_map(
514 seq_n!(
515 string_p("vsub4"),
516 Dtype::parse(),
517 Atype::parse(),
518 Btype::parse(),
519 string_p(".add"),
520 GeneralOperand::parse(),
521 optional(Mask::parse()),
522 comma_p(),
523 GeneralOperand::parse(),
524 optional(Asel::parse()),
525 comma_p(),
526 GeneralOperand::parse(),
527 optional(Bsel::parse()),
528 comma_p(),
529 GeneralOperand::parse(),
530 semicolon_p()
531 ),
532 |(_, dtype, atype, btype, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
533 ok!(Vsub4DtypeAtypeBtypeAdd {
534 dtype = dtype,
535 atype = atype,
536 btype = btype,
537 add = add,
538 d = d,
539 mask = mask,
540 a = a,
541 asel = asel,
542 b = b,
543 bsel = bsel,
544 c = c,
545
546 })
547 },
548 )
549 }
550 }
551
552 impl PtxParser for Vavrg4DtypeAtypeBtypeAdd {
553 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
554 try_map(
555 seq_n!(
556 string_p("vavrg4"),
557 Dtype::parse(),
558 Atype::parse(),
559 Btype::parse(),
560 string_p(".add"),
561 GeneralOperand::parse(),
562 optional(Mask::parse()),
563 comma_p(),
564 GeneralOperand::parse(),
565 optional(Asel::parse()),
566 comma_p(),
567 GeneralOperand::parse(),
568 optional(Bsel::parse()),
569 comma_p(),
570 GeneralOperand::parse(),
571 semicolon_p()
572 ),
573 |(_, dtype, atype, btype, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
574 ok!(Vavrg4DtypeAtypeBtypeAdd {
575 dtype = dtype,
576 atype = atype,
577 btype = btype,
578 add = add,
579 d = d,
580 mask = mask,
581 a = a,
582 asel = asel,
583 b = b,
584 bsel = bsel,
585 c = c,
586
587 })
588 },
589 )
590 }
591 }
592
593 impl PtxParser for Vabsdiff4DtypeAtypeBtypeAdd {
594 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
595 try_map(
596 seq_n!(
597 string_p("vabsdiff4"),
598 Dtype::parse(),
599 Atype::parse(),
600 Btype::parse(),
601 string_p(".add"),
602 GeneralOperand::parse(),
603 optional(Mask::parse()),
604 comma_p(),
605 GeneralOperand::parse(),
606 optional(Asel::parse()),
607 comma_p(),
608 GeneralOperand::parse(),
609 optional(Bsel::parse()),
610 comma_p(),
611 GeneralOperand::parse(),
612 semicolon_p()
613 ),
614 |(_, dtype, atype, btype, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
615 ok!(Vabsdiff4DtypeAtypeBtypeAdd {
616 dtype = dtype,
617 atype = atype,
618 btype = btype,
619 add = add,
620 d = d,
621 mask = mask,
622 a = a,
623 asel = asel,
624 b = b,
625 bsel = bsel,
626 c = c,
627
628 })
629 },
630 )
631 }
632 }
633
634 impl PtxParser for Vmin4DtypeAtypeBtypeAdd {
635 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
636 try_map(
637 seq_n!(
638 string_p("vmin4"),
639 Dtype::parse(),
640 Atype::parse(),
641 Btype::parse(),
642 string_p(".add"),
643 GeneralOperand::parse(),
644 optional(Mask::parse()),
645 comma_p(),
646 GeneralOperand::parse(),
647 optional(Asel::parse()),
648 comma_p(),
649 GeneralOperand::parse(),
650 optional(Bsel::parse()),
651 comma_p(),
652 GeneralOperand::parse(),
653 semicolon_p()
654 ),
655 |(_, dtype, atype, btype, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
656 ok!(Vmin4DtypeAtypeBtypeAdd {
657 dtype = dtype,
658 atype = atype,
659 btype = btype,
660 add = add,
661 d = d,
662 mask = mask,
663 a = a,
664 asel = asel,
665 b = b,
666 bsel = bsel,
667 c = c,
668
669 })
670 },
671 )
672 }
673 }
674
675 impl PtxParser for Vmax4DtypeAtypeBtypeAdd {
676 fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
677 try_map(
678 seq_n!(
679 string_p("vmax4"),
680 Dtype::parse(),
681 Atype::parse(),
682 Btype::parse(),
683 string_p(".add"),
684 GeneralOperand::parse(),
685 optional(Mask::parse()),
686 comma_p(),
687 GeneralOperand::parse(),
688 optional(Asel::parse()),
689 comma_p(),
690 GeneralOperand::parse(),
691 optional(Bsel::parse()),
692 comma_p(),
693 GeneralOperand::parse(),
694 semicolon_p()
695 ),
696 |(_, dtype, atype, btype, add, d, mask, _, a, asel, _, b, bsel, _, c, _), span| {
697 ok!(Vmax4DtypeAtypeBtypeAdd {
698 dtype = dtype,
699 atype = atype,
700 btype = btype,
701 add = add,
702 d = d,
703 mask = mask,
704 a = a,
705 asel = asel,
706 b = b,
707 bsel = bsel,
708 c = c,
709
710 })
711 },
712 )
713 }
714 }
715}