ptx_parser/parser/instruction/
sqrt.rs

1//! Original PTX specification:
2//!
3//! sqrt.approx{.ftz}.f32  d, a; // fast, approximate square root
4//! sqrt.rnd{.ftz}.f32     d, a; // IEEE 754 compliant rounding
5//! sqrt.rnd.f64           d, a; // IEEE 754 compliant rounding
6//! .rnd = { .rn, .rz, .rm, .rp };
7
8#![allow(unused)]
9
10use crate::lexer::PtxToken;
11use crate::parser::{PtxParseError, PtxParser, PtxTokenStream, Span};
12use crate::r#type::common::*;
13
14pub mod section_0 {
15    use super::*;
16    use crate::r#type::instruction::sqrt::section_0::*;
17
18    // ============================================================================
19    // Generated enum parsers
20    // ============================================================================
21
22    impl PtxParser for Rnd {
23        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
24            // Try Rn
25            {
26                let saved_pos = stream.position();
27                if stream.expect_string(".rn").is_ok() {
28                    return Ok(Rnd::Rn);
29                }
30                stream.set_position(saved_pos);
31            }
32            let saved_pos = stream.position();
33            // Try Rz
34            {
35                let saved_pos = stream.position();
36                if stream.expect_string(".rz").is_ok() {
37                    return Ok(Rnd::Rz);
38                }
39                stream.set_position(saved_pos);
40            }
41            stream.set_position(saved_pos);
42            let saved_pos = stream.position();
43            // Try Rm
44            {
45                let saved_pos = stream.position();
46                if stream.expect_string(".rm").is_ok() {
47                    return Ok(Rnd::Rm);
48                }
49                stream.set_position(saved_pos);
50            }
51            stream.set_position(saved_pos);
52            let saved_pos = stream.position();
53            // Try Rp
54            {
55                let saved_pos = stream.position();
56                if stream.expect_string(".rp").is_ok() {
57                    return Ok(Rnd::Rp);
58                }
59                stream.set_position(saved_pos);
60            }
61            stream.set_position(saved_pos);
62            let span = stream
63                .peek()
64                .map(|(_, s)| s.clone())
65                .unwrap_or(Span { start: 0, end: 0 });
66            let expected = &[".rn", ".rz", ".rm", ".rp"];
67            let found = stream
68                .peek()
69                .map(|(t, _)| format!("{:?}", t))
70                .unwrap_or_else(|_| "<end of input>".to_string());
71            Err(crate::parser::unexpected_value(span, expected, found))
72        }
73    }
74
75    impl PtxParser for SqrtApproxFtzF32 {
76        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
77            stream.expect_string("sqrt")?;
78            stream.expect_string(".approx")?;
79            let approx = ();
80            stream.expect_complete()?;
81            let saved_pos = stream.position();
82            let ftz = stream.expect_string(".ftz").is_ok();
83            if !ftz {
84                stream.set_position(saved_pos);
85            }
86            stream.expect_complete()?;
87            stream.expect_string(".f32")?;
88            let f32 = ();
89            stream.expect_complete()?;
90            let d = GeneralOperand::parse(stream)?;
91            stream.expect_complete()?;
92            stream.expect(&PtxToken::Comma)?;
93            let a = GeneralOperand::parse(stream)?;
94            stream.expect_complete()?;
95            stream.expect_complete()?;
96            stream.expect(&PtxToken::Semicolon)?;
97            Ok(SqrtApproxFtzF32 {
98                approx,
99                ftz,
100                f32,
101                d,
102                a,
103            })
104        }
105    }
106
107    impl PtxParser for SqrtRndFtzF32 {
108        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
109            stream.expect_string("sqrt")?;
110            let rnd = Rnd::parse(stream)?;
111            stream.expect_complete()?;
112            let saved_pos = stream.position();
113            let ftz = stream.expect_string(".ftz").is_ok();
114            if !ftz {
115                stream.set_position(saved_pos);
116            }
117            stream.expect_complete()?;
118            stream.expect_string(".f32")?;
119            let f32 = ();
120            stream.expect_complete()?;
121            let d = GeneralOperand::parse(stream)?;
122            stream.expect_complete()?;
123            stream.expect(&PtxToken::Comma)?;
124            let a = GeneralOperand::parse(stream)?;
125            stream.expect_complete()?;
126            stream.expect_complete()?;
127            stream.expect(&PtxToken::Semicolon)?;
128            Ok(SqrtRndFtzF32 {
129                rnd,
130                ftz,
131                f32,
132                d,
133                a,
134            })
135        }
136    }
137
138    impl PtxParser for SqrtRndF64 {
139        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
140            stream.expect_string("sqrt")?;
141            let rnd = Rnd::parse(stream)?;
142            stream.expect_complete()?;
143            stream.expect_string(".f64")?;
144            let f64 = ();
145            stream.expect_complete()?;
146            let d = GeneralOperand::parse(stream)?;
147            stream.expect_complete()?;
148            stream.expect(&PtxToken::Comma)?;
149            let a = GeneralOperand::parse(stream)?;
150            stream.expect_complete()?;
151            stream.expect_complete()?;
152            stream.expect(&PtxToken::Semicolon)?;
153            Ok(SqrtRndF64 { rnd, f64, d, a })
154        }
155    }
156}