ptx_parser/unparser/instruction/
vsh.rs

1//! Original PTX specification:
2//!
3//! // 32-bit scalar operation, with optional secondary operation
4//! vop.dtype.atype.u32{.sat}.mode       d, a{.asel}, b{.bsel};
5//! vop.dtype.atype.u32{.sat}.mode.op2   d, a{.asel}, b{.bsel}, c;
6//! // 32-bit scalar operation, with optional data merge
7//! vop.dtype.atype.u32{.sat}.mode  d.dsel, a{.asel}, b{.bsel}, c;
8//! vop   = { vshl, vshr };
9//! .dtype = .atype = { .u32, .s32 };
10//! .mode  = { .clamp, .wrap };
11//! .dsel  = .asel  = .bsel  = { .b0, .b1, .b2, .b3, .h0, .h1 };
12//! .op2   = { .add, .min, .max };
13
14#![allow(unused)]
15
16use crate::lexer::PtxToken;
17use crate::unparser::{PtxUnparser, common::*};
18
19pub mod section_0 {
20    use super::*;
21    use crate::r#type::instruction::vsh::section_0::*;
22
23    impl PtxUnparser for VshlDtypeAtypeU32SatMode {
24        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
25            push_opcode(tokens, "vshl");
26                    match &self.dtype {
27                            Dtype::U32 => {
28                                    push_directive(tokens, "u32");
29                            }
30                            Dtype::S32 => {
31                                    push_directive(tokens, "s32");
32                            }
33                    }
34                    match &self.atype {
35                            Atype::U32 => {
36                                    push_directive(tokens, "u32");
37                            }
38                            Atype::S32 => {
39                                    push_directive(tokens, "s32");
40                            }
41                    }
42                    push_directive(tokens, "u32");
43                    if self.sat {
44                            push_directive(tokens, "sat");
45                    }
46                    match &self.mode {
47                            Mode::Clamp => {
48                                    push_directive(tokens, "clamp");
49                            }
50                            Mode::Wrap => {
51                                    push_directive(tokens, "wrap");
52                            }
53                    }
54                    self.d.unparse_tokens(tokens);
55            tokens.push(PtxToken::Comma);
56                    self.a.unparse_tokens(tokens);
57                    if let Some(asel_0) = self.asel.as_ref() {
58                            match asel_0 {
59                                    Asel::B0 => {
60                                            push_directive(tokens, "b0");
61                                    }
62                                    Asel::B1 => {
63                                            push_directive(tokens, "b1");
64                                    }
65                                    Asel::B2 => {
66                                            push_directive(tokens, "b2");
67                                    }
68                                    Asel::B3 => {
69                                            push_directive(tokens, "b3");
70                                    }
71                                    Asel::H0 => {
72                                            push_directive(tokens, "h0");
73                                    }
74                                    Asel::H1 => {
75                                            push_directive(tokens, "h1");
76                                    }
77                            }
78                    }
79            tokens.push(PtxToken::Comma);
80                    self.b.unparse_tokens(tokens);
81                    if let Some(bsel_1) = self.bsel.as_ref() {
82                            match bsel_1 {
83                                    Bsel::B0 => {
84                                            push_directive(tokens, "b0");
85                                    }
86                                    Bsel::B1 => {
87                                            push_directive(tokens, "b1");
88                                    }
89                                    Bsel::B2 => {
90                                            push_directive(tokens, "b2");
91                                    }
92                                    Bsel::B3 => {
93                                            push_directive(tokens, "b3");
94                                    }
95                                    Bsel::H0 => {
96                                            push_directive(tokens, "h0");
97                                    }
98                                    Bsel::H1 => {
99                                            push_directive(tokens, "h1");
100                                    }
101                            }
102                    }
103            tokens.push(PtxToken::Semicolon);
104        }
105    }
106
107    impl PtxUnparser for VshrDtypeAtypeU32SatMode {
108        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
109            push_opcode(tokens, "vshr");
110                    match &self.dtype {
111                            Dtype::U32 => {
112                                    push_directive(tokens, "u32");
113                            }
114                            Dtype::S32 => {
115                                    push_directive(tokens, "s32");
116                            }
117                    }
118                    match &self.atype {
119                            Atype::U32 => {
120                                    push_directive(tokens, "u32");
121                            }
122                            Atype::S32 => {
123                                    push_directive(tokens, "s32");
124                            }
125                    }
126                    push_directive(tokens, "u32");
127                    if self.sat {
128                            push_directive(tokens, "sat");
129                    }
130                    match &self.mode {
131                            Mode::Clamp => {
132                                    push_directive(tokens, "clamp");
133                            }
134                            Mode::Wrap => {
135                                    push_directive(tokens, "wrap");
136                            }
137                    }
138                    self.d.unparse_tokens(tokens);
139            tokens.push(PtxToken::Comma);
140                    self.a.unparse_tokens(tokens);
141                    if let Some(asel_2) = self.asel.as_ref() {
142                            match asel_2 {
143                                    Asel::B0 => {
144                                            push_directive(tokens, "b0");
145                                    }
146                                    Asel::B1 => {
147                                            push_directive(tokens, "b1");
148                                    }
149                                    Asel::B2 => {
150                                            push_directive(tokens, "b2");
151                                    }
152                                    Asel::B3 => {
153                                            push_directive(tokens, "b3");
154                                    }
155                                    Asel::H0 => {
156                                            push_directive(tokens, "h0");
157                                    }
158                                    Asel::H1 => {
159                                            push_directive(tokens, "h1");
160                                    }
161                            }
162                    }
163            tokens.push(PtxToken::Comma);
164                    self.b.unparse_tokens(tokens);
165                    if let Some(bsel_3) = self.bsel.as_ref() {
166                            match bsel_3 {
167                                    Bsel::B0 => {
168                                            push_directive(tokens, "b0");
169                                    }
170                                    Bsel::B1 => {
171                                            push_directive(tokens, "b1");
172                                    }
173                                    Bsel::B2 => {
174                                            push_directive(tokens, "b2");
175                                    }
176                                    Bsel::B3 => {
177                                            push_directive(tokens, "b3");
178                                    }
179                                    Bsel::H0 => {
180                                            push_directive(tokens, "h0");
181                                    }
182                                    Bsel::H1 => {
183                                            push_directive(tokens, "h1");
184                                    }
185                            }
186                    }
187            tokens.push(PtxToken::Semicolon);
188        }
189    }
190
191    impl PtxUnparser for VshlDtypeAtypeU32SatModeOp2 {
192        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
193            push_opcode(tokens, "vshl");
194                    match &self.dtype {
195                            Dtype::U32 => {
196                                    push_directive(tokens, "u32");
197                            }
198                            Dtype::S32 => {
199                                    push_directive(tokens, "s32");
200                            }
201                    }
202                    match &self.atype {
203                            Atype::U32 => {
204                                    push_directive(tokens, "u32");
205                            }
206                            Atype::S32 => {
207                                    push_directive(tokens, "s32");
208                            }
209                    }
210                    push_directive(tokens, "u32");
211                    if self.sat {
212                            push_directive(tokens, "sat");
213                    }
214                    match &self.mode {
215                            Mode::Clamp => {
216                                    push_directive(tokens, "clamp");
217                            }
218                            Mode::Wrap => {
219                                    push_directive(tokens, "wrap");
220                            }
221                    }
222                    match &self.op2 {
223                            Op2::Add => {
224                                    push_directive(tokens, "add");
225                            }
226                            Op2::Min => {
227                                    push_directive(tokens, "min");
228                            }
229                            Op2::Max => {
230                                    push_directive(tokens, "max");
231                            }
232                    }
233                    self.d.unparse_tokens(tokens);
234            tokens.push(PtxToken::Comma);
235                    self.a.unparse_tokens(tokens);
236                    if let Some(asel_4) = self.asel.as_ref() {
237                            match asel_4 {
238                                    Asel::B0 => {
239                                            push_directive(tokens, "b0");
240                                    }
241                                    Asel::B1 => {
242                                            push_directive(tokens, "b1");
243                                    }
244                                    Asel::B2 => {
245                                            push_directive(tokens, "b2");
246                                    }
247                                    Asel::B3 => {
248                                            push_directive(tokens, "b3");
249                                    }
250                                    Asel::H0 => {
251                                            push_directive(tokens, "h0");
252                                    }
253                                    Asel::H1 => {
254                                            push_directive(tokens, "h1");
255                                    }
256                            }
257                    }
258            tokens.push(PtxToken::Comma);
259                    self.b.unparse_tokens(tokens);
260                    if let Some(bsel_5) = self.bsel.as_ref() {
261                            match bsel_5 {
262                                    Bsel::B0 => {
263                                            push_directive(tokens, "b0");
264                                    }
265                                    Bsel::B1 => {
266                                            push_directive(tokens, "b1");
267                                    }
268                                    Bsel::B2 => {
269                                            push_directive(tokens, "b2");
270                                    }
271                                    Bsel::B3 => {
272                                            push_directive(tokens, "b3");
273                                    }
274                                    Bsel::H0 => {
275                                            push_directive(tokens, "h0");
276                                    }
277                                    Bsel::H1 => {
278                                            push_directive(tokens, "h1");
279                                    }
280                            }
281                    }
282            tokens.push(PtxToken::Comma);
283                    self.c.unparse_tokens(tokens);
284            tokens.push(PtxToken::Semicolon);
285        }
286    }
287
288    impl PtxUnparser for VshrDtypeAtypeU32SatModeOp2 {
289        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
290            push_opcode(tokens, "vshr");
291                    match &self.dtype {
292                            Dtype::U32 => {
293                                    push_directive(tokens, "u32");
294                            }
295                            Dtype::S32 => {
296                                    push_directive(tokens, "s32");
297                            }
298                    }
299                    match &self.atype {
300                            Atype::U32 => {
301                                    push_directive(tokens, "u32");
302                            }
303                            Atype::S32 => {
304                                    push_directive(tokens, "s32");
305                            }
306                    }
307                    push_directive(tokens, "u32");
308                    if self.sat {
309                            push_directive(tokens, "sat");
310                    }
311                    match &self.mode {
312                            Mode::Clamp => {
313                                    push_directive(tokens, "clamp");
314                            }
315                            Mode::Wrap => {
316                                    push_directive(tokens, "wrap");
317                            }
318                    }
319                    match &self.op2 {
320                            Op2::Add => {
321                                    push_directive(tokens, "add");
322                            }
323                            Op2::Min => {
324                                    push_directive(tokens, "min");
325                            }
326                            Op2::Max => {
327                                    push_directive(tokens, "max");
328                            }
329                    }
330                    self.d.unparse_tokens(tokens);
331            tokens.push(PtxToken::Comma);
332                    self.a.unparse_tokens(tokens);
333                    if let Some(asel_6) = self.asel.as_ref() {
334                            match asel_6 {
335                                    Asel::B0 => {
336                                            push_directive(tokens, "b0");
337                                    }
338                                    Asel::B1 => {
339                                            push_directive(tokens, "b1");
340                                    }
341                                    Asel::B2 => {
342                                            push_directive(tokens, "b2");
343                                    }
344                                    Asel::B3 => {
345                                            push_directive(tokens, "b3");
346                                    }
347                                    Asel::H0 => {
348                                            push_directive(tokens, "h0");
349                                    }
350                                    Asel::H1 => {
351                                            push_directive(tokens, "h1");
352                                    }
353                            }
354                    }
355            tokens.push(PtxToken::Comma);
356                    self.b.unparse_tokens(tokens);
357                    if let Some(bsel_7) = self.bsel.as_ref() {
358                            match bsel_7 {
359                                    Bsel::B0 => {
360                                            push_directive(tokens, "b0");
361                                    }
362                                    Bsel::B1 => {
363                                            push_directive(tokens, "b1");
364                                    }
365                                    Bsel::B2 => {
366                                            push_directive(tokens, "b2");
367                                    }
368                                    Bsel::B3 => {
369                                            push_directive(tokens, "b3");
370                                    }
371                                    Bsel::H0 => {
372                                            push_directive(tokens, "h0");
373                                    }
374                                    Bsel::H1 => {
375                                            push_directive(tokens, "h1");
376                                    }
377                            }
378                    }
379            tokens.push(PtxToken::Comma);
380                    self.c.unparse_tokens(tokens);
381            tokens.push(PtxToken::Semicolon);
382        }
383    }
384
385    impl PtxUnparser for VshlDtypeAtypeU32SatMode1 {
386        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
387            push_opcode(tokens, "vshl");
388                    match &self.dtype {
389                            Dtype::U32 => {
390                                    push_directive(tokens, "u32");
391                            }
392                            Dtype::S32 => {
393                                    push_directive(tokens, "s32");
394                            }
395                    }
396                    match &self.atype {
397                            Atype::U32 => {
398                                    push_directive(tokens, "u32");
399                            }
400                            Atype::S32 => {
401                                    push_directive(tokens, "s32");
402                            }
403                    }
404                    push_directive(tokens, "u32");
405                    if self.sat {
406                            push_directive(tokens, "sat");
407                    }
408                    match &self.mode {
409                            Mode::Clamp => {
410                                    push_directive(tokens, "clamp");
411                            }
412                            Mode::Wrap => {
413                                    push_directive(tokens, "wrap");
414                            }
415                    }
416                    self.d.unparse_tokens(tokens);
417                    match &self.dsel {
418                            Dsel::B0 => {
419                                    push_directive(tokens, "b0");
420                            }
421                            Dsel::B1 => {
422                                    push_directive(tokens, "b1");
423                            }
424                            Dsel::B2 => {
425                                    push_directive(tokens, "b2");
426                            }
427                            Dsel::B3 => {
428                                    push_directive(tokens, "b3");
429                            }
430                            Dsel::H0 => {
431                                    push_directive(tokens, "h0");
432                            }
433                            Dsel::H1 => {
434                                    push_directive(tokens, "h1");
435                            }
436                    }
437            tokens.push(PtxToken::Comma);
438                    self.a.unparse_tokens(tokens);
439                    if let Some(asel_8) = self.asel.as_ref() {
440                            match asel_8 {
441                                    Asel::B0 => {
442                                            push_directive(tokens, "b0");
443                                    }
444                                    Asel::B1 => {
445                                            push_directive(tokens, "b1");
446                                    }
447                                    Asel::B2 => {
448                                            push_directive(tokens, "b2");
449                                    }
450                                    Asel::B3 => {
451                                            push_directive(tokens, "b3");
452                                    }
453                                    Asel::H0 => {
454                                            push_directive(tokens, "h0");
455                                    }
456                                    Asel::H1 => {
457                                            push_directive(tokens, "h1");
458                                    }
459                            }
460                    }
461            tokens.push(PtxToken::Comma);
462                    self.b.unparse_tokens(tokens);
463                    if let Some(bsel_9) = self.bsel.as_ref() {
464                            match bsel_9 {
465                                    Bsel::B0 => {
466                                            push_directive(tokens, "b0");
467                                    }
468                                    Bsel::B1 => {
469                                            push_directive(tokens, "b1");
470                                    }
471                                    Bsel::B2 => {
472                                            push_directive(tokens, "b2");
473                                    }
474                                    Bsel::B3 => {
475                                            push_directive(tokens, "b3");
476                                    }
477                                    Bsel::H0 => {
478                                            push_directive(tokens, "h0");
479                                    }
480                                    Bsel::H1 => {
481                                            push_directive(tokens, "h1");
482                                    }
483                            }
484                    }
485            tokens.push(PtxToken::Comma);
486                    self.c.unparse_tokens(tokens);
487            tokens.push(PtxToken::Semicolon);
488        }
489    }
490
491    impl PtxUnparser for VshrDtypeAtypeU32SatMode1 {
492        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
493            push_opcode(tokens, "vshr");
494                    match &self.dtype {
495                            Dtype::U32 => {
496                                    push_directive(tokens, "u32");
497                            }
498                            Dtype::S32 => {
499                                    push_directive(tokens, "s32");
500                            }
501                    }
502                    match &self.atype {
503                            Atype::U32 => {
504                                    push_directive(tokens, "u32");
505                            }
506                            Atype::S32 => {
507                                    push_directive(tokens, "s32");
508                            }
509                    }
510                    push_directive(tokens, "u32");
511                    if self.sat {
512                            push_directive(tokens, "sat");
513                    }
514                    match &self.mode {
515                            Mode::Clamp => {
516                                    push_directive(tokens, "clamp");
517                            }
518                            Mode::Wrap => {
519                                    push_directive(tokens, "wrap");
520                            }
521                    }
522                    self.d.unparse_tokens(tokens);
523                    match &self.dsel {
524                            Dsel::B0 => {
525                                    push_directive(tokens, "b0");
526                            }
527                            Dsel::B1 => {
528                                    push_directive(tokens, "b1");
529                            }
530                            Dsel::B2 => {
531                                    push_directive(tokens, "b2");
532                            }
533                            Dsel::B3 => {
534                                    push_directive(tokens, "b3");
535                            }
536                            Dsel::H0 => {
537                                    push_directive(tokens, "h0");
538                            }
539                            Dsel::H1 => {
540                                    push_directive(tokens, "h1");
541                            }
542                    }
543            tokens.push(PtxToken::Comma);
544                    self.a.unparse_tokens(tokens);
545                    if let Some(asel_10) = self.asel.as_ref() {
546                            match asel_10 {
547                                    Asel::B0 => {
548                                            push_directive(tokens, "b0");
549                                    }
550                                    Asel::B1 => {
551                                            push_directive(tokens, "b1");
552                                    }
553                                    Asel::B2 => {
554                                            push_directive(tokens, "b2");
555                                    }
556                                    Asel::B3 => {
557                                            push_directive(tokens, "b3");
558                                    }
559                                    Asel::H0 => {
560                                            push_directive(tokens, "h0");
561                                    }
562                                    Asel::H1 => {
563                                            push_directive(tokens, "h1");
564                                    }
565                            }
566                    }
567            tokens.push(PtxToken::Comma);
568                    self.b.unparse_tokens(tokens);
569                    if let Some(bsel_11) = self.bsel.as_ref() {
570                            match bsel_11 {
571                                    Bsel::B0 => {
572                                            push_directive(tokens, "b0");
573                                    }
574                                    Bsel::B1 => {
575                                            push_directive(tokens, "b1");
576                                    }
577                                    Bsel::B2 => {
578                                            push_directive(tokens, "b2");
579                                    }
580                                    Bsel::B3 => {
581                                            push_directive(tokens, "b3");
582                                    }
583                                    Bsel::H0 => {
584                                            push_directive(tokens, "h0");
585                                    }
586                                    Bsel::H1 => {
587                                            push_directive(tokens, "h1");
588                                    }
589                            }
590                    }
591            tokens.push(PtxToken::Comma);
592                    self.c.unparse_tokens(tokens);
593            tokens.push(PtxToken::Semicolon);
594        }
595    }
596
597}
598