ptx_parser/parser/instruction/
prefetch.rs

1//! Original PTX specification:
2//!
3//! prefetch{.space}.level                    [a];   // prefetch to data cache
4//! prefetch.global.level::eviction_priority  [a];   // prefetch to data cache
5//! prefetchu.L1  [a];             // prefetch to uniform cache
6//! prefetch{.tensormap_space}.tensormap [a];  // prefetch the tensormap
7//! .space =                    { .global, .local };
8//! .level =                    { .L1, .L2 };
9//! .level::eviction_priority = { .L2::evict_last, .L2::evict_normal };
10//! .tensormap_space =          { .const, .param };
11
12#![allow(unused)]
13
14use crate::parser::{
15    PtxParseError, PtxParser, PtxTokenStream, Span,
16    util::{
17        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
18        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
19    },
20};
21use crate::r#type::common::*;
22use crate::{alt, ok, seq_n};
23
24pub mod section_0 {
25    use super::*;
26    use crate::r#type::instruction::prefetch::section_0::*;
27
28    // ============================================================================
29    // Generated enum parsers
30    // ============================================================================
31
32    impl PtxParser for Level {
33        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
34            alt!(
35                map(string_p(".L1"), |_, _span| Level::L1),
36                map(string_p(".L2"), |_, _span| Level::L2)
37            )
38        }
39    }
40
41    impl PtxParser for LevelEvictionPriority {
42        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
43            alt!(
44                map(string_p(".L2::evict_normal"), |_, _span| {
45                    LevelEvictionPriority::L2EvictNormal
46                }),
47                map(string_p(".L2::evict_last"), |_, _span| {
48                    LevelEvictionPriority::L2EvictLast
49                })
50            )
51        }
52    }
53
54    impl PtxParser for Space {
55        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
56            alt!(
57                map(string_p(".global"), |_, _span| Space::Global),
58                map(string_p(".local"), |_, _span| Space::Local)
59            )
60        }
61    }
62
63    impl PtxParser for TensormapSpace {
64        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
65            alt!(
66                map(string_p(".const"), |_, _span| TensormapSpace::Const),
67                map(string_p(".param"), |_, _span| TensormapSpace::Param)
68            )
69        }
70    }
71
72    impl PtxParser for PrefetchSpaceLevel {
73        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
74            try_map(
75                seq_n!(
76                    string_p("prefetch"),
77                    optional(Space::parse()),
78                    Level::parse(),
79                    AddressOperand::parse(),
80                    semicolon_p()
81                ),
82                |(_, space, level, a, _), span| {
83                    ok!(PrefetchSpaceLevel {
84                        space = space,
85                        level = level,
86                        a = a,
87
88                    })
89                },
90            )
91        }
92    }
93
94    impl PtxParser for PrefetchGlobalLevelEvictionPriority {
95        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
96            try_map(
97                seq_n!(
98                    string_p("prefetch"),
99                    string_p(".global"),
100                    LevelEvictionPriority::parse(),
101                    AddressOperand::parse(),
102                    semicolon_p()
103                ),
104                |(_, global, level_eviction_priority, a, _), span| {
105                    ok!(PrefetchGlobalLevelEvictionPriority {
106                        global = global,
107                        level_eviction_priority = level_eviction_priority,
108                        a = a,
109
110                    })
111                },
112            )
113        }
114    }
115
116    impl PtxParser for PrefetchuL1 {
117        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
118            try_map(
119                seq_n!(
120                    string_p("prefetchu"),
121                    string_p(".L1"),
122                    AddressOperand::parse(),
123                    semicolon_p()
124                ),
125                |(_, l1, a, _), span| {
126                    ok!(PrefetchuL1 {
127                        l1 = l1,
128                        a = a,
129
130                    })
131                },
132            )
133        }
134    }
135
136    impl PtxParser for PrefetchTensormapSpaceTensormap {
137        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
138            try_map(
139                seq_n!(
140                    string_p("prefetch"),
141                    optional(TensormapSpace::parse()),
142                    string_p(".tensormap"),
143                    AddressOperand::parse(),
144                    semicolon_p()
145                ),
146                |(_, tensormap_space, tensormap, a, _), span| {
147                    ok!(PrefetchTensormapSpaceTensormap {
148                        tensormap_space = tensormap_space,
149                        tensormap = tensormap,
150                        a = a,
151
152                    })
153                },
154            )
155        }
156    }
157}