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.peek().map(|(_, s)| s.clone()).unwrap_or(Span { start: 0, end: 0 });
59            let expected = &[".s16", ".s32", ".s64"];
60            let found = stream.peek().map(|(t, _)| format!("{:?}", t)).unwrap_or_else(|_| "<end of input>".to_string());
61            Err(crate::parser::unexpected_value(span, expected, found))
62        }
63    }
64
65    impl PtxParser for NegType {
66        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
67            stream.expect_string("neg")?;
68            let type_ = Type::parse(stream)?;
69            stream.expect_complete()?;
70            let d = GeneralOperand::parse(stream)?;
71            stream.expect_complete()?;
72            stream.expect(&PtxToken::Comma)?;
73            let a = GeneralOperand::parse(stream)?;
74            stream.expect_complete()?;
75            stream.expect_complete()?;
76            stream.expect(&PtxToken::Semicolon)?;
77            Ok(NegType {
78                type_,
79                d,
80                a,
81            })
82        }
83    }
84
85
86    impl PtxParser for NegFtzF32 {
87        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
88            stream.expect_string("neg")?;
89            let saved_pos = stream.position();
90            let ftz = stream.expect_string(".ftz").is_ok();
91            if !ftz {
92                stream.set_position(saved_pos);
93            }
94            stream.expect_complete()?;
95            stream.expect_string(".f32")?;
96            let f32 = ();
97            stream.expect_complete()?;
98            let d = GeneralOperand::parse(stream)?;
99            stream.expect_complete()?;
100            stream.expect(&PtxToken::Comma)?;
101            let a = GeneralOperand::parse(stream)?;
102            stream.expect_complete()?;
103            stream.expect_complete()?;
104            stream.expect(&PtxToken::Semicolon)?;
105            Ok(NegFtzF32 {
106                ftz,
107                f32,
108                d,
109                a,
110            })
111        }
112    }
113
114
115    impl PtxParser for NegF64 {
116        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
117            stream.expect_string("neg")?;
118            stream.expect_string(".f64")?;
119            let f64 = ();
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(NegF64 {
129                f64,
130                d,
131                a,
132            })
133        }
134    }
135
136
137    impl PtxParser for NegFtzF16 {
138        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
139            stream.expect_string("neg")?;
140            let saved_pos = stream.position();
141            let ftz = stream.expect_string(".ftz").is_ok();
142            if !ftz {
143                stream.set_position(saved_pos);
144            }
145            stream.expect_complete()?;
146            stream.expect_string(".f16")?;
147            let f16 = ();
148            stream.expect_complete()?;
149            let d = GeneralOperand::parse(stream)?;
150            stream.expect_complete()?;
151            stream.expect(&PtxToken::Comma)?;
152            let a = GeneralOperand::parse(stream)?;
153            stream.expect_complete()?;
154            stream.expect_complete()?;
155            stream.expect(&PtxToken::Semicolon)?;
156            Ok(NegFtzF16 {
157                ftz,
158                f16,
159                d,
160                a,
161            })
162        }
163    }
164
165
166    impl PtxParser for NegFtzF16x2 {
167        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
168            stream.expect_string("neg")?;
169            let saved_pos = stream.position();
170            let ftz = stream.expect_string(".ftz").is_ok();
171            if !ftz {
172                stream.set_position(saved_pos);
173            }
174            stream.expect_complete()?;
175            stream.expect_string(".f16x2")?;
176            let f16x2 = ();
177            stream.expect_complete()?;
178            let d = GeneralOperand::parse(stream)?;
179            stream.expect_complete()?;
180            stream.expect(&PtxToken::Comma)?;
181            let a = GeneralOperand::parse(stream)?;
182            stream.expect_complete()?;
183            stream.expect_complete()?;
184            stream.expect(&PtxToken::Semicolon)?;
185            Ok(NegFtzF16x2 {
186                ftz,
187                f16x2,
188                d,
189                a,
190            })
191        }
192    }
193
194
195    impl PtxParser for NegBf16 {
196        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
197            stream.expect_string("neg")?;
198            stream.expect_string(".bf16")?;
199            let bf16 = ();
200            stream.expect_complete()?;
201            let d = GeneralOperand::parse(stream)?;
202            stream.expect_complete()?;
203            stream.expect(&PtxToken::Comma)?;
204            let a = GeneralOperand::parse(stream)?;
205            stream.expect_complete()?;
206            stream.expect_complete()?;
207            stream.expect(&PtxToken::Semicolon)?;
208            Ok(NegBf16 {
209                bf16,
210                d,
211                a,
212            })
213        }
214    }
215
216
217    impl PtxParser for NegBf16x2 {
218        fn parse(stream: &mut PtxTokenStream) -> Result<Self, PtxParseError> {
219            stream.expect_string("neg")?;
220            stream.expect_string(".bf16x2")?;
221            let bf16x2 = ();
222            stream.expect_complete()?;
223            let d = GeneralOperand::parse(stream)?;
224            stream.expect_complete()?;
225            stream.expect(&PtxToken::Comma)?;
226            let a = GeneralOperand::parse(stream)?;
227            stream.expect_complete()?;
228            stream.expect_complete()?;
229            stream.expect(&PtxToken::Semicolon)?;
230            Ok(NegBf16x2 {
231                bf16x2,
232                d,
233                a,
234            })
235        }
236    }
237
238
239}
240