ptx_parser/unparser/instruction/
red.rs

1//! Original PTX specification:
2//!
3//! // Reduction operation with scalar type:
4//! red.op{.space}{.sem}{.scope}{.level::cache_hint}.type          [a], b{, cache-policy};
5//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.f16    [a], b{, cache-policy};
6//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.f16x2  [a], b{, cache-policy};
7//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.bf16   [a], b{, cache-policy};
8//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.bf16x2 [a], b{, cache-policy};
9//! .space =              { .global, .shared, .shared::cta, .shared::cluster};
10//! .sem =                {.relaxed, .release};
11//! .scope =              {.cta, .cluster, .gpu, .sys};
12//! .op =                 { .and, .or, .xor, .add, .inc, .dec, .min, .max };
13//! .level::cache_hint =  { .L2::cache_hint };
14//! .type =               { .b32, .b64, .u32, .u64, .s32, .s64, .f32, .f64 };
15//! ------------------------------------------------------------------
16//! // Reduction operation with vector type:
17//! red.add{.space}{.sem}{.scope}{.level::cache_hint}.vec_32_bit.f32 [a], b{, cache-policy};
18//! red.op{.space}{.sem}{.scope}.noftz{.level::cache_hint}. vec_16_bit.half_word_type [a], b{, cache-policy};
19//! red.op{.space}{.sem}{.scope}.noftz{.level::cache_hint}.vec_32_bit.packed_type [a], b {, cache-policy};
20//! .sem =                { .relaxed, .release };
21//! .scope =              { .cta, .cluster, .gpu, .sys };
22//! .op =                 { .add, .min, .max };
23//! .half_word_type =     { .f16, .bf16 };
24//! .packed_type =        { .f16x2,.bf16x2 };
25//! .vec_16_bit =         { .v2, .v4, .v8 };
26//! .vec_32_bit =         { .v2, .v4 };
27//! .level::cache_hint =  { .L2::cache_hint };
28
29#![allow(unused)]
30
31use crate::lexer::PtxToken;
32use crate::unparser::{PtxUnparser, common::*};
33
34pub mod section_0 {
35    use super::*;
36    use crate::r#type::instruction::red::section_0::*;
37
38    impl PtxUnparser for RedOpSpaceSemScopeLevelCacheHintType {
39        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
40            push_opcode(tokens, "red");
41            match &self.op {
42                Op::And => {
43                    push_directive(tokens, "and");
44                }
45                Op::Xor => {
46                    push_directive(tokens, "xor");
47                }
48                Op::Add => {
49                    push_directive(tokens, "add");
50                }
51                Op::Inc => {
52                    push_directive(tokens, "inc");
53                }
54                Op::Dec => {
55                    push_directive(tokens, "dec");
56                }
57                Op::Min => {
58                    push_directive(tokens, "min");
59                }
60                Op::Max => {
61                    push_directive(tokens, "max");
62                }
63                Op::Or => {
64                    push_directive(tokens, "or");
65                }
66            }
67            if let Some(space_0) = self.space.as_ref() {
68                match space_0 {
69                    Space::SharedCluster => {
70                        push_directive(tokens, "shared::cluster");
71                    }
72                    Space::SharedCta => {
73                        push_directive(tokens, "shared::cta");
74                    }
75                    Space::Global => {
76                        push_directive(tokens, "global");
77                    }
78                    Space::Shared => {
79                        push_directive(tokens, "shared");
80                    }
81                }
82            }
83            if let Some(sem_1) = self.sem.as_ref() {
84                match sem_1 {
85                    Sem::Relaxed => {
86                        push_directive(tokens, "relaxed");
87                    }
88                    Sem::Release => {
89                        push_directive(tokens, "release");
90                    }
91                }
92            }
93            if let Some(scope_2) = self.scope.as_ref() {
94                match scope_2 {
95                    Scope::Cluster => {
96                        push_directive(tokens, "cluster");
97                    }
98                    Scope::Cta => {
99                        push_directive(tokens, "cta");
100                    }
101                    Scope::Gpu => {
102                        push_directive(tokens, "gpu");
103                    }
104                    Scope::Sys => {
105                        push_directive(tokens, "sys");
106                    }
107                }
108            }
109            if let Some(level_cache_hint_3) = self.level_cache_hint.as_ref() {
110                match level_cache_hint_3 {
111                    LevelCacheHint::L2CacheHint => {
112                        push_directive(tokens, "L2::cache_hint");
113                    }
114                }
115            }
116            match &self.type_ {
117                Type::B32 => {
118                    push_directive(tokens, "b32");
119                }
120                Type::B64 => {
121                    push_directive(tokens, "b64");
122                }
123                Type::U32 => {
124                    push_directive(tokens, "u32");
125                }
126                Type::U64 => {
127                    push_directive(tokens, "u64");
128                }
129                Type::S32 => {
130                    push_directive(tokens, "s32");
131                }
132                Type::S64 => {
133                    push_directive(tokens, "s64");
134                }
135                Type::F32 => {
136                    push_directive(tokens, "f32");
137                }
138                Type::F64 => {
139                    push_directive(tokens, "f64");
140                }
141            }
142            self.a.unparse_tokens(tokens);
143            tokens.push(PtxToken::Comma);
144            self.b.unparse_tokens(tokens);
145            if self.cache_policy.is_some() {
146                tokens.push(PtxToken::Comma);
147            }
148            if let Some(opt_4) = self.cache_policy.as_ref() {
149                opt_4.unparse_tokens(tokens);
150            }
151            tokens.push(PtxToken::Semicolon);
152        }
153    }
154
155    impl PtxUnparser for RedAddSpaceSemScopeNoftzLevelCacheHintF16 {
156        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
157            push_opcode(tokens, "red");
158            push_directive(tokens, "add");
159            if let Some(space_5) = self.space.as_ref() {
160                match space_5 {
161                    Space::SharedCluster => {
162                        push_directive(tokens, "shared::cluster");
163                    }
164                    Space::SharedCta => {
165                        push_directive(tokens, "shared::cta");
166                    }
167                    Space::Global => {
168                        push_directive(tokens, "global");
169                    }
170                    Space::Shared => {
171                        push_directive(tokens, "shared");
172                    }
173                }
174            }
175            if let Some(sem_6) = self.sem.as_ref() {
176                match sem_6 {
177                    Sem::Relaxed => {
178                        push_directive(tokens, "relaxed");
179                    }
180                    Sem::Release => {
181                        push_directive(tokens, "release");
182                    }
183                }
184            }
185            if let Some(scope_7) = self.scope.as_ref() {
186                match scope_7 {
187                    Scope::Cluster => {
188                        push_directive(tokens, "cluster");
189                    }
190                    Scope::Cta => {
191                        push_directive(tokens, "cta");
192                    }
193                    Scope::Gpu => {
194                        push_directive(tokens, "gpu");
195                    }
196                    Scope::Sys => {
197                        push_directive(tokens, "sys");
198                    }
199                }
200            }
201            push_directive(tokens, "noftz");
202            if let Some(level_cache_hint_8) = self.level_cache_hint.as_ref() {
203                match level_cache_hint_8 {
204                    LevelCacheHint::L2CacheHint => {
205                        push_directive(tokens, "L2::cache_hint");
206                    }
207                }
208            }
209            push_directive(tokens, "f16");
210            self.a.unparse_tokens(tokens);
211            tokens.push(PtxToken::Comma);
212            self.b.unparse_tokens(tokens);
213            if self.cache_policy.is_some() {
214                tokens.push(PtxToken::Comma);
215            }
216            if let Some(opt_9) = self.cache_policy.as_ref() {
217                opt_9.unparse_tokens(tokens);
218            }
219            tokens.push(PtxToken::Semicolon);
220        }
221    }
222
223    impl PtxUnparser for RedAddSpaceSemScopeNoftzLevelCacheHintF16x2 {
224        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
225            push_opcode(tokens, "red");
226            push_directive(tokens, "add");
227            if let Some(space_10) = self.space.as_ref() {
228                match space_10 {
229                    Space::SharedCluster => {
230                        push_directive(tokens, "shared::cluster");
231                    }
232                    Space::SharedCta => {
233                        push_directive(tokens, "shared::cta");
234                    }
235                    Space::Global => {
236                        push_directive(tokens, "global");
237                    }
238                    Space::Shared => {
239                        push_directive(tokens, "shared");
240                    }
241                }
242            }
243            if let Some(sem_11) = self.sem.as_ref() {
244                match sem_11 {
245                    Sem::Relaxed => {
246                        push_directive(tokens, "relaxed");
247                    }
248                    Sem::Release => {
249                        push_directive(tokens, "release");
250                    }
251                }
252            }
253            if let Some(scope_12) = self.scope.as_ref() {
254                match scope_12 {
255                    Scope::Cluster => {
256                        push_directive(tokens, "cluster");
257                    }
258                    Scope::Cta => {
259                        push_directive(tokens, "cta");
260                    }
261                    Scope::Gpu => {
262                        push_directive(tokens, "gpu");
263                    }
264                    Scope::Sys => {
265                        push_directive(tokens, "sys");
266                    }
267                }
268            }
269            push_directive(tokens, "noftz");
270            if let Some(level_cache_hint_13) = self.level_cache_hint.as_ref() {
271                match level_cache_hint_13 {
272                    LevelCacheHint::L2CacheHint => {
273                        push_directive(tokens, "L2::cache_hint");
274                    }
275                }
276            }
277            push_directive(tokens, "f16x2");
278            self.a.unparse_tokens(tokens);
279            tokens.push(PtxToken::Comma);
280            self.b.unparse_tokens(tokens);
281            if self.cache_policy.is_some() {
282                tokens.push(PtxToken::Comma);
283            }
284            if let Some(opt_14) = self.cache_policy.as_ref() {
285                opt_14.unparse_tokens(tokens);
286            }
287            tokens.push(PtxToken::Semicolon);
288        }
289    }
290
291    impl PtxUnparser for RedAddSpaceSemScopeNoftzLevelCacheHintBf16 {
292        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
293            push_opcode(tokens, "red");
294            push_directive(tokens, "add");
295            if let Some(space_15) = self.space.as_ref() {
296                match space_15 {
297                    Space::SharedCluster => {
298                        push_directive(tokens, "shared::cluster");
299                    }
300                    Space::SharedCta => {
301                        push_directive(tokens, "shared::cta");
302                    }
303                    Space::Global => {
304                        push_directive(tokens, "global");
305                    }
306                    Space::Shared => {
307                        push_directive(tokens, "shared");
308                    }
309                }
310            }
311            if let Some(sem_16) = self.sem.as_ref() {
312                match sem_16 {
313                    Sem::Relaxed => {
314                        push_directive(tokens, "relaxed");
315                    }
316                    Sem::Release => {
317                        push_directive(tokens, "release");
318                    }
319                }
320            }
321            if let Some(scope_17) = self.scope.as_ref() {
322                match scope_17 {
323                    Scope::Cluster => {
324                        push_directive(tokens, "cluster");
325                    }
326                    Scope::Cta => {
327                        push_directive(tokens, "cta");
328                    }
329                    Scope::Gpu => {
330                        push_directive(tokens, "gpu");
331                    }
332                    Scope::Sys => {
333                        push_directive(tokens, "sys");
334                    }
335                }
336            }
337            push_directive(tokens, "noftz");
338            if let Some(level_cache_hint_18) = self.level_cache_hint.as_ref() {
339                match level_cache_hint_18 {
340                    LevelCacheHint::L2CacheHint => {
341                        push_directive(tokens, "L2::cache_hint");
342                    }
343                }
344            }
345            push_directive(tokens, "bf16");
346            self.a.unparse_tokens(tokens);
347            tokens.push(PtxToken::Comma);
348            self.b.unparse_tokens(tokens);
349            if self.cache_policy.is_some() {
350                tokens.push(PtxToken::Comma);
351            }
352            if let Some(opt_19) = self.cache_policy.as_ref() {
353                opt_19.unparse_tokens(tokens);
354            }
355            tokens.push(PtxToken::Semicolon);
356        }
357    }
358
359    impl PtxUnparser for RedAddSpaceSemScopeNoftzLevelCacheHintBf16x2 {
360        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
361            push_opcode(tokens, "red");
362            push_directive(tokens, "add");
363            if let Some(space_20) = self.space.as_ref() {
364                match space_20 {
365                    Space::SharedCluster => {
366                        push_directive(tokens, "shared::cluster");
367                    }
368                    Space::SharedCta => {
369                        push_directive(tokens, "shared::cta");
370                    }
371                    Space::Global => {
372                        push_directive(tokens, "global");
373                    }
374                    Space::Shared => {
375                        push_directive(tokens, "shared");
376                    }
377                }
378            }
379            if let Some(sem_21) = self.sem.as_ref() {
380                match sem_21 {
381                    Sem::Relaxed => {
382                        push_directive(tokens, "relaxed");
383                    }
384                    Sem::Release => {
385                        push_directive(tokens, "release");
386                    }
387                }
388            }
389            if let Some(scope_22) = self.scope.as_ref() {
390                match scope_22 {
391                    Scope::Cluster => {
392                        push_directive(tokens, "cluster");
393                    }
394                    Scope::Cta => {
395                        push_directive(tokens, "cta");
396                    }
397                    Scope::Gpu => {
398                        push_directive(tokens, "gpu");
399                    }
400                    Scope::Sys => {
401                        push_directive(tokens, "sys");
402                    }
403                }
404            }
405            push_directive(tokens, "noftz");
406            if let Some(level_cache_hint_23) = self.level_cache_hint.as_ref() {
407                match level_cache_hint_23 {
408                    LevelCacheHint::L2CacheHint => {
409                        push_directive(tokens, "L2::cache_hint");
410                    }
411                }
412            }
413            push_directive(tokens, "bf16x2");
414            self.a.unparse_tokens(tokens);
415            tokens.push(PtxToken::Comma);
416            self.b.unparse_tokens(tokens);
417            if self.cache_policy.is_some() {
418                tokens.push(PtxToken::Comma);
419            }
420            if let Some(opt_24) = self.cache_policy.as_ref() {
421                opt_24.unparse_tokens(tokens);
422            }
423            tokens.push(PtxToken::Semicolon);
424        }
425    }
426}
427
428pub mod section_1 {
429    use super::*;
430    use crate::r#type::instruction::red::section_1::*;
431
432    impl PtxUnparser for RedAddSpaceSemScopeLevelCacheHintVec32BitF32 {
433        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
434            push_opcode(tokens, "red");
435            push_directive(tokens, "add");
436            if let Some(space_25) = self.space.as_ref() {
437                match space_25 {
438                    Space::SharedCluster => {
439                        push_directive(tokens, "shared::cluster");
440                    }
441                    Space::SharedCta => {
442                        push_directive(tokens, "shared::cta");
443                    }
444                    Space::Global => {
445                        push_directive(tokens, "global");
446                    }
447                    Space::Shared => {
448                        push_directive(tokens, "shared");
449                    }
450                }
451            }
452            if let Some(sem_26) = self.sem.as_ref() {
453                match sem_26 {
454                    Sem::Relaxed => {
455                        push_directive(tokens, "relaxed");
456                    }
457                    Sem::Release => {
458                        push_directive(tokens, "release");
459                    }
460                }
461            }
462            if let Some(scope_27) = self.scope.as_ref() {
463                match scope_27 {
464                    Scope::Cluster => {
465                        push_directive(tokens, "cluster");
466                    }
467                    Scope::Cta => {
468                        push_directive(tokens, "cta");
469                    }
470                    Scope::Gpu => {
471                        push_directive(tokens, "gpu");
472                    }
473                    Scope::Sys => {
474                        push_directive(tokens, "sys");
475                    }
476                }
477            }
478            if let Some(level_cache_hint_28) = self.level_cache_hint.as_ref() {
479                match level_cache_hint_28 {
480                    LevelCacheHint::L2CacheHint => {
481                        push_directive(tokens, "L2::cache_hint");
482                    }
483                }
484            }
485            match &self.vec_32_bit {
486                Vec32Bit::V2 => {
487                    push_directive(tokens, "v2");
488                }
489                Vec32Bit::V4 => {
490                    push_directive(tokens, "v4");
491                }
492            }
493            push_directive(tokens, "f32");
494            self.a.unparse_tokens(tokens);
495            tokens.push(PtxToken::Comma);
496            self.b.unparse_tokens(tokens);
497            if self.cache_policy.is_some() {
498                tokens.push(PtxToken::Comma);
499            }
500            if let Some(opt_29) = self.cache_policy.as_ref() {
501                opt_29.unparse_tokens(tokens);
502            }
503            tokens.push(PtxToken::Semicolon);
504        }
505    }
506
507    impl PtxUnparser for RedOpSpaceSemScopeNoftzLevelCacheHintVec16BitHalfWordType {
508        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
509            push_opcode(tokens, "red");
510            match &self.op {
511                Op::Add => {
512                    push_directive(tokens, "add");
513                }
514                Op::Min => {
515                    push_directive(tokens, "min");
516                }
517                Op::Max => {
518                    push_directive(tokens, "max");
519                }
520            }
521            if let Some(space_30) = self.space.as_ref() {
522                match space_30 {
523                    Space::SharedCluster => {
524                        push_directive(tokens, "shared::cluster");
525                    }
526                    Space::SharedCta => {
527                        push_directive(tokens, "shared::cta");
528                    }
529                    Space::Global => {
530                        push_directive(tokens, "global");
531                    }
532                    Space::Shared => {
533                        push_directive(tokens, "shared");
534                    }
535                }
536            }
537            if let Some(sem_31) = self.sem.as_ref() {
538                match sem_31 {
539                    Sem::Relaxed => {
540                        push_directive(tokens, "relaxed");
541                    }
542                    Sem::Release => {
543                        push_directive(tokens, "release");
544                    }
545                }
546            }
547            if let Some(scope_32) = self.scope.as_ref() {
548                match scope_32 {
549                    Scope::Cluster => {
550                        push_directive(tokens, "cluster");
551                    }
552                    Scope::Cta => {
553                        push_directive(tokens, "cta");
554                    }
555                    Scope::Gpu => {
556                        push_directive(tokens, "gpu");
557                    }
558                    Scope::Sys => {
559                        push_directive(tokens, "sys");
560                    }
561                }
562            }
563            push_directive(tokens, "noftz");
564            if let Some(level_cache_hint_33) = self.level_cache_hint.as_ref() {
565                match level_cache_hint_33 {
566                    LevelCacheHint::L2CacheHint => {
567                        push_directive(tokens, "L2::cache_hint");
568                    }
569                }
570            }
571            match &self.vec_16_bit {
572                Vec16Bit::V2 => {
573                    push_directive(tokens, "v2");
574                }
575                Vec16Bit::V4 => {
576                    push_directive(tokens, "v4");
577                }
578                Vec16Bit::V8 => {
579                    push_directive(tokens, "v8");
580                }
581            }
582            match &self.half_word_type {
583                HalfWordType::Bf16 => {
584                    push_directive(tokens, "bf16");
585                }
586                HalfWordType::F16 => {
587                    push_directive(tokens, "f16");
588                }
589            }
590            self.a.unparse_tokens(tokens);
591            tokens.push(PtxToken::Comma);
592            self.b.unparse_tokens(tokens);
593            if self.cache_policy.is_some() {
594                tokens.push(PtxToken::Comma);
595            }
596            if let Some(opt_34) = self.cache_policy.as_ref() {
597                opt_34.unparse_tokens(tokens);
598            }
599            tokens.push(PtxToken::Semicolon);
600        }
601    }
602
603    impl PtxUnparser for RedOpSpaceSemScopeNoftzLevelCacheHintVec32BitPackedType {
604        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
605            push_opcode(tokens, "red");
606            match &self.op {
607                Op::Add => {
608                    push_directive(tokens, "add");
609                }
610                Op::Min => {
611                    push_directive(tokens, "min");
612                }
613                Op::Max => {
614                    push_directive(tokens, "max");
615                }
616            }
617            if let Some(space_35) = self.space.as_ref() {
618                match space_35 {
619                    Space::SharedCluster => {
620                        push_directive(tokens, "shared::cluster");
621                    }
622                    Space::SharedCta => {
623                        push_directive(tokens, "shared::cta");
624                    }
625                    Space::Global => {
626                        push_directive(tokens, "global");
627                    }
628                    Space::Shared => {
629                        push_directive(tokens, "shared");
630                    }
631                }
632            }
633            if let Some(sem_36) = self.sem.as_ref() {
634                match sem_36 {
635                    Sem::Relaxed => {
636                        push_directive(tokens, "relaxed");
637                    }
638                    Sem::Release => {
639                        push_directive(tokens, "release");
640                    }
641                }
642            }
643            if let Some(scope_37) = self.scope.as_ref() {
644                match scope_37 {
645                    Scope::Cluster => {
646                        push_directive(tokens, "cluster");
647                    }
648                    Scope::Cta => {
649                        push_directive(tokens, "cta");
650                    }
651                    Scope::Gpu => {
652                        push_directive(tokens, "gpu");
653                    }
654                    Scope::Sys => {
655                        push_directive(tokens, "sys");
656                    }
657                }
658            }
659            push_directive(tokens, "noftz");
660            if let Some(level_cache_hint_38) = self.level_cache_hint.as_ref() {
661                match level_cache_hint_38 {
662                    LevelCacheHint::L2CacheHint => {
663                        push_directive(tokens, "L2::cache_hint");
664                    }
665                }
666            }
667            match &self.vec_32_bit {
668                Vec32Bit::V2 => {
669                    push_directive(tokens, "v2");
670                }
671                Vec32Bit::V4 => {
672                    push_directive(tokens, "v4");
673                }
674            }
675            match &self.packed_type {
676                PackedType::Bf16x2 => {
677                    push_directive(tokens, "bf16x2");
678                }
679                PackedType::F16x2 => {
680                    push_directive(tokens, "f16x2");
681                }
682            }
683            self.a.unparse_tokens(tokens);
684            tokens.push(PtxToken::Comma);
685            self.b.unparse_tokens(tokens);
686            if self.cache_policy.is_some() {
687                tokens.push(PtxToken::Comma);
688            }
689            if let Some(opt_39) = self.cache_policy.as_ref() {
690                opt_39.unparse_tokens(tokens);
691            }
692            tokens.push(PtxToken::Semicolon);
693        }
694    }
695}