ptx_parser/unparser/instruction/
mad.rs

1//! Original PTX specification:
2//!
3//! mad.mode.type  d, a, b, c;
4//! mad.hi.sat.s32 d, a, b, c;
5//! .mode = { .hi, .lo, .wide };
6//! .type = { .u16, .u32, .u64,
7//! .s16, .s32, .s64 };
8//!
9//! mad{.ftz}{.sat}.f32      d, a, b, c;    // .target sm_1x
10//! mad.rnd{.ftz}{.sat}.f32  d, a, b, c;    // .target sm_20
11//! mad.rnd.f64              d, a, b, c;    // .target sm_13 and higher
12//! .rnd = { .rn, .rz, .rm, .rp };
13
14#![allow(unused)]
15
16use crate::lexer::PtxToken;
17use crate::unparser::{PtxUnparser, common::*};
18
19pub mod section_0 {
20    use super::*;
21    use crate::r#type::instruction::mad::section_0::*;
22
23    impl PtxUnparser for MadModeType {
24        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
25            push_opcode(tokens, "mad");
26            match &self.mode {
27                Mode::Wide => {
28                    push_directive(tokens, "wide");
29                }
30                Mode::Hi => {
31                    push_directive(tokens, "hi");
32                }
33                Mode::Lo => {
34                    push_directive(tokens, "lo");
35                }
36            }
37            match &self.type_ {
38                Type::U16 => {
39                    push_directive(tokens, "u16");
40                }
41                Type::U32 => {
42                    push_directive(tokens, "u32");
43                }
44                Type::U64 => {
45                    push_directive(tokens, "u64");
46                }
47                Type::S16 => {
48                    push_directive(tokens, "s16");
49                }
50                Type::S32 => {
51                    push_directive(tokens, "s32");
52                }
53                Type::S64 => {
54                    push_directive(tokens, "s64");
55                }
56            }
57            self.d.unparse_tokens(tokens);
58            tokens.push(PtxToken::Comma);
59            self.a.unparse_tokens(tokens);
60            tokens.push(PtxToken::Comma);
61            self.b.unparse_tokens(tokens);
62            tokens.push(PtxToken::Comma);
63            self.c.unparse_tokens(tokens);
64            tokens.push(PtxToken::Semicolon);
65        }
66    }
67
68    impl PtxUnparser for MadHiSatS32 {
69        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
70            push_opcode(tokens, "mad");
71            push_directive(tokens, "hi");
72            push_directive(tokens, "sat");
73            push_directive(tokens, "s32");
74            self.d.unparse_tokens(tokens);
75            tokens.push(PtxToken::Comma);
76            self.a.unparse_tokens(tokens);
77            tokens.push(PtxToken::Comma);
78            self.b.unparse_tokens(tokens);
79            tokens.push(PtxToken::Comma);
80            self.c.unparse_tokens(tokens);
81            tokens.push(PtxToken::Semicolon);
82        }
83    }
84
85    impl PtxUnparser for MadFtzSatF32 {
86        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
87            push_opcode(tokens, "mad");
88            if self.ftz {
89                push_directive(tokens, "ftz");
90            }
91            if self.sat {
92                push_directive(tokens, "sat");
93            }
94            push_directive(tokens, "f32");
95            self.d.unparse_tokens(tokens);
96            tokens.push(PtxToken::Comma);
97            self.a.unparse_tokens(tokens);
98            tokens.push(PtxToken::Comma);
99            self.b.unparse_tokens(tokens);
100            tokens.push(PtxToken::Comma);
101            self.c.unparse_tokens(tokens);
102            tokens.push(PtxToken::Semicolon);
103        }
104    }
105
106    impl PtxUnparser for MadRndFtzSatF32 {
107        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
108            push_opcode(tokens, "mad");
109            match &self.rnd {
110                Rnd::Rn => {
111                    push_directive(tokens, "rn");
112                }
113                Rnd::Rz => {
114                    push_directive(tokens, "rz");
115                }
116                Rnd::Rm => {
117                    push_directive(tokens, "rm");
118                }
119                Rnd::Rp => {
120                    push_directive(tokens, "rp");
121                }
122            }
123            if self.ftz {
124                push_directive(tokens, "ftz");
125            }
126            if self.sat {
127                push_directive(tokens, "sat");
128            }
129            push_directive(tokens, "f32");
130            self.d.unparse_tokens(tokens);
131            tokens.push(PtxToken::Comma);
132            self.a.unparse_tokens(tokens);
133            tokens.push(PtxToken::Comma);
134            self.b.unparse_tokens(tokens);
135            tokens.push(PtxToken::Comma);
136            self.c.unparse_tokens(tokens);
137            tokens.push(PtxToken::Semicolon);
138        }
139    }
140
141    impl PtxUnparser for MadRndF64 {
142        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
143            push_opcode(tokens, "mad");
144            match &self.rnd {
145                Rnd::Rn => {
146                    push_directive(tokens, "rn");
147                }
148                Rnd::Rz => {
149                    push_directive(tokens, "rz");
150                }
151                Rnd::Rm => {
152                    push_directive(tokens, "rm");
153                }
154                Rnd::Rp => {
155                    push_directive(tokens, "rp");
156                }
157            }
158            push_directive(tokens, "f64");
159            self.d.unparse_tokens(tokens);
160            tokens.push(PtxToken::Comma);
161            self.a.unparse_tokens(tokens);
162            tokens.push(PtxToken::Comma);
163            self.b.unparse_tokens(tokens);
164            tokens.push(PtxToken::Comma);
165            self.c.unparse_tokens(tokens);
166            tokens.push(PtxToken::Semicolon);
167        }
168    }
169}