Skip to main content

ptx_parser/unparser/instruction/
rcp.rs

1//! Original PTX specification:
2//!
3//! rcp.approx{.ftz}.f32  d, a;  // fast, approximate reciprocal
4//! rcp.rnd{.ftz}.f32     d, a;  // IEEE 754 compliant rounding
5//! rcp.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::unparser::{PtxUnparser, common::*};
12
13pub mod section_0 {
14    use super::*;
15    use crate::r#type::instruction::rcp::section_0::*;
16
17    impl PtxUnparser for RcpApproxFtzF32 {
18        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
19            self.unparse_tokens_mode(tokens, false);
20        }
21        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
22            push_opcode(tokens, "rcp");
23            push_directive(tokens, "approx");
24            if self.ftz {
25                push_directive(tokens, "ftz");
26            }
27            push_directive(tokens, "f32");
28            if spaced {
29                tokens.push(PtxToken::Space);
30            }
31            self.d.unparse_tokens_mode(tokens, spaced);
32            tokens.push(PtxToken::Comma);
33            if spaced {
34                tokens.push(PtxToken::Space);
35            }
36            self.a.unparse_tokens_mode(tokens, spaced);
37            tokens.push(PtxToken::Semicolon);
38            if spaced {
39                tokens.push(PtxToken::Newline);
40            }
41        }
42    }
43
44    impl PtxUnparser for RcpRndFtzF32 {
45        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
46            self.unparse_tokens_mode(tokens, false);
47        }
48        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
49            push_opcode(tokens, "rcp");
50            match &self.rnd {
51                Rnd::Rn => {
52                    push_directive(tokens, "rn");
53                }
54                Rnd::Rz => {
55                    push_directive(tokens, "rz");
56                }
57                Rnd::Rm => {
58                    push_directive(tokens, "rm");
59                }
60                Rnd::Rp => {
61                    push_directive(tokens, "rp");
62                }
63            }
64            if self.ftz {
65                push_directive(tokens, "ftz");
66            }
67            push_directive(tokens, "f32");
68            if spaced {
69                tokens.push(PtxToken::Space);
70            }
71            self.d.unparse_tokens_mode(tokens, spaced);
72            tokens.push(PtxToken::Comma);
73            if spaced {
74                tokens.push(PtxToken::Space);
75            }
76            self.a.unparse_tokens_mode(tokens, spaced);
77            tokens.push(PtxToken::Semicolon);
78            if spaced {
79                tokens.push(PtxToken::Newline);
80            }
81        }
82    }
83
84    impl PtxUnparser for RcpRndF64 {
85        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
86            self.unparse_tokens_mode(tokens, false);
87        }
88        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
89            push_opcode(tokens, "rcp");
90            match &self.rnd {
91                Rnd::Rn => {
92                    push_directive(tokens, "rn");
93                }
94                Rnd::Rz => {
95                    push_directive(tokens, "rz");
96                }
97                Rnd::Rm => {
98                    push_directive(tokens, "rm");
99                }
100                Rnd::Rp => {
101                    push_directive(tokens, "rp");
102                }
103            }
104            push_directive(tokens, "f64");
105            if spaced {
106                tokens.push(PtxToken::Space);
107            }
108            self.d.unparse_tokens_mode(tokens, spaced);
109            tokens.push(PtxToken::Comma);
110            if spaced {
111                tokens.push(PtxToken::Space);
112            }
113            self.a.unparse_tokens_mode(tokens, spaced);
114            tokens.push(PtxToken::Semicolon);
115            if spaced {
116                tokens.push(PtxToken::Newline);
117            }
118        }
119    }
120}