Skip to main content

ptx_parser/parser/instruction/
shfl.rs

1//! Original PTX specification:
2//!
3//! shfl.mode.b32  d{|p}, a, b, c;
4//! .mode = { .up, .down, .bfly, .idx };
5
6#![allow(unused)]
7
8use crate::parser::{
9    PtxParseError, PtxParser, PtxTokenStream, Span,
10    util::{
11        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
12        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
13    },
14};
15use crate::r#type::common::*;
16use crate::{alt, ok, seq_n};
17
18pub mod section_0 {
19    use super::*;
20    use crate::r#type::instruction::shfl::section_0::*;
21
22    // ============================================================================
23    // Generated enum parsers
24    // ============================================================================
25
26    impl PtxParser for Mode {
27        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
28            alt!(
29                map(string_p(".down"), |_, _span| Mode::Down),
30                map(string_p(".bfly"), |_, _span| Mode::Bfly),
31                map(string_p(".idx"), |_, _span| Mode::Idx),
32                map(string_p(".up"), |_, _span| Mode::Up)
33            )
34        }
35    }
36
37    impl PtxParser for ShflModeB32 {
38        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
39            try_map(
40                seq_n!(
41                    string_p("shfl"),
42                    Mode::parse(),
43                    string_p(".b32"),
44                    GeneralOperand::parse(),
45                    map(
46                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
47                        |value, _| value.map(|(_, operand)| operand)
48                    ),
49                    comma_p(),
50                    GeneralOperand::parse(),
51                    comma_p(),
52                    GeneralOperand::parse(),
53                    comma_p(),
54                    GeneralOperand::parse(),
55                    semicolon_p()
56                ),
57                |(_, mode, b32, d, p, _, a, _, b, _, c, _), span| {
58                    ok!(ShflModeB32 {
59                        mode = mode,
60                        b32 = b32,
61                        d = d,
62                        p = p,
63                        a = a,
64                        b = b,
65                        c = c,
66
67                    })
68                },
69            )
70        }
71    }
72}