ptx_parser/parser/instruction/
ld.rs

1//! Original PTX specification:
2//!
3//! ld{.weak}{.ss}{.cop}{.level::cache_hint}{.level::prefetch_size}{.vec}.type  d, [a]{.unified}{, cache-policy};
4//! ld{.weak}{.ss}{.level1::eviction_priority}{.level2::eviction_priority}{.level::cache_hint}{.level::prefetch_size}{.vec}.type  d, [a]{.unified}{, cache-policy};
5//! ld.volatile{.ss}{.level::prefetch_size}{.vec}.type  d, [a];
6//! ld.relaxed.scope{.ss}{.level1::eviction_priority}{.level2::eviction_priority}{.level::cache_hint}{.level::prefetch_size}{.vec}.type  d, [a]{, cache-policy};
7//! ld.acquire.scope{.ss}{.level1::eviction_priority}{.level2::eviction_priority}{.level::cache_hint}{.level::prefetch_size}{.vec}.type  d, [a]{, cache-policy};
8//! ld.mmio.relaxed.sys{.global}.type  d, [a];
9//! .ss =                       { .const, .global, .local, .param::entry, .param::func, .param, .shared, .shared::cta, .shared::cluster};
10//! .cop =                      { .ca, .cg, .cs, .lu, .cv };
11//! .level1::eviction_priority = { .L1::evict_normal, .L1::evict_unchanged, .L1::evict_first, .L1::evict_last, .L1::no_allocate };
12//! .level2::eviction_priority = {.L2::evict_normal, .L2::evict_first, .L2::evict_last};
13//! .level::cache_hint =        { .L2::cache_hint };
14//! .level::prefetch_size =     { .L2::64B, .L2::128B, .L2::256B };
15//! .scope =                    { .cta, .cluster, .gpu, .sys };
16//! .vec =                      { .v2, .v4, .v8 };
17//! .type =                     { .b8, .b16, .b32, .b64, .b128,
18//! .u8, .u16, .u32, .u64,
19//! .s8, .s16, .s32, .s64,
20//! .f32, .f64 };
21
22#![allow(unused)]
23
24use crate::parser::{
25    PtxParseError, PtxParser, PtxTokenStream, Span,
26    util::{
27        between, comma_p, directive_p, exclamation_p, lbracket_p, lparen_p, map, minus_p, optional,
28        pipe_p, rbracket_p, rparen_p, semicolon_p, sep_by, string_p, try_map,
29    },
30};
31use crate::r#type::common::*;
32use crate::{alt, ok, seq_n};
33
34pub mod section_0 {
35    use super::*;
36    use crate::r#type::instruction::ld::section_0::*;
37
38    // ============================================================================
39    // Generated enum parsers
40    // ============================================================================
41
42    impl PtxParser for Cop {
43        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
44            alt!(
45                map(string_p(".ca"), |_, _span| Cop::Ca),
46                map(string_p(".cg"), |_, _span| Cop::Cg),
47                map(string_p(".cs"), |_, _span| Cop::Cs),
48                map(string_p(".lu"), |_, _span| Cop::Lu),
49                map(string_p(".cv"), |_, _span| Cop::Cv)
50            )
51        }
52    }
53
54    impl PtxParser for Level1EvictionPriority {
55        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
56            alt!(
57                map(string_p(".L1::evict_unchanged"), |_, _span| {
58                    Level1EvictionPriority::L1EvictUnchanged
59                }),
60                map(string_p(".L1::evict_normal"), |_, _span| {
61                    Level1EvictionPriority::L1EvictNormal
62                }),
63                map(string_p(".L1::evict_first"), |_, _span| {
64                    Level1EvictionPriority::L1EvictFirst
65                }),
66                map(string_p(".L1::no_allocate"), |_, _span| {
67                    Level1EvictionPriority::L1NoAllocate
68                }),
69                map(string_p(".L1::evict_last"), |_, _span| {
70                    Level1EvictionPriority::L1EvictLast
71                })
72            )
73        }
74    }
75
76    impl PtxParser for Level2EvictionPriority {
77        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
78            alt!(
79                map(string_p(".L2::evict_normal"), |_, _span| {
80                    Level2EvictionPriority::L2EvictNormal
81                }),
82                map(string_p(".L2::evict_first"), |_, _span| {
83                    Level2EvictionPriority::L2EvictFirst
84                }),
85                map(string_p(".L2::evict_last"), |_, _span| {
86                    Level2EvictionPriority::L2EvictLast
87                })
88            )
89        }
90    }
91
92    impl PtxParser for LevelCacheHint {
93        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
94            alt!(map(string_p(".L2::cache_hint"), |_, _span| {
95                LevelCacheHint::L2CacheHint
96            }))
97        }
98    }
99
100    impl PtxParser for LevelPrefetchSize {
101        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
102            alt!(
103                map(string_p(".L2::128B"), |_, _span| LevelPrefetchSize::L2128b),
104                map(string_p(".L2::256B"), |_, _span| LevelPrefetchSize::L2256b),
105                map(string_p(".L2::64B"), |_, _span| LevelPrefetchSize::L264b)
106            )
107        }
108    }
109
110    impl PtxParser for Scope {
111        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
112            alt!(
113                map(string_p(".cluster"), |_, _span| Scope::Cluster),
114                map(string_p(".cta"), |_, _span| Scope::Cta),
115                map(string_p(".gpu"), |_, _span| Scope::Gpu),
116                map(string_p(".sys"), |_, _span| Scope::Sys)
117            )
118        }
119    }
120
121    impl PtxParser for Ss {
122        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
123            alt!(
124                map(string_p(".shared::cluster"), |_, _span| Ss::SharedCluster),
125                map(string_p(".param::entry"), |_, _span| Ss::ParamEntry),
126                map(string_p(".param::func"), |_, _span| Ss::ParamFunc),
127                map(string_p(".shared::cta"), |_, _span| Ss::SharedCta),
128                map(string_p(".global"), |_, _span| Ss::Global),
129                map(string_p(".shared"), |_, _span| Ss::Shared),
130                map(string_p(".const"), |_, _span| Ss::Const),
131                map(string_p(".local"), |_, _span| Ss::Local),
132                map(string_p(".param"), |_, _span| Ss::Param)
133            )
134        }
135    }
136
137    impl PtxParser for Type {
138        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
139            alt!(
140                map(string_p(".b128"), |_, _span| Type::B128),
141                map(string_p(".b16"), |_, _span| Type::B16),
142                map(string_p(".b32"), |_, _span| Type::B32),
143                map(string_p(".b64"), |_, _span| Type::B64),
144                map(string_p(".u16"), |_, _span| Type::U16),
145                map(string_p(".u32"), |_, _span| Type::U32),
146                map(string_p(".u64"), |_, _span| Type::U64),
147                map(string_p(".s16"), |_, _span| Type::S16),
148                map(string_p(".s32"), |_, _span| Type::S32),
149                map(string_p(".s64"), |_, _span| Type::S64),
150                map(string_p(".f32"), |_, _span| Type::F32),
151                map(string_p(".f64"), |_, _span| Type::F64),
152                map(string_p(".b8"), |_, _span| Type::B8),
153                map(string_p(".u8"), |_, _span| Type::U8),
154                map(string_p(".s8"), |_, _span| Type::S8)
155            )
156        }
157    }
158
159    impl PtxParser for Vec {
160        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
161            alt!(
162                map(string_p(".v2"), |_, _span| Vec::V2),
163                map(string_p(".v4"), |_, _span| Vec::V4),
164                map(string_p(".v8"), |_, _span| Vec::V8)
165            )
166        }
167    }
168
169    impl PtxParser for LdWeakSsCopLevelCacheHintLevelPrefetchSizeVecType {
170        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
171            try_map(
172                seq_n!(
173                    string_p("ld"),
174                    map(optional(string_p(".weak")), |value, _| value.is_some()),
175                    optional(Ss::parse()),
176                    optional(Cop::parse()),
177                    optional(LevelCacheHint::parse()),
178                    optional(LevelPrefetchSize::parse()),
179                    optional(Vec::parse()),
180                    Type::parse(),
181                    GeneralOperand::parse(),
182                    comma_p(),
183                    AddressOperand::parse(),
184                    map(optional(string_p(".unified")), |value, _| value.is_some()),
185                    map(
186                        optional(seq_n!(comma_p(), GeneralOperand::parse())),
187                        |value, _| value.map(|(_, operand)| operand)
188                    ),
189                    semicolon_p()
190                ),
191                |(
192                    _,
193                    weak,
194                    ss,
195                    cop,
196                    level_cache_hint,
197                    level_prefetch_size,
198                    vec,
199                    type_,
200                    d,
201                    _,
202                    a,
203                    unified,
204                    cache_policy,
205                    _,
206                ),
207                 span| {
208                    ok!(LdWeakSsCopLevelCacheHintLevelPrefetchSizeVecType {
209                        weak = weak,
210                        ss = ss,
211                        cop = cop,
212                        level_cache_hint = level_cache_hint,
213                        level_prefetch_size = level_prefetch_size,
214                        vec = vec,
215                        type_ = type_,
216                        d = d,
217                        a = a,
218                        unified = unified,
219                        cache_policy = cache_policy,
220
221                    })
222                },
223            )
224        }
225    }
226
227    impl PtxParser for LdWeakSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintLevelPrefetchSizeVecType {
228        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
229            try_map(
230                seq_n!(
231                    string_p("ld"),
232                    map(optional(string_p(".weak")), |value, _| value.is_some()),
233                    optional(Ss::parse()),
234                    optional(Level1EvictionPriority::parse()),
235                    optional(Level2EvictionPriority::parse()),
236                    optional(LevelCacheHint::parse()),
237                    optional(LevelPrefetchSize::parse()),
238                    optional(Vec::parse()),
239                    Type::parse(),
240                    GeneralOperand::parse(),
241                    comma_p(),
242                    AddressOperand::parse(),
243                    map(optional(string_p(".unified")), |value, _| value.is_some()),
244                    map(optional(seq_n!(comma_p(), GeneralOperand::parse())), |value, _| value.map(|(_, operand)| operand)),
245                    semicolon_p()
246                ),
247                |(_, weak, ss, level1_eviction_priority, level2_eviction_priority, level_cache_hint, level_prefetch_size, vec, type_, d, _, a, unified, cache_policy, _), span| {
248                    ok!(LdWeakSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintLevelPrefetchSizeVecType {
249                        weak = weak,
250                        ss = ss,
251                        level1_eviction_priority = level1_eviction_priority,
252                        level2_eviction_priority = level2_eviction_priority,
253                        level_cache_hint = level_cache_hint,
254                        level_prefetch_size = level_prefetch_size,
255                        vec = vec,
256                        type_ = type_,
257                        d = d,
258                        a = a,
259                        unified = unified,
260                        cache_policy = cache_policy,
261
262                    })
263                },
264            )
265        }
266    }
267
268    impl PtxParser for LdVolatileSsLevelPrefetchSizeVecType {
269        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
270            try_map(
271                seq_n!(
272                    string_p("ld"),
273                    string_p(".volatile"),
274                    optional(Ss::parse()),
275                    optional(LevelPrefetchSize::parse()),
276                    optional(Vec::parse()),
277                    Type::parse(),
278                    GeneralOperand::parse(),
279                    comma_p(),
280                    AddressOperand::parse(),
281                    semicolon_p()
282                ),
283                |(_, volatile, ss, level_prefetch_size, vec, type_, d, _, a, _), span| {
284                    ok!(LdVolatileSsLevelPrefetchSizeVecType {
285                        volatile = volatile,
286                        ss = ss,
287                        level_prefetch_size = level_prefetch_size,
288                        vec = vec,
289                        type_ = type_,
290                        d = d,
291                        a = a,
292
293                    })
294                },
295            )
296        }
297    }
298
299    impl PtxParser for LdRelaxedScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintLevelPrefetchSizeVecType {
300        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
301            try_map(
302                seq_n!(
303                    string_p("ld"),
304                    string_p(".relaxed"),
305                    Scope::parse(),
306                    optional(Ss::parse()),
307                    optional(Level1EvictionPriority::parse()),
308                    optional(Level2EvictionPriority::parse()),
309                    optional(LevelCacheHint::parse()),
310                    optional(LevelPrefetchSize::parse()),
311                    optional(Vec::parse()),
312                    Type::parse(),
313                    GeneralOperand::parse(),
314                    comma_p(),
315                    AddressOperand::parse(),
316                    map(optional(seq_n!(comma_p(), GeneralOperand::parse())), |value, _| value.map(|(_, operand)| operand)),
317                    semicolon_p()
318                ),
319                |(_, relaxed, scope, ss, level1_eviction_priority, level2_eviction_priority, level_cache_hint, level_prefetch_size, vec, type_, d, _, a, cache_policy, _), span| {
320                    ok!(LdRelaxedScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintLevelPrefetchSizeVecType {
321                        relaxed = relaxed,
322                        scope = scope,
323                        ss = ss,
324                        level1_eviction_priority = level1_eviction_priority,
325                        level2_eviction_priority = level2_eviction_priority,
326                        level_cache_hint = level_cache_hint,
327                        level_prefetch_size = level_prefetch_size,
328                        vec = vec,
329                        type_ = type_,
330                        d = d,
331                        a = a,
332                        cache_policy = cache_policy,
333
334                    })
335                },
336            )
337        }
338    }
339
340    impl PtxParser for LdAcquireScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintLevelPrefetchSizeVecType {
341        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
342            try_map(
343                seq_n!(
344                    string_p("ld"),
345                    string_p(".acquire"),
346                    Scope::parse(),
347                    optional(Ss::parse()),
348                    optional(Level1EvictionPriority::parse()),
349                    optional(Level2EvictionPriority::parse()),
350                    optional(LevelCacheHint::parse()),
351                    optional(LevelPrefetchSize::parse()),
352                    optional(Vec::parse()),
353                    Type::parse(),
354                    GeneralOperand::parse(),
355                    comma_p(),
356                    AddressOperand::parse(),
357                    map(optional(seq_n!(comma_p(), GeneralOperand::parse())), |value, _| value.map(|(_, operand)| operand)),
358                    semicolon_p()
359                ),
360                |(_, acquire, scope, ss, level1_eviction_priority, level2_eviction_priority, level_cache_hint, level_prefetch_size, vec, type_, d, _, a, cache_policy, _), span| {
361                    ok!(LdAcquireScopeSsLevel1EvictionPriorityLevel2EvictionPriorityLevelCacheHintLevelPrefetchSizeVecType {
362                        acquire = acquire,
363                        scope = scope,
364                        ss = ss,
365                        level1_eviction_priority = level1_eviction_priority,
366                        level2_eviction_priority = level2_eviction_priority,
367                        level_cache_hint = level_cache_hint,
368                        level_prefetch_size = level_prefetch_size,
369                        vec = vec,
370                        type_ = type_,
371                        d = d,
372                        a = a,
373                        cache_policy = cache_policy,
374
375                    })
376                },
377            )
378        }
379    }
380
381    impl PtxParser for LdMmioRelaxedSysGlobalType {
382        fn parse() -> impl Fn(&mut PtxTokenStream) -> Result<(Self, Span), PtxParseError> {
383            try_map(
384                seq_n!(
385                    string_p("ld"),
386                    string_p(".mmio"),
387                    string_p(".relaxed"),
388                    string_p(".sys"),
389                    map(optional(string_p(".global")), |value, _| value.is_some()),
390                    Type::parse(),
391                    GeneralOperand::parse(),
392                    comma_p(),
393                    AddressOperand::parse(),
394                    semicolon_p()
395                ),
396                |(_, mmio, relaxed, sys, global, type_, d, _, a, _), span| {
397                    ok!(LdMmioRelaxedSysGlobalType {
398                        mmio = mmio,
399                        relaxed = relaxed,
400                        sys = sys,
401                        global = global,
402                        type_ = type_,
403                        d = d,
404                        a = a,
405
406                    })
407                },
408            )
409        }
410    }
411}