ptx_parser/parser/instruction/
mad.rs

1//! Original PTX specification:
2//!
3//! mad.mode.type  d, a, b, c;
4//! mad.hi.sat.s32 d, a, b, c;
5//! .mode = { .hi, .lo, .wide };
6//! .type = { .u16, .u32, .u64,
7//! .s16, .s32, .s64 };
8//!
9//! mad{.ftz}{.sat}.f32      d, a, b, c;    // .target sm_1x
10//! mad.rnd{.ftz}{.sat}.f32  d, a, b, c;    // .target sm_20
11//! mad.rnd.f64              d, a, b, c;    // .target sm_13 and higher
12//! .rnd = { .rn, .rz, .rm, .rp };
13
14#![allow(unused)]
15
16use crate::parser::{
17    PtxParseError, PtxParser, PtxTokenStream, Span,
18    util::{
19        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
20        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
21    },
22};
23use crate::r#type::common::*;
24use crate::{alt, ok, seq_n};
25
26pub mod section_0 {
27    use super::*;
28    use crate::r#type::instruction::mad::section_0::*;
29
30    // ============================================================================
31    // Generated enum parsers
32    // ============================================================================
33
34    impl PtxParser for Mode {
35        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
36            alt!(
37                map(string_p(".wide"), |_, _span| Mode::Wide),
38                map(string_p(".hi"), |_, _span| Mode::Hi),
39                map(string_p(".lo"), |_, _span| Mode::Lo)
40            )
41        }
42    }
43
44    impl PtxParser for Rnd {
45        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
46            alt!(
47                map(string_p(".rn"), |_, _span| Rnd::Rn),
48                map(string_p(".rz"), |_, _span| Rnd::Rz),
49                map(string_p(".rm"), |_, _span| Rnd::Rm),
50                map(string_p(".rp"), |_, _span| Rnd::Rp)
51            )
52        }
53    }
54
55    impl PtxParser for Type {
56        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
57            alt!(
58                map(string_p(".u16"), |_, _span| Type::U16),
59                map(string_p(".u32"), |_, _span| Type::U32),
60                map(string_p(".u64"), |_, _span| Type::U64),
61                map(string_p(".s16"), |_, _span| Type::S16),
62                map(string_p(".s32"), |_, _span| Type::S32),
63                map(string_p(".s64"), |_, _span| Type::S64)
64            )
65        }
66    }
67
68    impl PtxParser for MadModeType {
69        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
70            try_map(
71                seq_n!(
72                    string_p("mad"),
73                    Mode::parse(),
74                    Type::parse(),
75                    GeneralOperand::parse(),
76                    comma_p(),
77                    GeneralOperand::parse(),
78                    comma_p(),
79                    GeneralOperand::parse(),
80                    comma_p(),
81                    GeneralOperand::parse(),
82                    semicolon_p()
83                ),
84                |(_, mode, type_, d, _, a, _, b, _, c, _), span| {
85                    ok!(MadModeType {
86                        mode = mode,
87                        type_ = type_,
88                        d = d,
89                        a = a,
90                        b = b,
91                        c = c,
92
93                    })
94                },
95            )
96        }
97    }
98
99    impl PtxParser for MadHiSatS32 {
100        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
101            try_map(
102                seq_n!(
103                    string_p("mad"),
104                    string_p(".hi"),
105                    string_p(".sat"),
106                    string_p(".s32"),
107                    GeneralOperand::parse(),
108                    comma_p(),
109                    GeneralOperand::parse(),
110                    comma_p(),
111                    GeneralOperand::parse(),
112                    comma_p(),
113                    GeneralOperand::parse(),
114                    semicolon_p()
115                ),
116                |(_, hi, sat, s32, d, _, a, _, b, _, c, _), span| {
117                    ok!(MadHiSatS32 {
118                        hi = hi,
119                        sat = sat,
120                        s32 = s32,
121                        d = d,
122                        a = a,
123                        b = b,
124                        c = c,
125
126                    })
127                },
128            )
129        }
130    }
131
132    impl PtxParser for MadFtzSatF32 {
133        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
134            try_map(
135                seq_n!(
136                    string_p("mad"),
137                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
138                    map(optional(string_p(".sat")), |value, _| value.is_some()),
139                    string_p(".f32"),
140                    GeneralOperand::parse(),
141                    comma_p(),
142                    GeneralOperand::parse(),
143                    comma_p(),
144                    GeneralOperand::parse(),
145                    comma_p(),
146                    GeneralOperand::parse(),
147                    semicolon_p()
148                ),
149                |(_, ftz, sat, f32, d, _, a, _, b, _, c, _), span| {
150                    ok!(MadFtzSatF32 {
151                        ftz = ftz,
152                        sat = sat,
153                        f32 = f32,
154                        d = d,
155                        a = a,
156                        b = b,
157                        c = c,
158
159                    })
160                },
161            )
162        }
163    }
164
165    impl PtxParser for MadRndFtzSatF32 {
166        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
167            try_map(
168                seq_n!(
169                    string_p("mad"),
170                    Rnd::parse(),
171                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
172                    map(optional(string_p(".sat")), |value, _| value.is_some()),
173                    string_p(".f32"),
174                    GeneralOperand::parse(),
175                    comma_p(),
176                    GeneralOperand::parse(),
177                    comma_p(),
178                    GeneralOperand::parse(),
179                    comma_p(),
180                    GeneralOperand::parse(),
181                    semicolon_p()
182                ),
183                |(_, rnd, ftz, sat, f32, d, _, a, _, b, _, c, _), span| {
184                    ok!(MadRndFtzSatF32 {
185                        rnd = rnd,
186                        ftz = ftz,
187                        sat = sat,
188                        f32 = f32,
189                        d = d,
190                        a = a,
191                        b = b,
192                        c = c,
193
194                    })
195                },
196            )
197        }
198    }
199
200    impl PtxParser for MadRndF64 {
201        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
202            try_map(
203                seq_n!(
204                    string_p("mad"),
205                    Rnd::parse(),
206                    string_p(".f64"),
207                    GeneralOperand::parse(),
208                    comma_p(),
209                    GeneralOperand::parse(),
210                    comma_p(),
211                    GeneralOperand::parse(),
212                    comma_p(),
213                    GeneralOperand::parse(),
214                    semicolon_p()
215                ),
216                |(_, rnd, f64, d, _, a, _, b, _, c, _), span| {
217                    ok!(MadRndF64 {
218                        rnd = rnd,
219                        f64 = f64,
220                        d = d,
221                        a = a,
222                        b = b,
223                        c = c,
224
225                    })
226                },
227            )
228        }
229    }
230}