Skip to main content

ptx_parser/parser/instruction/
rsqrt.rs

1//! Original PTX specification:
2//!
3//! rsqrt.approx{.ftz}.f32  d, a;
4//! rsqrt.approx.f64        d, a;
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::rsqrt::section_0::*;
21
22    impl PtxParser for RsqrtApproxFtzF32 {
23        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
24            try_map(
25                seq_n!(
26                    string_p("rsqrt"),
27                    string_p(".approx"),
28                    map(optional(string_p(".ftz")), |value, _| value.is_some()),
29                    string_p(".f32"),
30                    GeneralOperand::parse(),
31                    comma_p(),
32                    GeneralOperand::parse(),
33                    semicolon_p()
34                ),
35                |(_, approx, ftz, f32, d, _, a, _), span| {
36                    ok!(RsqrtApproxFtzF32 {
37                        approx = approx,
38                        ftz = ftz,
39                        f32 = f32,
40                        d = d,
41                        a = a,
42
43                    })
44                },
45            )
46        }
47    }
48
49    impl PtxParser for RsqrtApproxF64 {
50        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
51            try_map(
52                seq_n!(
53                    string_p("rsqrt"),
54                    string_p(".approx"),
55                    string_p(".f64"),
56                    GeneralOperand::parse(),
57                    comma_p(),
58                    GeneralOperand::parse(),
59                    semicolon_p()
60                ),
61                |(_, approx, f64, d, _, a, _), span| {
62                    ok!(RsqrtApproxF64 {
63                        approx = approx,
64                        f64 = f64,
65                        d = d,
66                        a = a,
67
68                    })
69                },
70            )
71        }
72    }
73}