xref: /aosp_15_r20/external/mesa3d/src/imagination/rogue/rogue_isa.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © 2022 Imagination Technologies Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef ROGUE_ISA_H
25 #define ROGUE_ISA_H
26 
27 /**
28  * \file rogue_isa.h
29  *
30  * \brief Contains hardware ISA definitions and encodings.
31  */
32 
33 /* Source/destination encodings. */
34 
35 /* Internal source selector. */
36 typedef struct rogue_iss_encoding {
37    unsigned is1 : 1;
38    unsigned is2 : 1;
39    unsigned is3 : 2;
40    unsigned is4 : 2;
41    unsigned is5 : 2;
42 } PACKED rogue_iss_encoding;
43 static_assert(sizeof(rogue_iss_encoding) == 1,
44               "sizeof(rogue_iss_encoding) != 1");
45 
46 typedef struct rogue_dbN {
47    union {
48       struct {
49          unsigned _0 : 1;
50          unsigned _2_1 : 2;
51          unsigned : 5;
52       } PACKED;
53 
54       uint8_t _;
55    } PACKED;
56 } PACKED rogue_dbN;
57 static_assert(sizeof(rogue_dbN) == 1, "sizeof(rogue_dbN) != 1");
58 
59 typedef struct rogue_dN {
60    union {
61       struct {
62          unsigned _5_0 : 6;
63          unsigned _7_6 : 2;
64          unsigned _10_8 : 3;
65          unsigned : 5;
66       } PACKED;
67 
68       uint8_t _;
69    } PACKED;
70 } PACKED rogue_dN;
71 static_assert(sizeof(rogue_dN) == 2, "sizeof(rogue_dN) != 2");
72 
73 typedef struct rogue_db0 {
74    union {
75       struct {
76          unsigned _0 : 1;
77          unsigned _2_1 : 2;
78          unsigned : 5;
79       } PACKED;
80 
81       uint8_t _;
82    } PACKED;
83 } PACKED rogue_db0;
84 static_assert(sizeof(rogue_db0) == 1, "sizeof(rogue_db0) != 1");
85 
86 typedef struct rogue_db1 {
87    union {
88       struct {
89          unsigned _0 : 1;
90          unsigned _2_1 : 2;
91          unsigned : 5;
92       } PACKED;
93 
94       uint8_t _;
95    } PACKED;
96 } PACKED rogue_db1;
97 static_assert(sizeof(rogue_db0) == 1, "sizeof(rogue_db0) != 1");
98 
99 typedef struct rogue_d0 {
100    union {
101       struct {
102          unsigned _6_0 : 7;
103          unsigned _7 : 1;
104          unsigned _10_8 : 3;
105          unsigned : 5;
106       } PACKED;
107 
108       uint16_t _;
109    } PACKED;
110 } PACKED rogue_d0;
111 static_assert(sizeof(rogue_d0) == 2, "sizeof(rogue_d0) != 2");
112 
113 typedef struct rogue_d1 {
114    union {
115       struct {
116          unsigned _5_0 : 6;
117          unsigned _7_6 : 2;
118          unsigned _10_8 : 3;
119          unsigned : 5;
120       } PACKED;
121 
122       uint16_t _;
123    } PACKED;
124 } PACKED rogue_d1;
125 static_assert(sizeof(rogue_d1) == 2, "sizeof(rogue_d1) != 2");
126 
127 typedef struct rogue_dest_map_encoding {
128    /* Byte 0 */
129    union {
130       struct {
131          unsigned dN_5_0 : 6;
132          unsigned dbN_0 : 1;
133          unsigned ext0 : 1;
134       } PACKED;
135 
136       struct {
137          unsigned d0_6_0 : 7;
138          unsigned db0_0 : 1;
139       } PACKED;
140    };
141 
142    /* Byte 1 */
143    union {
144       struct {
145          unsigned dN_7_6 : 2;
146          unsigned dbN_2_1 : 2;
147          unsigned dN_10_8 : 3;
148          unsigned rsvd1 : 1;
149       } PACKED;
150 
151       struct {
152          unsigned d1_5_0 : 6;
153          unsigned db1_0 : 1;
154          unsigned ext1 : 1;
155       } PACKED;
156    };
157 
158    /* Byte 2 */
159    struct {
160       unsigned d0_7 : 1;
161       unsigned db0_2_1 : 2;
162       unsigned d1_7_6 : 2;
163       unsigned db1_2_1 : 2;
164       unsigned ext2 : 1;
165    } PACKED;
166 
167    /* Byte 3 */
168    struct {
169       unsigned d0_10_8 : 3;
170       unsigned d1_10_8 : 3;
171       unsigned rsvd3 : 2;
172    } PACKED;
173 } PACKED rogue_dest_map_encoding;
174 static_assert(sizeof(rogue_dest_map_encoding) == 4,
175               "sizeof(rogue_dest_map_encoding) != 4");
176 
177 /****************/
178 
179 typedef struct rogue_source_map_encoding {
180    /* Byte 0 */
181    struct {
182       unsigned sA_5_0 : 6;
183       unsigned sbA_0 : 1;
184       unsigned ext0 : 1;
185    } PACKED;
186 
187    /* Byte 1 */
188    union {
189       struct {
190          unsigned sA_7_6 : 2;
191          unsigned sbA_2_1 : 2;
192          unsigned mux_1_0 : 2;
193          unsigned : 2;
194       } PACKED sA_1;
195 
196       struct {
197          unsigned sB_4_0 : 5;
198          unsigned sbB_0 : 1;
199          unsigned ext1 : 1;
200          unsigned sel : 1;
201       } PACKED;
202    } PACKED;
203 
204    /* Byte 2 */
205    union {
206       /* Common def. */
207       struct sA_sC_10_8 {
208          unsigned sA_10_8 : 3;
209          unsigned sC_10_8 : 3;
210          unsigned rsvd5 : 2;
211       } PACKED sA_2;
212 
213       struct {
214          unsigned sB_6_5 : 2;
215          unsigned sA_6 : 1;
216          unsigned sbB_1 : 1;
217          unsigned sbA_1 : 1;
218          unsigned mux_1_0 : 2;
219          unsigned ext2 : 1;
220       } PACKED;
221 
222       struct {
223          unsigned : 3;
224          unsigned rsvd2 : 5;
225       } PACKED;
226    } PACKED;
227 
228    /* Byte 3 */
229    union {
230       /* Common def. */
231       struct sB_sC_mux2 {
232          union {
233             struct {
234                unsigned sB_7 : 1;
235                unsigned sA_7 : 1;
236                unsigned rsvd3 : 1;
237                unsigned sbA_2 : 1;
238                unsigned mux_2 : 1;
239                unsigned sA_10_8 : 3;
240             } PACKED;
241 
242             struct {
243                unsigned : 2;
244                unsigned ext4 : 1;
245                unsigned : 2;
246                unsigned sC_7_6 : 2;
247                unsigned sbC_2 : 1;
248             } PACKED;
249          } PACKED;
250       } PACKED sB_3;
251 
252       struct {
253          unsigned sC_5_0 : 6;
254          unsigned sbC_1_0 : 2;
255       } PACKED;
256    } PACKED;
257 
258    /* Byte 4 */
259    struct sB_sC_mux2 sC_4;
260 
261    /* Byte 5 */
262    struct sA_sC_10_8 sC_5;
263 } PACKED rogue_source_map_encoding;
264 static_assert(sizeof(rogue_source_map_encoding) == 6,
265               "sizeof(rogue_source_map_encoding) == 6");
266 
267 typedef struct rogue_sbA {
268    union {
269       struct {
270          unsigned _0 : 1;
271          unsigned _2_1 : 2;
272          unsigned : 5;
273       } PACKED;
274 
275       struct {
276          unsigned : 1;
277          unsigned _1 : 1;
278          unsigned _2 : 1;
279          unsigned : 5;
280       } PACKED;
281 
282       uint8_t _;
283    } PACKED;
284 } PACKED rogue_sbA;
285 static_assert(sizeof(rogue_sbA) == 1, "sizeof(rogue_sbA) != 1");
286 
287 typedef struct rogue_sA {
288    union {
289       struct {
290          unsigned _5_0 : 6;
291          unsigned _7_6 : 2;
292          unsigned _10_8 : 3;
293          unsigned : 5;
294       } PACKED;
295 
296       struct {
297          unsigned : 6;
298          unsigned _6 : 1;
299          unsigned _7 : 1;
300          unsigned : 8;
301       } PACKED;
302 
303       uint16_t _;
304    } PACKED;
305 } PACKED rogue_sA;
306 static_assert(sizeof(rogue_sA) == 2, "sizeof(rogue_sA) != 2");
307 
308 typedef struct rogue_sbB {
309    union {
310       struct {
311          unsigned _0 : 1;
312          unsigned _1 : 1;
313          unsigned : 6;
314       } PACKED;
315 
316       uint8_t _;
317    } PACKED;
318 } PACKED rogue_sbB;
319 static_assert(sizeof(rogue_sbB) == 1, "sizeof(rogue_sbB) != 1");
320 
321 typedef struct rogue_sB {
322    union {
323       struct {
324          unsigned _4_0 : 5;
325          unsigned _6_5 : 2;
326          unsigned _7 : 1;
327          unsigned : 8;
328       } PACKED;
329 
330       uint16_t _;
331    } PACKED;
332 } PACKED rogue_sB;
333 static_assert(sizeof(rogue_sB) == 2, "sizeof(rogue_sB) != 2");
334 
335 typedef struct rogue_sbC {
336    union {
337       struct {
338          unsigned _1_0 : 2;
339          unsigned _2 : 1;
340          unsigned : 5;
341       } PACKED;
342 
343       uint8_t _;
344    } PACKED;
345 } PACKED rogue_sbC;
346 static_assert(sizeof(rogue_sbC) == 1, "sizeof(rogue_sbC) != 1");
347 
348 typedef struct rogue_sC {
349    union {
350       struct {
351          unsigned _5_0 : 6;
352          unsigned _7_6 : 2;
353          unsigned _10_8 : 3;
354          unsigned : 5;
355       } PACKED;
356 
357       uint16_t _;
358    } PACKED;
359 } PACKED rogue_sC;
360 static_assert(sizeof(rogue_sC) == 2, "sizeof(rogue_sC) != 2");
361 
362 typedef struct rogue_mux {
363    union {
364       struct {
365          unsigned _1_0 : 2;
366          unsigned _2 : 1;
367          unsigned : 5;
368       } PACKED;
369 
370       uint8_t _;
371    } PACKED;
372 } PACKED rogue_mux;
373 static_assert(sizeof(rogue_mux) == 1, "sizeof(rogue_mux) != 1");
374 
375 typedef struct rogue_idx_offset {
376    union {
377       struct {
378          unsigned bank : 3;
379          unsigned offset : 8;
380          unsigned : 5;
381       } PACKED;
382 
383       uint16_t _;
384    } PACKED;
385 } PACKED rogue_idx_offset;
386 static_assert(sizeof(rogue_idx_offset) == 2, "sizeof(rogue_idx_offset) != 2");
387 
388 typedef struct rogue_idx_dim_offset {
389    union {
390       struct {
391          unsigned bank : 3;
392          unsigned dim_offset : 5;
393          unsigned : 8;
394       } PACKED;
395 
396       uint16_t _;
397    } PACKED;
398 } PACKED rogue_idx_dim_offset;
399 static_assert(sizeof(rogue_idx_dim_offset) == 2,
400               "sizeof(rogue_idx_dim_offset) != 2");
401 
402 enum reg_bank {
403    BANK_SPECIAL = 0b000,
404    BANK_TEMP = 0b001,
405    BANK_VTXIN = 0b010,
406    BANK_COEFF = 0b011,
407    BANK_SHARED = 0b100,
408    BANK_COEFF_ALT = 0b101,
409    BANK_IDX0 = 0b110,
410    BANK_IDX1 = 0b111,
411 };
412 
413 enum idx_bank {
414    IDX_BANK_TEMP = 0b000,
415    IDX_BANK_VTXIN = 0b001,
416    IDX_BANK_COEFF = 0b010,
417    IDX_BANK_SHARED = 0b011,
418    IDX_BANK_DC = 0b100,
419    IDX_BANK_IDX = 0b101,
420    IDX_BANK_COEFF_ALT = 0b110,
421    IDX_BANK_PIXOUT = 0b111,
422 };
423 
424 enum is0 {
425    IS0_S0 = 0b000,
426    IS0_S3 = 0b001,
427    IS0_S4 = 0b010,
428    IS0_S5 = 0b011,
429    IS0_S1 = 0b100,
430    IS0_S2 = 0b101,
431 };
432 
433 enum is1 {
434    IS1_FT0 = 0b0,
435    IS1_FTE = 0b1,
436 };
437 
438 enum is2 {
439    IS2_FT1 = 0b0,
440    IS2_FTE = 0b1,
441 };
442 
443 enum is3 {
444    IS3_FT0 = 0b00,
445    IS3_FT1 = 0b01,
446    IS3_S2 = 0b10,
447    IS3_FTE = 0b11,
448 };
449 
450 enum is4 {
451    IS4_FT0 = 0b00,
452    IS4_FT1 = 0b01,
453    IS4_FT2 = 0b10,
454    IS4_FTE = 0b11,
455 };
456 
457 enum is5 {
458    IS5_FT0 = 0b00,
459    IS5_FT1 = 0b01,
460    IS5_FT2 = 0b10,
461    IS5_FTE = 0b11,
462 };
463 
464 /* Single source instructions. */
465 
466 typedef struct rogue_single_pck_encoding {
467    /* Byte 1 */
468    union {
469       struct {
470          union {
471             struct {
472                unsigned format : 5;
473                unsigned scale : 1;
474                unsigned elem : 2;
475             } PACKED;
476 
477             struct {
478                unsigned : 5;
479                unsigned rtz : 1;
480                unsigned : 2;
481             } PACKED;
482          } PACKED;
483       } PACKED upck;
484 
485       struct {
486          unsigned format : 5;
487          unsigned scale : 1;
488          unsigned rtz : 1;
489          unsigned prog : 1;
490       } PACKED pck;
491    } PACKED;
492 } PACKED rogue_single_pck_encoding;
493 static_assert(sizeof(rogue_single_pck_encoding) == 1,
494               "sizeof(rogue_single_pck_encoding) != 1");
495 
496 enum pck_fmt {
497    PCK_FMT_U8888 = 0b00000,
498    PCK_FMT_S8888 = 0b00001,
499    PCK_FMT_O8888 = 0b00010,
500    PCK_FMT_U1616 = 0b00011,
501    PCK_FMT_S1616 = 0b00100,
502    PCK_FMT_O1616 = 0b00101,
503    PCK_FMT_U32 = 0b00110,
504    PCK_FMT_S32 = 0b00111,
505    PCK_FMT_U1010102 = 0b01000,
506    PCK_FMT_S1010102 = 0b01001,
507    PCK_FMT_U111110 = 0b01010,
508    PCK_FMT_S111110 = 0b01011,
509    PCK_FMT_F111110 = 0b01100,
510    PCK_FMT_F16F16 = 0b01110,
511    PCK_FMT_F32 = 0b01111,
512    PCK_FMT_COV = 0b10000,
513    PCK_FMT_U565U565 = 0b10001,
514    PCK_FMT_D24S8 = 0b10010,
515    PCK_FMT_S8D24 = 0b10011,
516    PCK_FMT_F32_MASK = 0b10100,
517    PCK_FMT_2F10F10F10 = 0b10101,
518    PCK_FMT_S8888OGL = 0b10110,
519    PCK_FMT_S1616OGL = 0b10111,
520    PCK_FMT_ZERO = 0b11110,
521    PCK_FMT_ONE = 0b11111,
522 };
523 
524 typedef struct rogue_single_mbyp_encoding {
525    /* Byte 1 */
526    struct {
527       unsigned s0abs : 1;
528       unsigned s0neg : 1;
529       unsigned : 6;
530    } PACKED;
531 } PACKED rogue_single_mbyp_encoding;
532 static_assert(sizeof(rogue_single_mbyp_encoding) == 1,
533               "sizeof(rogue_single_mbyp_encoding) != 1");
534 
535 enum snglop {
536    SNGLOP_RCP = 0b0000,
537    SNGLOP_RSQ = 0b0001,
538    SNGLOP_LOG = 0b0010,
539    SNGLOP_EXP = 0b0011,
540    SNGLOP_F16SOP = 0b0100,
541    SNGLOP_LOGCN = 0b0101,
542    SNGLOP_GAMMA = 0b0110,
543    SNGLOP_BYP = 0b0111,
544    SNGLOP_DSX = 0b1000,
545    SNGLOP_DSY = 0b1001,
546    SNGLOP_DSXF = 0b1010,
547    SNGLOP_DSYF = 0b1011,
548    SNGLOP_PCK = 0b1100,
549    SNGLOP_RED = 0b1101,
550    SNGLOP_SINC = 0b1110,
551    SNGLOP_ARCTANC = 0b1111,
552 };
553 
554 typedef struct rogue_alu_single_encoding {
555    /* Byte 0 */
556    struct {
557       unsigned snglop : 4;
558       unsigned ext0 : 1;
559       unsigned : 3;
560    } PACKED;
561 
562    /* Byte 1+ */
563    union {
564       rogue_single_mbyp_encoding mbyp;
565       rogue_single_pck_encoding pck;
566    } PACKED;
567 } PACKED rogue_alu_single_encoding;
568 static_assert(sizeof(rogue_alu_single_encoding) == 2,
569               "sizeof(rogue_alu_single_encoding) != 2");
570 
571 typedef struct rogue_alu_fmad_encoding {
572    /* Byte 0 */
573    struct {
574       unsigned sat : 1;
575       unsigned s2neg : 1;
576       unsigned s0abs : 1;
577       unsigned s0neg : 1;
578       unsigned ext : 1;
579       unsigned : 3;
580    } PACKED;
581 
582    /* Byte 1 */
583    struct {
584       unsigned s2abs : 1;
585       unsigned s2flr : 1;
586       unsigned s1neg : 1;
587       unsigned s1abs : 1;
588       unsigned lp : 1;
589       unsigned : 3;
590    } PACKED;
591 } PACKED rogue_alu_fmad_encoding;
592 static_assert(sizeof(rogue_alu_fmad_encoding) == 2,
593               "sizeof(rogue_alu_fmad_encoding) != 2");
594 
595 typedef struct rogue_alu_fdual_encoding {
596    /* Byte 0 */
597    struct {
598       unsigned s0flr : 1;
599       unsigned s1abs : 1;
600       unsigned s0abs : 1;
601       unsigned s0neg : 1;
602       unsigned sat : 1;
603       unsigned lp : 1;
604       unsigned : 2;
605    } PACKED;
606 } PACKED rogue_alu_fdual_encoding;
607 static_assert(sizeof(rogue_alu_fdual_encoding) == 1,
608               "sizeof(rogue_alu_fdual_encoding) != 1");
609 
610 typedef struct rogue_alu_tst_encoding {
611    /* Byte 0 */
612    struct {
613       unsigned pwen : 1;
614       unsigned tstop_2_0 : 3;
615       unsigned ext : 1;
616       unsigned : 3;
617    } PACKED;
618 
619    /* Byte 1 */
620    struct {
621       unsigned tstop_3 : 1;
622       unsigned : 1;
623       unsigned elem : 2;
624       unsigned p2end : 1;
625       unsigned type : 3;
626    } PACKED;
627 } PACKED rogue_alu_tst_encoding;
628 static_assert(sizeof(rogue_alu_tst_encoding) == 2,
629               "sizeof(rogue_alu_tst_encoding) != 2");
630 
631 typedef struct rogue_tstop {
632    union {
633       struct {
634          unsigned _2_0 : 3;
635          unsigned _3 : 1;
636          unsigned : 4;
637       } PACKED;
638 
639       uint8_t _;
640    } PACKED;
641 } PACKED rogue_tstop;
642 static_assert(sizeof(rogue_tstop) == 1, "sizeof(rogue_tstop) != 1");
643 
644 enum tstop {
645    TSTOP_Z = 0b0000,
646    TSTOP_GZ = 0b0001,
647    TSTOP_GEZ = 0b0010,
648    TSTOP_C = 0b0011,
649    TSTOP_E = 0b0100,
650    TSTOP_G = 0b0101,
651    TSTOP_GE = 0b0110,
652    TSTOP_NE = 0b0111,
653    TSTOP_L = 0b1000,
654    TSTOP_LE = 0b1001,
655 };
656 
657 enum tsttype {
658    TSTTYPE_F32 = 0b000,
659    TSTTYPE_U16 = 0b001,
660    TSTTYPE_S16 = 0b010,
661    TSTTYPE_U8 = 0b011,
662    TSTTYPE_S8 = 0b100,
663    TSTTYPE_U32 = 0b101,
664    TSTTYPE_S32 = 0b110,
665 };
666 
667 enum tstelem {
668    TST_E0 = 0b00,
669    TST_E1 = 0b01,
670    TST_E2 = 0b10,
671    TST_E3 = 0b11,
672 };
673 
674 typedef struct rogue_alu_movc_encoding {
675    /* Byte 0 */
676    struct {
677       unsigned movw0 : 2;
678       unsigned movw1 : 2;
679       unsigned ext : 1;
680       unsigned : 3;
681    } PACKED;
682 
683    /* Byte 1 */
684    struct {
685       unsigned p2end : 1;
686       unsigned aw : 1;
687       unsigned maskw0 : 4;
688       unsigned : 2;
689    } PACKED;
690 } PACKED rogue_alu_movc_encoding;
691 static_assert(sizeof(rogue_alu_movc_encoding) == 2,
692               "sizeof(rogue_alu_movc_encoding) != 2");
693 
694 enum movw {
695    MOVW_FT0 = 0b00,
696    MOVW_FT1 = 0b01,
697    MOVW_FT2 = 0b10,
698    MOVW_FTE = 0b11,
699 };
700 
701 enum maskw0 {
702    MASKW0_E0 = 0b0001,
703    MASKW0_E1 = 0b0010,
704    MASKW0_E2 = 0b0100,
705    MASKW0_E3 = 0b1000,
706    MASKW0_EALL = 0b1111,
707 };
708 
709 typedef struct rogue_alu_int32_64_encoding {
710    /* Byte 0 */
711    struct {
712       unsigned int32_64_op : 2;
713       unsigned s2neg : 1;
714       unsigned s : 1;
715       unsigned ext : 1;
716       unsigned : 3;
717    } PACKED;
718 
719    /* Byte 1 */
720    struct {
721       unsigned s2abs : 1;
722       unsigned s1abs : 1;
723       unsigned s0abs : 1;
724       unsigned : 1;
725       unsigned s0neg : 1;
726       unsigned s1neg : 1;
727       unsigned cin : 1;
728       unsigned : 1;
729    } PACKED;
730 } PACKED rogue_alu_int32_64_encoding;
731 static_assert(sizeof(rogue_alu_int32_64_encoding) == 2,
732               "sizeof(rogue_alu_int32_64_encoding) != 2");
733 
734 enum int32_64_op {
735    INT32_64_OP_ADD6432 = 0b00,
736    /* No multiply or extension, only valid when s=0. */
737    INT32_64_OP_ADD64_NMX = 0b01,
738    INT32_64_OP_MADD32 = 0b10,
739    INT32_64_OP_MADD64 = 0b11,
740 };
741 typedef struct rogue_alu_instr_encoding {
742    union {
743       /* Byte 0 */
744       struct {
745          unsigned : 5;
746          unsigned op : 3;
747       } PACKED;
748 
749       /* Bytes 1+ */
750       rogue_alu_single_encoding sngl;
751       rogue_alu_fdual_encoding fadd;
752       rogue_alu_fdual_encoding fmul;
753       rogue_alu_fmad_encoding fmad;
754       rogue_alu_tst_encoding tst;
755       rogue_alu_movc_encoding movc;
756       rogue_alu_int32_64_encoding int32_64;
757    } PACKED;
758 } PACKED rogue_alu_instr_encoding;
759 static_assert(sizeof(rogue_alu_instr_encoding) == 2,
760               "sizeof(rogue_alu_instr_encoding) != 2");
761 
762 enum aluop {
763    ALUOP_FADD = 0b000, /** Phase 0, 1. */
764    ALUOP_FMUL = 0b010, /** Phase 0, 1. */
765    ALUOP_SNGL = 0b100, /** Phase 0, 1, 2. */
766    ALUOP_INT8_16 = 0b101, /** Phase 0. */
767    ALUOP_FMAD = 0b110, /** Phase 0, 1. */
768    ALUOP_MOVC = 0b110, /** Phase 2. */
769    ALUOP_INT32_64 = 0b111, /** Phase 0. */
770    ALUOP_TST = 0b111, /** Phase 2. */
771 };
772 
773 /* Backend instructions. */
774 
775 typedef struct rogue_backend_emitpix_encoding {
776    /* Byte 0 */
777    struct {
778       unsigned : 1;
779       unsigned freep : 1;
780       unsigned : 6;
781    } PACKED;
782 } PACKED rogue_backend_emitpix_encoding;
783 static_assert(sizeof(rogue_backend_emitpix_encoding) == 1,
784               "sizeof(rogue_backend_emitpix_encoding) != 1");
785 
786 typedef struct rogue_backend_fitr_encoding {
787    /* Byte 0 */
788    struct {
789       unsigned mode : 2;
790       unsigned : 1;
791       unsigned drc : 1;
792       unsigned p : 1;
793       unsigned : 3;
794    } PACKED;
795 
796    /* Byte 1 */
797    struct {
798       unsigned count : 4;
799       unsigned sat : 1;
800       unsigned : 3;
801    } PACKED;
802 } PACKED rogue_backend_fitr_encoding;
803 static_assert(sizeof(rogue_backend_fitr_encoding) == 2,
804               "sizeof(rogue_backend_fitr_encoding) != 2");
805 
806 enum fitr_mode {
807    FITR_MODE_PIXEL = 0b00,
808    FITR_MODE_SAMPLE = 0b01,
809    FITR_MODE_CENTROID = 0b10,
810 };
811 
812 typedef struct rogue_backend_uvsw_encoding {
813    /* Byte 0 */
814    struct {
815       unsigned writeop : 3;
816       unsigned imm : 1;
817       unsigned dsel : 1;
818       unsigned : 3;
819    } PACKED;
820 
821    /* Byte 1 */
822    union {
823       struct {
824          unsigned srcsel : 3;
825          unsigned : 5;
826       } PACKED src;
827 
828       struct {
829          unsigned imm_addr : 8;
830       } PACKED imm_src;
831 
832       struct {
833          unsigned streamid : 2;
834          unsigned : 6;
835       } PACKED stream_src;
836    } PACKED;
837 } PACKED rogue_backend_uvsw_encoding;
838 static_assert(sizeof(rogue_backend_uvsw_encoding) == 2,
839               "sizeof(rogue_backend_uvsw_encoding) != 2");
840 
841 enum uvsw_writeop {
842    UVSW_WRITEOP_WRITE = 0b000,
843    UVSW_WRITEOP_EMIT = 0b001,
844    UVSW_WRITEOP_CUT = 0b010,
845    UVSW_WRITEOP_EMIT_CUT = 0b011,
846    UVSW_WRITEOP_END = 0b100,
847    UVSW_WRITEOP_EMIT_END = 0b101,
848    UVSW_WRITEOP_WRITE_EMIT_END = 0b110,
849 };
850 
851 typedef struct rogue_burstlen {
852    union {
853       struct {
854          unsigned _2_0 : 3;
855          unsigned _3 : 1;
856          unsigned : 4;
857       } PACKED;
858 
859       uint8_t _;
860    } PACKED;
861 } PACKED rogue_burstlen;
862 static_assert(sizeof(rogue_burstlen) == 1, "sizeof(rogue_burstlen) != 1");
863 
864 typedef struct rogue_backend_dma_ld_encoding {
865    /* Byte 0 */
866    struct {
867       unsigned : 3;
868       unsigned drc : 1;
869       unsigned ext : 1;
870       unsigned : 3;
871    } PACKED;
872 
873    /* Byte 1 */
874    union {
875       struct {
876          unsigned cachemode : 2;
877          unsigned burstlen_2_0 : 3;
878          unsigned srcseladd : 3;
879       } PACKED;
880 
881       struct {
882          unsigned : 2;
883          unsigned srcselbl : 3;
884          unsigned : 3;
885       } PACKED;
886    } PACKED;
887 
888    /* Byte 2 */
889    struct {
890       unsigned burstlen_3 : 1;
891       unsigned slccachemode : 2;
892       unsigned notimmbl : 1; /* N.B. default is 1 if ext = 0. */
893       unsigned : 4;
894    } PACKED;
895 } PACKED rogue_backend_dma_ld_encoding;
896 static_assert(sizeof(rogue_backend_dma_ld_encoding) == 3,
897               "sizeof(rogue_backend_dma_ld_encoding) != 3");
898 
899 enum cachemode_ld {
900    CACHEMODE_LD_NORMAL = 0b00,
901    CACHEMODE_LD_BYPASS = 0b01,
902    CACHEMODE_LD_FORCE_LINE_FILL = 0b10,
903 };
904 
905 typedef struct rogue_backend_dma_st_encoding {
906    /* Byte 0 */
907    struct {
908       unsigned : 3;
909       unsigned drc : 1;
910       unsigned immbl : 1;
911       unsigned : 3;
912    } PACKED;
913 
914    /* Byte 1 */
915    union {
916       struct {
917          unsigned cachemode : 2;
918          unsigned burstlen_2_0 : 3;
919          unsigned srcseladd : 3;
920       } PACKED;
921 
922       struct {
923          unsigned : 2;
924          unsigned srcselbl : 3;
925          unsigned : 3;
926       } PACKED;
927    } PACKED;
928 
929    /* Byte 2 */
930    struct {
931       unsigned burstlen_3 : 1;
932       unsigned : 1;
933       unsigned dsize : 2;
934       unsigned srcseldata : 3;
935       unsigned ext : 1;
936    } PACKED;
937 
938    /* Byte 3 */
939    struct {
940       unsigned srcmask : 3;
941       unsigned slccachemode : 2;
942       unsigned nottiled : 1; /* N.B. default is 1 if ext = 0. */
943       unsigned : 2;
944    } PACKED;
945 } PACKED rogue_backend_dma_st_encoding;
946 static_assert(sizeof(rogue_backend_dma_st_encoding) == 4,
947               "sizeof(rogue_backend_dma_st_encoding) != 4");
948 
949 enum dsize {
950    DSIZE_8 = 0b00,
951    DSIZE_16 = 0b01,
952    DSIZE_BURSTLEN = 0b10,
953 };
954 
955 enum cachemode_st {
956    CACHEMODE_ST_WRITE_THROUGH = 0b00,
957    CACHEMODE_ST_WRITE_BACK = 0b01,
958    CACHEMODE_ST_WRITE_BACK_LAZY = 0b10,
959 };
960 
961 enum slccachemode {
962    SLCCACHEMODE_BYPASS = 0b00,
963    SLCCACHEMODE_WRITE_BACK = 0b01,
964    SLCCACHEMODE_WRITE_THROUGH = 0b10,
965    SLCCACHEMODE_CACHED_READS = 0b11,
966 };
967 
968 typedef struct rogue_backend_dma_smp_encoding {
969    /* Byte 0 */
970    struct {
971       unsigned : 3;
972       unsigned drc : 1;
973       unsigned fcnorm : 1;
974       unsigned : 3;
975    } PACKED;
976 
977    /* Byte 1 */
978    struct {
979       unsigned lodm : 2;
980       unsigned chan : 2;
981       unsigned exta : 1;
982       unsigned dmn : 2;
983       unsigned extb : 1;
984    } PACKED;
985 
986    /* Byte 2 */
987    struct {
988       unsigned tao : 1;
989       unsigned soo : 1;
990       unsigned sno : 1;
991       unsigned nncoords : 1;
992       unsigned sbmode : 2;
993       unsigned proj : 1;
994       unsigned pplod : 1;
995    } PACKED;
996 
997    /* Byte 3 */
998    struct {
999       unsigned w : 1;
1000       unsigned cachemode : 2;
1001       unsigned swap : 1;
1002       unsigned f16 : 1;
1003       unsigned slccachemode : 2;
1004       unsigned extc : 1;
1005    } PACKED;
1006 
1007    /* Byte 4 */
1008    struct {
1009       unsigned array : 1;
1010       unsigned : 7;
1011    } PACKED;
1012 } PACKED rogue_backend_dma_smp_encoding;
1013 static_assert(sizeof(rogue_backend_dma_smp_encoding) == 5,
1014               "sizeof(rogue_backend_dma_smp_encoding) != 5");
1015 
1016 enum fcnorm {
1017    FCNORM_INT_NOCONVFP = 0,
1018    FCNORM_FIXED_CONVFP = 1,
1019 };
1020 
1021 enum lodm {
1022    LODM_NORMAL = 0b00,
1023    LODM_BIAS = 0b01,
1024    LODM_REPLACE = 0b10,
1025    LODM_GRADIENTS = 0b11,
1026 };
1027 
1028 enum smpchan {
1029    SMPCHAN_1 = 0b00,
1030    SMPCHAN_2 = 0b01,
1031    SMPCHAN_3 = 0b10,
1032    SMPCHAN_4 = 0b11,
1033 };
1034 
1035 enum dmn {
1036    DMN_1D = 0b01,
1037    DMN_2D = 0b10,
1038    DMN_3D = 0b11,
1039 };
1040 
1041 enum sbmode {
1042    SBMODE_NONE = 0b00,
1043    SBMODE_DATA = 0b01,
1044    SBMODE_INFO = 0b10,
1045    SBMODE_BOTH = 0b11,
1046 };
1047 
1048 typedef struct rogue_backend_dma_idf_encoding {
1049    /* Byte 0 */
1050    struct {
1051       unsigned : 3;
1052       unsigned drc : 1;
1053       unsigned : 4;
1054    } PACKED;
1055 
1056    /* Byte 1 */
1057    struct {
1058       unsigned srcseladd : 3;
1059       unsigned : 5;
1060    } PACKED;
1061 } PACKED rogue_backend_dma_idf_encoding;
1062 static_assert(sizeof(rogue_backend_dma_idf_encoding) == 2,
1063               "sizeof(rogue_backend_dma_idf_encoding) != 2");
1064 
1065 typedef struct rogue_backend_dma_encoding {
1066    union {
1067       /* Byte 0 */
1068       struct {
1069          unsigned dmaop : 3;
1070          unsigned : 5;
1071       } PACKED;
1072 
1073       rogue_backend_dma_smp_encoding smp;
1074       rogue_backend_dma_idf_encoding idf;
1075       rogue_backend_dma_ld_encoding ld;
1076       rogue_backend_dma_st_encoding st;
1077    } PACKED;
1078 } PACKED rogue_backend_dma_encoding;
1079 static_assert(sizeof(rogue_backend_dma_encoding) == 5,
1080               "sizeof(rogue_backend_dma_encoding) != 5");
1081 
1082 enum dmaop {
1083    DMAOP_IDF = 0b000,
1084    DMAOP_LD = 0b001,
1085    DMAOP_ST = 0b010,
1086    DMAOP_SMP = 0b100,
1087    DMAOP_ATOMIC = 0b101,
1088 };
1089 
1090 typedef struct rogue_backend_instr_encoding {
1091    union {
1092       /* Byte 0 */
1093       struct {
1094          unsigned : 5;
1095          unsigned op : 3;
1096       } PACKED;
1097 
1098       rogue_backend_uvsw_encoding uvsw;
1099       rogue_backend_fitr_encoding fitr;
1100       rogue_backend_emitpix_encoding emitpix;
1101       rogue_backend_dma_encoding dma;
1102    } PACKED;
1103 } PACKED rogue_backend_instr_encoding;
1104 static_assert(sizeof(rogue_backend_instr_encoding) == 5,
1105               "sizeof(rogue_backend_instr_encoding) != 5");
1106 
1107 enum backendop {
1108    BACKENDOP_UVSW = 0b000,
1109    BACKENDOP_MSK = 0b001,
1110    BACKENDOP_PHAS = 0b010,
1111    BACKENDOP_SETL = 0b011,
1112    BACKENDOP_VISTEST = 0b100,
1113    BACKENDOP_FITR = 0b101,
1114    BACKENDOP_EMIT = 0b110,
1115    BACKENDOP_DMA = 0b111,
1116 };
1117 
1118 /* Branch */
1119 typedef struct rogue_ctrl_ba_encoding {
1120    /* Byte 0 */
1121    struct {
1122       unsigned : 1;
1123       unsigned abs : 1;
1124       unsigned allp : 1;
1125       unsigned anyp : 1;
1126       unsigned link : 1;
1127       unsigned : 3;
1128    } PACKED;
1129 
1130    /* Byte 1 */
1131    struct {
1132       unsigned : 1;
1133       unsigned offset_7_1 : 7;
1134    } PACKED;
1135 
1136    /* Byte 2 */
1137    struct {
1138       unsigned offset_15_8 : 8;
1139    } PACKED;
1140 
1141    /* Byte 3 */
1142    struct {
1143       unsigned offset_23_16 : 8;
1144    } PACKED;
1145 
1146    /* Byte 4 */
1147    struct {
1148       unsigned offset_31_24 : 8;
1149    } PACKED;
1150 } PACKED rogue_ctrl_ba_encoding;
1151 static_assert(sizeof(rogue_ctrl_ba_encoding) == 5,
1152               "sizeof(rogue_ctrl_ba_encoding) != 5");
1153 
1154 typedef struct rogue_offset32 {
1155    union {
1156       struct {
1157          struct {
1158             unsigned : 1;
1159             unsigned _7_1 : 7;
1160          } PACKED;
1161 
1162          struct {
1163             unsigned _15_8 : 8;
1164          } PACKED;
1165 
1166          struct {
1167             unsigned _23_16 : 8;
1168          } PACKED;
1169 
1170          struct {
1171             unsigned _31_24 : 8;
1172          } PACKED;
1173       } PACKED;
1174 
1175       uint32_t _;
1176    } PACKED;
1177 } PACKED rogue_offset32;
1178 static_assert(sizeof(rogue_offset32) == 4, "sizeof(rogue_offset32) != 4");
1179 
1180 /* NOP */
1181 typedef struct rogue_ctrl_nop_encoding {
1182    /* Byte 0 */
1183    struct {
1184       unsigned : 8;
1185    } PACKED;
1186 } PACKED rogue_ctrl_nop_encoding;
1187 static_assert(sizeof(rogue_ctrl_nop_encoding) == 1,
1188               "sizeof(rogue_ctrl_nop_encoding) != 1");
1189 
1190 /* Common for all control instructions. */
1191 typedef struct rogue_ctrl_instr_encoding {
1192    union {
1193       /* Bytes 0+ */
1194       rogue_ctrl_ba_encoding ba;
1195       rogue_ctrl_nop_encoding nop;
1196    } PACKED;
1197 } PACKED rogue_ctrl_instr_encoding;
1198 static_assert(sizeof(rogue_ctrl_instr_encoding) == 5,
1199               "sizeof(rogue_ctrl_instr_encoding) != 5");
1200 
1201 enum ctrlop {
1202    CTRLOP_BA = 0b0000,
1203    CTRLOP_LAPC = 0b0001,
1204    CTRLOP_SAVL = 0b0010,
1205    CTRLOP_CND = 0b0011,
1206    CTRLOP_WOP = 0b0100,
1207    CTRLOP_WDF = 0b0101,
1208    CTRLOP_MUTEX = 0b0110,
1209    CTRLOP_NOP = 0b0111,
1210    CTRLOP_ITRSMP = 0b1000,
1211    CTRLOP_UNIQ = 0b1001,
1212    CTRLOP_FETCH = 0b1010,
1213    CTRLOP_SBO = 0b1011,
1214 };
1215 
1216 /* Bitwise phase 0: logical */
1217 typedef struct rogue_bitwise_ph0_encoding {
1218    /* Byte 0 */
1219    struct {
1220       unsigned bm : 1;
1221       unsigned cnt_byp : 1;
1222       unsigned shft : 2;
1223       unsigned ext : 1;
1224       unsigned cnt : 1;
1225       unsigned csrc : 1;
1226       unsigned : 1;
1227    } PACKED;
1228 
1229    /* Byte 1 */
1230    struct {
1231       unsigned imm_7_0 : 8;
1232    } PACKED;
1233 
1234    /* Byte 2 */
1235    struct {
1236       unsigned imm_15_8 : 8;
1237    } PACKED;
1238 
1239    /* Byte 3 */
1240    struct {
1241       unsigned imm_23_16 : 8;
1242    } PACKED;
1243 
1244    /* Byte 4 */
1245    struct {
1246       unsigned imm_31_24 : 8;
1247    } PACKED;
1248 } PACKED rogue_bitwise_ph0_encoding;
1249 static_assert(sizeof(rogue_bitwise_ph0_encoding) == 5,
1250               "sizeof(rogue_bitwise_ph0_encoding) != 5");
1251 
1252 enum shft1 {
1253    SHFT1_BYP = 0b00,
1254    SHFT1_SHFL = 0b01,
1255    SHFT1_REV = 0b10,
1256    SHFT1_LSL = 0b11,
1257 };
1258 
1259 enum cnt {
1260    CNT_CBS = 0b0,
1261    CNT_FTB = 0b1,
1262 };
1263 
1264 enum csrc {
1265    CNT_S2 = 0b0,
1266    CNT_FT2 = 0b1,
1267 };
1268 
1269 typedef struct rogue_imm32 {
1270    union {
1271       struct {
1272          struct {
1273             unsigned _7_0 : 8;
1274          } PACKED;
1275 
1276          struct {
1277             unsigned _15_8 : 8;
1278          } PACKED;
1279 
1280          struct {
1281             unsigned _23_16 : 8;
1282          } PACKED;
1283 
1284          struct {
1285             unsigned _31_24 : 8;
1286          } PACKED;
1287       } PACKED;
1288 
1289       uint32_t _;
1290    } PACKED;
1291 } PACKED rogue_imm32;
1292 static_assert(sizeof(rogue_imm32) == 4, "sizeof(rogue_imm32) != 4");
1293 
1294 /* Bitwise phase 1: logical */
1295 typedef struct rogue_bitwise_ph1_encoding {
1296    /* Byte 0 */
1297    struct {
1298       unsigned op : 3;
1299       unsigned mska : 1;
1300       unsigned : 1;
1301       unsigned mskb : 1;
1302       unsigned : 2;
1303    } PACKED;
1304 } PACKED rogue_bitwise_ph1_encoding;
1305 static_assert(sizeof(rogue_bitwise_ph1_encoding) == 1,
1306               "sizeof(rogue_bitwise_ph1_encoding) != 1");
1307 
1308 enum ph1op {
1309    PH1OP_OR = 0b000,
1310    PH1OP_AND = 0b001,
1311    PH1OP_XOR = 0b010,
1312    PH1OP_NOR = 0b100,
1313    PH1OP_NAND = 0b101,
1314    PH1OP_XNOR = 0b110,
1315    PH1OP_BYP = 0b111,
1316 };
1317 
1318 /* Bitwise phase 2: shift2/test */
1319 typedef struct rogue_bitwise_ph2_encoding {
1320    /* Byte 0 */
1321    struct {
1322       unsigned shft : 3;
1323       unsigned top : 1;
1324       unsigned tsrc : 1;
1325       unsigned pwen : 1;
1326       unsigned : 2;
1327    } PACKED;
1328 } PACKED rogue_bitwise_ph2_encoding;
1329 static_assert(sizeof(rogue_bitwise_ph2_encoding) == 1,
1330               "sizeof(rogue_bitwise_ph2_encoding) != 1");
1331 
1332 enum shft2 {
1333    SHFT2_LSL = 0b000,
1334    SHFT2_SHR = 0b001,
1335    SHFT2_ROL = 0b010,
1336    SHFT2_CPS = 0b011,
1337    SHFT2_ASR_TWB = 0b100,
1338    SHFT2_ASR_PWB = 0b101,
1339    SHFT2_ASR_MTB = 0b110,
1340    SHFT2_ASR_FTB = 0b111,
1341 };
1342 
1343 enum top {
1344    TOP_TZ = 0b0,
1345    TOP_TNZ = 0b1,
1346 };
1347 
1348 enum tsrc {
1349    TSRC_FT5 = 0b0,
1350    TSRC_FT3 = 0b1,
1351 };
1352 
1353 /* Common for all bitwise instructions. */
1354 typedef struct rogue_bitwise_instr_encoding {
1355    union {
1356       /* Bytes 0+ */
1357       struct {
1358          unsigned : 6;
1359          unsigned phase1 : 1;
1360          unsigned phase0 : 1;
1361       } PACKED;
1362 
1363       rogue_bitwise_ph0_encoding ph0;
1364       rogue_bitwise_ph1_encoding ph1;
1365       rogue_bitwise_ph2_encoding ph2;
1366    } PACKED;
1367 } PACKED rogue_bitwise_instr_encoding;
1368 static_assert(sizeof(rogue_bitwise_instr_encoding) == 5,
1369               "sizeof(rogue_bitwise_instr_encoding) != 5");
1370 
1371 typedef struct rogue_instr_group_header_encoding {
1372    /* Byte 0 */
1373    struct {
1374       unsigned length : 4;
1375       unsigned da : 4;
1376    } PACKED;
1377 
1378    /* Byte 1 */
1379    union {
1380       struct {
1381          unsigned cc : 1;
1382          unsigned w0p : 1;
1383          unsigned w1p : 1;
1384          unsigned olchk : 1;
1385          unsigned oporg : 3;
1386          unsigned ext : 1;
1387       } PACKED;
1388 
1389       struct {
1390          unsigned : 4;
1391          unsigned opcnt : 3;
1392          unsigned : 1;
1393       } PACKED;
1394    } PACKED;
1395 
1396    /* Byte 2 */
1397    union {
1398       struct {
1399          unsigned ccext : 1;
1400          unsigned rpt : 2;
1401          unsigned atom : 1;
1402          unsigned : 1;
1403          unsigned alutype : 2;
1404          unsigned end : 1;
1405       } PACKED;
1406 
1407       struct {
1408          unsigned : 1;
1409          unsigned ctrlop : 4;
1410          unsigned : 2;
1411          unsigned miscctl : 1;
1412       } PACKED;
1413    } PACKED;
1414 } PACKED rogue_instr_group_header_encoding;
1415 static_assert(sizeof(rogue_instr_group_header_encoding) == 3,
1416               "sizeof(rogue_instr_group_header_encoding) != 3");
1417 
1418 enum oporg {
1419    OPORG_P0 = 0b000,
1420    OPORG_P2 = 0b001,
1421    OPORG_BE = 0b010,
1422    OPORG_P0_P1 = 0b011,
1423    OPORG_P0_P2 = 0b100,
1424    OPORG_P0_P1_P2 = 0b101,
1425    OPORG_P0_P2_BE = 0b110,
1426    OPORG_P0_P1_P2_BE = 0b111,
1427 };
1428 
1429 enum opcnt {
1430    OPCNT_P0 = 0b001,
1431    OPCNT_P1 = 0b010,
1432    OPCNT_P2 = 0b100,
1433 };
1434 
1435 enum alutype {
1436    ALUTYPE_MAIN = 0b00,
1437    ALUTYPE_BITWISE = 0b10,
1438    ALUTYPE_CONTROL = 0b11,
1439 };
1440 
1441 enum cc {
1442    CC_PE_TRUE = 0b00,
1443    CC_P0_TRUE = 0b01,
1444    CC_PE_ANY = 0b10,
1445    CC_P0_FALSE = 0b11,
1446 };
1447 
1448 typedef struct rogue_cc {
1449    union {
1450       struct {
1451          unsigned cc : 1;
1452          unsigned ccext : 1;
1453          unsigned : 6;
1454       } PACKED;
1455 
1456       uint8_t _;
1457    } PACKED;
1458 } PACKED rogue_cc;
1459 static_assert(sizeof(rogue_cc) == 1, "sizeof(rogue_cc) != 1");
1460 
1461 #endif /* ROGUE_ISA_H */
1462