Skip to main content

ptx_parser/parser/instruction/
setp.rs

1//! Original PTX specification:
2//!
3//! setp.CmpOp{.ftz}.type         p{|q}, a, b;
4//! setp.CmpOp.BoolOp{.ftz}.type  p{|q}, a, b, {!}c;
5//! .CmpOp  = { .eq, .ne, .lt, .le, .gt, .ge, .lo, .ls, .hi, .hs, .equ, .neu, .ltu, .leu, .gtu, .geu, .num, .nan };
6//! .BoolOp = { .and, .or, .xor };
7//! .type   = { .b16, .b32, .b64, .u16, .u32, .u64, .s16, .s32, .s64, .f32, .f64 };
8//! --------------------------------------------------------------
9//! setp.CmpOp{.ftz}.f16           p, a, b;
10//! setp.CmpOp.BoolOp{.ftz}.f16    p, a, b, {!}c;
11//! setp.CmpOp{.ftz}.f16x2         p|q, a, b;
12//! setp.CmpOp.BoolOp{.ftz}.f16x2  p|q, a, b, {!}c;
13//! setp.CmpOp.bf16                p, a, b;
14//! setp.CmpOp.BoolOp.bf16         p, a, b, {!}c;
15//! setp.CmpOp.bf16x2              p|q, a, b;
16//! setp.CmpOp.BoolOp.bf16x2       p|q, a, b, {!}c;
17//! .CmpOp  = { .eq, .ne, .lt, .le, .gt, .ge, .equ, .neu, .ltu, .leu, .gtu, .geu, .num, .nan };
18//! .BoolOp = { .and, .or, .xor };
19
20#![allow(unused)]
21
22use crate::parser::{
23    PtxParseError, PtxParser, PtxTokenStream, Span,
24    util::{
25        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
26        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
27    },
28};
29use crate::r#type::common::*;
30use crate::{alt, ok, seq_n};
31
32pub mod section_0 {
33    use super::*;
34    use crate::r#type::instruction::setp::section_0::*;
35
36    // ============================================================================
37    // Generated enum parsers
38    // ============================================================================
39
40    impl PtxParser for Boolop {
41        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
42            alt!(
43                map(string_p(".and"), |_, _span| Boolop::And),
44                map(string_p(".xor"), |_, _span| Boolop::Xor),
45                map(string_p(".or"), |_, _span| Boolop::Or)
46            )
47        }
48    }
49
50    impl PtxParser for Cmpop {
51        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
52            alt!(
53                map(string_p(".equ"), |_, _span| Cmpop::Equ),
54                map(string_p(".neu"), |_, _span| Cmpop::Neu),
55                map(string_p(".ltu"), |_, _span| Cmpop::Ltu),
56                map(string_p(".leu"), |_, _span| Cmpop::Leu),
57                map(string_p(".gtu"), |_, _span| Cmpop::Gtu),
58                map(string_p(".geu"), |_, _span| Cmpop::Geu),
59                map(string_p(".num"), |_, _span| Cmpop::Num),
60                map(string_p(".nan"), |_, _span| Cmpop::Nan),
61                map(string_p(".eq"), |_, _span| Cmpop::Eq),
62                map(string_p(".ne"), |_, _span| Cmpop::Ne),
63                map(string_p(".lt"), |_, _span| Cmpop::Lt),
64                map(string_p(".le"), |_, _span| Cmpop::Le),
65                map(string_p(".gt"), |_, _span| Cmpop::Gt),
66                map(string_p(".ge"), |_, _span| Cmpop::Ge),
67                map(string_p(".lo"), |_, _span| Cmpop::Lo),
68                map(string_p(".ls"), |_, _span| Cmpop::Ls),
69                map(string_p(".hi"), |_, _span| Cmpop::Hi),
70                map(string_p(".hs"), |_, _span| Cmpop::Hs)
71            )
72        }
73    }
74
75    impl PtxParser for Type {
76        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
77            alt!(
78                map(string_p(".b16"), |_, _span| Type::B16),
79                map(string_p(".b32"), |_, _span| Type::B32),
80                map(string_p(".b64"), |_, _span| Type::B64),
81                map(string_p(".u16"), |_, _span| Type::U16),
82                map(string_p(".u32"), |_, _span| Type::U32),
83                map(string_p(".u64"), |_, _span| Type::U64),
84                map(string_p(".s16"), |_, _span| Type::S16),
85                map(string_p(".s32"), |_, _span| Type::S32),
86                map(string_p(".s64"), |_, _span| Type::S64),
87                map(string_p(".f32"), |_, _span| Type::F32),
88                map(string_p(".f64"), |_, _span| Type::F64)
89            )
90        }
91    }
92
93    impl PtxParser for SetpCmpopFtzType {
94        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
95            try_map(
96                seq_n!(
97                    string_p("setp"),
98                    Cmpop::parse(),
99                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
100                    Type::parse(),
101                    GeneralOperand::parse(),
102                    map(
103                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
104                        |value, _| value.map(|(_, operand)| operand)
105                    ),
106                    comma_p(),
107                    GeneralOperand::parse(),
108                    comma_p(),
109                    GeneralOperand::parse(),
110                    semicolon_p()
111                ),
112                |(_, cmpop, ftz, type_, p, q, _, a, _, b, _), span| {
113                    ok!(SetpCmpopFtzType {
114                        cmpop = cmpop,
115                        ftz = ftz,
116                        type_ = type_,
117                        p = p,
118                        q = q,
119                        a = a,
120                        b = b,
121
122                    })
123                },
124            )
125        }
126    }
127
128    impl PtxParser for SetpCmpopBoolopFtzType {
129        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
130            try_map(
131                seq_n!(
132                    string_p("setp"),
133                    Cmpop::parse(),
134                    Boolop::parse(),
135                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
136                    Type::parse(),
137                    GeneralOperand::parse(),
138                    map(
139                        optional(seq_n!(pipe_p(), GeneralOperand::parse())),
140                        |value, _| value.map(|(_, operand)| operand)
141                    ),
142                    comma_p(),
143                    GeneralOperand::parse(),
144                    comma_p(),
145                    GeneralOperand::parse(),
146                    comma_p(),
147                    map(optional(exclamation_p()), |value, _| value.is_some()),
148                    GeneralOperand::parse(),
149                    semicolon_p()
150                ),
151                |(_, cmpop, boolop, ftz, type_, p, q, _, a, _, b, _, c_op, c, _), span| {
152                    ok!(SetpCmpopBoolopFtzType {
153                        cmpop = cmpop,
154                        boolop = boolop,
155                        ftz = ftz,
156                        type_ = type_,
157                        p = p,
158                        q = q,
159                        a = a,
160                        b = b,
161                        c_op = c_op,
162                        c = c,
163
164                    })
165                },
166            )
167        }
168    }
169}
170
171pub mod section_1 {
172    use super::*;
173    use crate::r#type::instruction::setp::section_1::*;
174
175    // ============================================================================
176    // Generated enum parsers
177    // ============================================================================
178
179    impl PtxParser for Boolop {
180        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
181            alt!(
182                map(string_p(".and"), |_, _span| Boolop::And),
183                map(string_p(".xor"), |_, _span| Boolop::Xor),
184                map(string_p(".or"), |_, _span| Boolop::Or)
185            )
186        }
187    }
188
189    impl PtxParser for Cmpop {
190        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
191            alt!(
192                map(string_p(".equ"), |_, _span| Cmpop::Equ),
193                map(string_p(".neu"), |_, _span| Cmpop::Neu),
194                map(string_p(".ltu"), |_, _span| Cmpop::Ltu),
195                map(string_p(".leu"), |_, _span| Cmpop::Leu),
196                map(string_p(".gtu"), |_, _span| Cmpop::Gtu),
197                map(string_p(".geu"), |_, _span| Cmpop::Geu),
198                map(string_p(".num"), |_, _span| Cmpop::Num),
199                map(string_p(".nan"), |_, _span| Cmpop::Nan),
200                map(string_p(".eq"), |_, _span| Cmpop::Eq),
201                map(string_p(".ne"), |_, _span| Cmpop::Ne),
202                map(string_p(".lt"), |_, _span| Cmpop::Lt),
203                map(string_p(".le"), |_, _span| Cmpop::Le),
204                map(string_p(".gt"), |_, _span| Cmpop::Gt),
205                map(string_p(".ge"), |_, _span| Cmpop::Ge)
206            )
207        }
208    }
209
210    impl PtxParser for SetpCmpopFtzF16 {
211        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
212            try_map(
213                seq_n!(
214                    string_p("setp"),
215                    Cmpop::parse(),
216                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
217                    string_p(".f16"),
218                    GeneralOperand::parse(),
219                    comma_p(),
220                    GeneralOperand::parse(),
221                    comma_p(),
222                    GeneralOperand::parse(),
223                    semicolon_p()
224                ),
225                |(_, cmpop, ftz, f16, p, _, a, _, b, _), span| {
226                    ok!(SetpCmpopFtzF16 {
227                        cmpop = cmpop,
228                        ftz = ftz,
229                        f16 = f16,
230                        p = p,
231                        a = a,
232                        b = b,
233
234                    })
235                },
236            )
237        }
238    }
239
240    impl PtxParser for SetpCmpopBoolopFtzF16 {
241        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
242            try_map(
243                seq_n!(
244                    string_p("setp"),
245                    Cmpop::parse(),
246                    Boolop::parse(),
247                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
248                    string_p(".f16"),
249                    GeneralOperand::parse(),
250                    comma_p(),
251                    GeneralOperand::parse(),
252                    comma_p(),
253                    GeneralOperand::parse(),
254                    comma_p(),
255                    map(optional(exclamation_p()), |value, _| value.is_some()),
256                    GeneralOperand::parse(),
257                    semicolon_p()
258                ),
259                |(_, cmpop, boolop, ftz, f16, p, _, a, _, b, _, c_op, c, _), span| {
260                    ok!(SetpCmpopBoolopFtzF16 {
261                        cmpop = cmpop,
262                        boolop = boolop,
263                        ftz = ftz,
264                        f16 = f16,
265                        p = p,
266                        a = a,
267                        b = b,
268                        c_op = c_op,
269                        c = c,
270
271                    })
272                },
273            )
274        }
275    }
276
277    impl PtxParser for SetpCmpopFtzF16x2 {
278        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
279            try_map(
280                seq_n!(
281                    string_p("setp"),
282                    Cmpop::parse(),
283                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
284                    string_p(".f16x2"),
285                    GeneralOperand::parse(),
286                    pipe_p(),
287                    GeneralOperand::parse(),
288                    comma_p(),
289                    GeneralOperand::parse(),
290                    comma_p(),
291                    GeneralOperand::parse(),
292                    semicolon_p()
293                ),
294                |(_, cmpop, ftz, f16x2, p, _, q, _, a, _, b, _), span| {
295                    ok!(SetpCmpopFtzF16x2 {
296                        cmpop = cmpop,
297                        ftz = ftz,
298                        f16x2 = f16x2,
299                        p = p,
300                        q = q,
301                        a = a,
302                        b = b,
303
304                    })
305                },
306            )
307        }
308    }
309
310    impl PtxParser for SetpCmpopBoolopFtzF16x2 {
311        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
312            try_map(
313                seq_n!(
314                    string_p("setp"),
315                    Cmpop::parse(),
316                    Boolop::parse(),
317                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
318                    string_p(".f16x2"),
319                    GeneralOperand::parse(),
320                    pipe_p(),
321                    GeneralOperand::parse(),
322                    comma_p(),
323                    GeneralOperand::parse(),
324                    comma_p(),
325                    GeneralOperand::parse(),
326                    comma_p(),
327                    map(optional(exclamation_p()), |value, _| value.is_some()),
328                    GeneralOperand::parse(),
329                    semicolon_p()
330                ),
331                |(_, cmpop, boolop, ftz, f16x2, p, _, q, _, a, _, b, _, c_op, c, _), span| {
332                    ok!(SetpCmpopBoolopFtzF16x2 {
333                        cmpop = cmpop,
334                        boolop = boolop,
335                        ftz = ftz,
336                        f16x2 = f16x2,
337                        p = p,
338                        q = q,
339                        a = a,
340                        b = b,
341                        c_op = c_op,
342                        c = c,
343
344                    })
345                },
346            )
347        }
348    }
349
350    impl PtxParser for SetpCmpopBf16 {
351        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
352            try_map(
353                seq_n!(
354                    string_p("setp"),
355                    Cmpop::parse(),
356                    string_p(".bf16"),
357                    GeneralOperand::parse(),
358                    comma_p(),
359                    GeneralOperand::parse(),
360                    comma_p(),
361                    GeneralOperand::parse(),
362                    semicolon_p()
363                ),
364                |(_, cmpop, bf16, p, _, a, _, b, _), span| {
365                    ok!(SetpCmpopBf16 {
366                        cmpop = cmpop,
367                        bf16 = bf16,
368                        p = p,
369                        a = a,
370                        b = b,
371
372                    })
373                },
374            )
375        }
376    }
377
378    impl PtxParser for SetpCmpopBoolopBf16 {
379        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
380            try_map(
381                seq_n!(
382                    string_p("setp"),
383                    Cmpop::parse(),
384                    Boolop::parse(),
385                    string_p(".bf16"),
386                    GeneralOperand::parse(),
387                    comma_p(),
388                    GeneralOperand::parse(),
389                    comma_p(),
390                    GeneralOperand::parse(),
391                    comma_p(),
392                    map(optional(exclamation_p()), |value, _| value.is_some()),
393                    GeneralOperand::parse(),
394                    semicolon_p()
395                ),
396                |(_, cmpop, boolop, bf16, p, _, a, _, b, _, c_op, c, _), span| {
397                    ok!(SetpCmpopBoolopBf16 {
398                        cmpop = cmpop,
399                        boolop = boolop,
400                        bf16 = bf16,
401                        p = p,
402                        a = a,
403                        b = b,
404                        c_op = c_op,
405                        c = c,
406
407                    })
408                },
409            )
410        }
411    }
412
413    impl PtxParser for SetpCmpopBf16x2 {
414        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
415            try_map(
416                seq_n!(
417                    string_p("setp"),
418                    Cmpop::parse(),
419                    string_p(".bf16x2"),
420                    GeneralOperand::parse(),
421                    pipe_p(),
422                    GeneralOperand::parse(),
423                    comma_p(),
424                    GeneralOperand::parse(),
425                    comma_p(),
426                    GeneralOperand::parse(),
427                    semicolon_p()
428                ),
429                |(_, cmpop, bf16x2, p, _, q, _, a, _, b, _), span| {
430                    ok!(SetpCmpopBf16x2 {
431                        cmpop = cmpop,
432                        bf16x2 = bf16x2,
433                        p = p,
434                        q = q,
435                        a = a,
436                        b = b,
437
438                    })
439                },
440            )
441        }
442    }
443
444    impl PtxParser for SetpCmpopBoolopBf16x2 {
445        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
446            try_map(
447                seq_n!(
448                    string_p("setp"),
449                    Cmpop::parse(),
450                    Boolop::parse(),
451                    string_p(".bf16x2"),
452                    GeneralOperand::parse(),
453                    pipe_p(),
454                    GeneralOperand::parse(),
455                    comma_p(),
456                    GeneralOperand::parse(),
457                    comma_p(),
458                    GeneralOperand::parse(),
459                    comma_p(),
460                    map(optional(exclamation_p()), |value, _| value.is_some()),
461                    GeneralOperand::parse(),
462                    semicolon_p()
463                ),
464                |(_, cmpop, boolop, bf16x2, p, _, q, _, a, _, b, _, c_op, c, _), span| {
465                    ok!(SetpCmpopBoolopBf16x2 {
466                        cmpop = cmpop,
467                        boolop = boolop,
468                        bf16x2 = bf16x2,
469                        p = p,
470                        q = q,
471                        a = a,
472                        b = b,
473                        c_op = c_op,
474                        c = c,
475
476                    })
477                },
478            )
479        }
480    }
481}