ptx_parser/unparser/instruction/
createpolicy.rs

1//! Original PTX specification:
2//!
3//! // Range-based policy
4//! createpolicy.range{.global}.level::primary_priority{.level::secondary_priority}.b64
5//! cache-policy, [a], primary-size, total-size;
6//! // Fraction-based policy
7//! createpolicy.fractional.level::primary_priority{.level::secondary_priority}.b64
8//! cache-policy{, fraction};
9//! // Converting the access property from CUDA APIs
10//! createpolicy.cvt.L2.b64            cache-policy, access-property;
11//! .level::primary_priority =   { .L2::evict_last, .L2::evict_normal,
12//! .L2::evict_first, .L2::evict_unchanged };
13//! .level::secondary_priority = { .L2::evict_first, .L2::evict_unchanged };
14
15#![allow(unused)]
16
17use crate::lexer::PtxToken;
18use crate::unparser::{PtxUnparser, common::*};
19
20pub mod section_0 {
21    use super::*;
22    use crate::r#type::instruction::createpolicy::section_0::*;
23
24    impl PtxUnparser for CreatepolicyRangeGlobalLevelPrimaryPriorityLevelSecondaryPriorityB64 {
25        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
26            push_opcode(tokens, "createpolicy");
27            push_directive(tokens, "range");
28            if self.global {
29                push_directive(tokens, "global");
30            }
31            match &self.level_primary_priority {
32                LevelPrimaryPriority::L2EvictUnchanged => {
33                    push_directive(tokens, "L2::evict_unchanged");
34                }
35                LevelPrimaryPriority::L2EvictNormal => {
36                    push_directive(tokens, "L2::evict_normal");
37                }
38                LevelPrimaryPriority::L2EvictFirst => {
39                    push_directive(tokens, "L2::evict_first");
40                }
41                LevelPrimaryPriority::L2EvictLast => {
42                    push_directive(tokens, "L2::evict_last");
43                }
44            }
45            if let Some(level_secondary_priority_0) = self.level_secondary_priority.as_ref() {
46                match level_secondary_priority_0 {
47                    LevelSecondaryPriority::L2EvictUnchanged => {
48                        push_directive(tokens, "L2::evict_unchanged");
49                    }
50                    LevelSecondaryPriority::L2EvictFirst => {
51                        push_directive(tokens, "L2::evict_first");
52                    }
53                }
54            }
55            push_directive(tokens, "b64");
56            self.cache_policy.unparse_tokens(tokens);
57            tokens.push(PtxToken::Comma);
58            self.a.unparse_tokens(tokens);
59            tokens.push(PtxToken::Comma);
60            self.primary_size.unparse_tokens(tokens);
61            tokens.push(PtxToken::Comma);
62            self.total_size.unparse_tokens(tokens);
63            tokens.push(PtxToken::Semicolon);
64        }
65    }
66
67    impl PtxUnparser for CreatepolicyFractionalLevelPrimaryPriorityLevelSecondaryPriorityB64 {
68        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
69            push_opcode(tokens, "createpolicy");
70            push_directive(tokens, "fractional");
71            match &self.level_primary_priority {
72                LevelPrimaryPriority::L2EvictUnchanged => {
73                    push_directive(tokens, "L2::evict_unchanged");
74                }
75                LevelPrimaryPriority::L2EvictNormal => {
76                    push_directive(tokens, "L2::evict_normal");
77                }
78                LevelPrimaryPriority::L2EvictFirst => {
79                    push_directive(tokens, "L2::evict_first");
80                }
81                LevelPrimaryPriority::L2EvictLast => {
82                    push_directive(tokens, "L2::evict_last");
83                }
84            }
85            if let Some(level_secondary_priority_1) = self.level_secondary_priority.as_ref() {
86                match level_secondary_priority_1 {
87                    LevelSecondaryPriority::L2EvictUnchanged => {
88                        push_directive(tokens, "L2::evict_unchanged");
89                    }
90                    LevelSecondaryPriority::L2EvictFirst => {
91                        push_directive(tokens, "L2::evict_first");
92                    }
93                }
94            }
95            push_directive(tokens, "b64");
96            self.cache_policy.unparse_tokens(tokens);
97            if self.fraction.is_some() {
98                tokens.push(PtxToken::Comma);
99            }
100            if let Some(opt_2) = self.fraction.as_ref() {
101                opt_2.unparse_tokens(tokens);
102            }
103            tokens.push(PtxToken::Semicolon);
104        }
105    }
106
107    impl PtxUnparser for CreatepolicyCvtL2B64 {
108        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
109            push_opcode(tokens, "createpolicy");
110            push_directive(tokens, "cvt");
111            push_directive(tokens, "L2");
112            push_directive(tokens, "b64");
113            self.cache_policy.unparse_tokens(tokens);
114            tokens.push(PtxToken::Comma);
115            self.access_property.unparse_tokens(tokens);
116            tokens.push(PtxToken::Semicolon);
117        }
118    }
119}