ptx_parser/parser/instruction/
shf.rs

1//! Original PTX specification:
2//!
3//! shf.l.mode.b32  d, a, b, c;  // left shift
4//! shf.r.mode.b32  d, a, b, c;  // right shift
5//! .mode = { .clamp, .wrap };
6
7#![allow(unused)]
8
9use crate::parser::{
10    PtxParseError, PtxParser, PtxTokenStream, Span,
11    util::{
12        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
13        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
14    },
15};
16use crate::r#type::common::*;
17use crate::{alt, ok, seq_n};
18
19pub mod section_0 {
20    use super::*;
21    use crate::r#type::instruction::shf::section_0::*;
22
23    // ============================================================================
24    // Generated enum parsers
25    // ============================================================================
26
27    impl PtxParser for Mode {
28        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
29            alt!(
30                map(string_p(".clamp"), |_, _span| Mode::Clamp),
31                map(string_p(".wrap"), |_, _span| Mode::Wrap)
32            )
33        }
34    }
35
36    impl PtxParser for ShfLModeB32 {
37        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
38            try_map(
39                seq_n!(
40                    string_p("shf"),
41                    string_p(".l"),
42                    Mode::parse(),
43                    string_p(".b32"),
44                    GeneralOperand::parse(),
45                    comma_p(),
46                    GeneralOperand::parse(),
47                    comma_p(),
48                    GeneralOperand::parse(),
49                    comma_p(),
50                    GeneralOperand::parse(),
51                    semicolon_p()
52                ),
53                |(_, l, mode, b32, d, _, a, _, b, _, c, _), span| {
54                    ok!(ShfLModeB32 {
55                        l = l,
56                        mode = mode,
57                        b32 = b32,
58                        d = d,
59                        a = a,
60                        b = b,
61                        c = c,
62
63                    })
64                },
65            )
66        }
67    }
68
69    impl PtxParser for ShfRModeB32 {
70        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
71            try_map(
72                seq_n!(
73                    string_p("shf"),
74                    string_p(".r"),
75                    Mode::parse(),
76                    string_p(".b32"),
77                    GeneralOperand::parse(),
78                    comma_p(),
79                    GeneralOperand::parse(),
80                    comma_p(),
81                    GeneralOperand::parse(),
82                    comma_p(),
83                    GeneralOperand::parse(),
84                    semicolon_p()
85                ),
86                |(_, r, mode, b32, d, _, a, _, b, _, c, _), span| {
87                    ok!(ShfRModeB32 {
88                        r = r,
89                        mode = mode,
90                        b32 = b32,
91                        d = d,
92                        a = a,
93                        b = b,
94                        c = c,
95
96                    })
97                },
98            )
99        }
100    }
101}