Skip to main content

ptx_parser/unparser/instruction/
shf.rs

1//! Original PTX specification:
2//!
3//! shf.l.mode.b32  d, a, b, c;  // left shift
4//! shf.r.mode.b32  d, a, b, c;  // right shift
5//! .mode = { .clamp, .wrap };
6
7#![allow(unused)]
8
9use crate::lexer::PtxToken;
10use crate::unparser::{PtxUnparser, common::*};
11
12pub mod section_0 {
13    use super::*;
14    use crate::r#type::instruction::shf::section_0::*;
15
16    impl PtxUnparser for ShfLModeB32 {
17        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
18            self.unparse_tokens_mode(tokens, false);
19        }
20        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
21            push_opcode(tokens, "shf");
22            push_directive(tokens, "l");
23            match &self.mode {
24                Mode::Clamp => {
25                    push_directive(tokens, "clamp");
26                }
27                Mode::Wrap => {
28                    push_directive(tokens, "wrap");
29                }
30            }
31            push_directive(tokens, "b32");
32            if spaced {
33                tokens.push(PtxToken::Space);
34            }
35            self.d.unparse_tokens_mode(tokens, spaced);
36            tokens.push(PtxToken::Comma);
37            if spaced {
38                tokens.push(PtxToken::Space);
39            }
40            self.a.unparse_tokens_mode(tokens, spaced);
41            tokens.push(PtxToken::Comma);
42            if spaced {
43                tokens.push(PtxToken::Space);
44            }
45            self.b.unparse_tokens_mode(tokens, spaced);
46            tokens.push(PtxToken::Comma);
47            if spaced {
48                tokens.push(PtxToken::Space);
49            }
50            self.c.unparse_tokens_mode(tokens, spaced);
51            tokens.push(PtxToken::Semicolon);
52            if spaced {
53                tokens.push(PtxToken::Newline);
54            }
55        }
56    }
57
58    impl PtxUnparser for ShfRModeB32 {
59        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
60            self.unparse_tokens_mode(tokens, false);
61        }
62        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
63            push_opcode(tokens, "shf");
64            push_directive(tokens, "r");
65            match &self.mode {
66                Mode::Clamp => {
67                    push_directive(tokens, "clamp");
68                }
69                Mode::Wrap => {
70                    push_directive(tokens, "wrap");
71                }
72            }
73            push_directive(tokens, "b32");
74            if spaced {
75                tokens.push(PtxToken::Space);
76            }
77            self.d.unparse_tokens_mode(tokens, spaced);
78            tokens.push(PtxToken::Comma);
79            if spaced {
80                tokens.push(PtxToken::Space);
81            }
82            self.a.unparse_tokens_mode(tokens, spaced);
83            tokens.push(PtxToken::Comma);
84            if spaced {
85                tokens.push(PtxToken::Space);
86            }
87            self.b.unparse_tokens_mode(tokens, spaced);
88            tokens.push(PtxToken::Comma);
89            if spaced {
90                tokens.push(PtxToken::Space);
91            }
92            self.c.unparse_tokens_mode(tokens, spaced);
93            tokens.push(PtxToken::Semicolon);
94            if spaced {
95                tokens.push(PtxToken::Newline);
96            }
97        }
98    }
99}