ptx_parser/parser/instruction/
neg.rs

1//! Original PTX specification:
2//!
3//! neg.type  d, a;
4//! .type = { .s16, .s32, .s64 };
5//!
6//! neg{.ftz}.f32  d, a;
7//! neg.f64        d, a;
8//!
9//! neg{.ftz}.f16    d, a;
10//! neg{.ftz}.f16x2  d, a;
11//! neg.bf16         d, a;
12//! neg.bf16x2       d, a;
13
14#![allow(unused)]
15
16use crate::lexer::PtxToken;
17use crate::parser::{PtxParseError, PtxParser, PtxTokenStream, Span};
18use crate::r#type::common::*;
19
20pub mod section_0 {
21    use super::*;
22    use crate::r#type::instruction::neg::section_0::*;
23
24    // ============================================================================
25    // Generated enum parsers
26    // ============================================================================
27
28    impl PtxParser for Type {
29        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
30            // Try S16
31            {
32                let saved_pos = stream.position();
33                if stream.expect_string(".s16").is_ok() {
34                    return Ok(Type::S16);
35                }
36                stream.set_position(saved_pos);
37            }
38            let saved_pos = stream.position();
39            // Try S32
40            {
41                let saved_pos = stream.position();
42                if stream.expect_string(".s32").is_ok() {
43                    return Ok(Type::S32);
44                }
45                stream.set_position(saved_pos);
46            }
47            stream.set_position(saved_pos);
48            let saved_pos = stream.position();
49            // Try S64
50            {
51                let saved_pos = stream.position();
52                if stream.expect_string(".s64").is_ok() {
53                    return Ok(Type::S64);
54                }
55                stream.set_position(saved_pos);
56            }
57            stream.set_position(saved_pos);
58            let span = stream
59                .peek()
60                .map(|(_, s)| s.clone())
61                .unwrap_or(Span { start: 0, end: 0 });
62            let expected = &[".s16", ".s32", ".s64"];
63            let found = stream
64                .peek()
65                .map(|(t, _)| format!("{:?}", t))
66                .unwrap_or_else(|_| "<end of input>".to_string());
67            Err(crate::parser::unexpected_value(span, expected, found))
68        }
69    }
70
71    impl PtxParser for NegType {
72        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
73            stream.expect_string("neg")?;
74            let type_ = Type::parse(stream)?;
75            stream.expect_complete()?;
76            let d = GeneralOperand::parse(stream)?;
77            stream.expect_complete()?;
78            stream.expect(&PtxToken::Comma)?;
79            let a = GeneralOperand::parse(stream)?;
80            stream.expect_complete()?;
81            stream.expect_complete()?;
82            stream.expect(&PtxToken::Semicolon)?;
83            Ok(NegType { type_, d, a })
84        }
85    }
86
87    impl PtxParser for NegFtzF32 {
88        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
89            stream.expect_string("neg")?;
90            let saved_pos = stream.position();
91            let ftz = stream.expect_string(".ftz").is_ok();
92            if !ftz {
93                stream.set_position(saved_pos);
94            }
95            stream.expect_complete()?;
96            stream.expect_string(".f32")?;
97            let f32 = ();
98            stream.expect_complete()?;
99            let d = GeneralOperand::parse(stream)?;
100            stream.expect_complete()?;
101            stream.expect(&PtxToken::Comma)?;
102            let a = GeneralOperand::parse(stream)?;
103            stream.expect_complete()?;
104            stream.expect_complete()?;
105            stream.expect(&PtxToken::Semicolon)?;
106            Ok(NegFtzF32 { ftz, f32, d, a })
107        }
108    }
109
110    impl PtxParser for NegF64 {
111        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
112            stream.expect_string("neg")?;
113            stream.expect_string(".f64")?;
114            let f64 = ();
115            stream.expect_complete()?;
116            let d = GeneralOperand::parse(stream)?;
117            stream.expect_complete()?;
118            stream.expect(&PtxToken::Comma)?;
119            let a = GeneralOperand::parse(stream)?;
120            stream.expect_complete()?;
121            stream.expect_complete()?;
122            stream.expect(&PtxToken::Semicolon)?;
123            Ok(NegF64 { f64, d, a })
124        }
125    }
126
127    impl PtxParser for NegFtzF16 {
128        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
129            stream.expect_string("neg")?;
130            let saved_pos = stream.position();
131            let ftz = stream.expect_string(".ftz").is_ok();
132            if !ftz {
133                stream.set_position(saved_pos);
134            }
135            stream.expect_complete()?;
136            stream.expect_string(".f16")?;
137            let f16 = ();
138            stream.expect_complete()?;
139            let d = GeneralOperand::parse(stream)?;
140            stream.expect_complete()?;
141            stream.expect(&PtxToken::Comma)?;
142            let a = GeneralOperand::parse(stream)?;
143            stream.expect_complete()?;
144            stream.expect_complete()?;
145            stream.expect(&PtxToken::Semicolon)?;
146            Ok(NegFtzF16 { ftz, f16, d, a })
147        }
148    }
149
150    impl PtxParser for NegFtzF16x2 {
151        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
152            stream.expect_string("neg")?;
153            let saved_pos = stream.position();
154            let ftz = stream.expect_string(".ftz").is_ok();
155            if !ftz {
156                stream.set_position(saved_pos);
157            }
158            stream.expect_complete()?;
159            stream.expect_string(".f16x2")?;
160            let f16x2 = ();
161            stream.expect_complete()?;
162            let d = GeneralOperand::parse(stream)?;
163            stream.expect_complete()?;
164            stream.expect(&PtxToken::Comma)?;
165            let a = GeneralOperand::parse(stream)?;
166            stream.expect_complete()?;
167            stream.expect_complete()?;
168            stream.expect(&PtxToken::Semicolon)?;
169            Ok(NegFtzF16x2 { ftz, f16x2, d, a })
170        }
171    }
172
173    impl PtxParser for NegBf16 {
174        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
175            stream.expect_string("neg")?;
176            stream.expect_string(".bf16")?;
177            let bf16 = ();
178            stream.expect_complete()?;
179            let d = GeneralOperand::parse(stream)?;
180            stream.expect_complete()?;
181            stream.expect(&PtxToken::Comma)?;
182            let a = GeneralOperand::parse(stream)?;
183            stream.expect_complete()?;
184            stream.expect_complete()?;
185            stream.expect(&PtxToken::Semicolon)?;
186            Ok(NegBf16 { bf16, d, a })
187        }
188    }
189
190    impl PtxParser for NegBf16x2 {
191        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
192            stream.expect_string("neg")?;
193            stream.expect_string(".bf16x2")?;
194            let bf16x2 = ();
195            stream.expect_complete()?;
196            let d = GeneralOperand::parse(stream)?;
197            stream.expect_complete()?;
198            stream.expect(&PtxToken::Comma)?;
199            let a = GeneralOperand::parse(stream)?;
200            stream.expect_complete()?;
201            stream.expect_complete()?;
202            stream.expect(&PtxToken::Semicolon)?;
203            Ok(NegBf16x2 { bf16x2, d, a })
204        }
205    }
206}