2 * Copyright (c) 2013 Rob Clark <robdclark@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
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
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
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE 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
27 #define PACKED __attribute__((__packed__))
32 /* size of largest OPC field of all the instruction categories: */
35 #define _OPC(cat, opc) (((cat) << NOPC_BITS) | opc)
41 OPC_JUMP
= _OPC(0, 2),
42 OPC_CALL
= _OPC(0, 3),
44 OPC_KILL
= _OPC(0, 5),
46 OPC_EMIT
= _OPC(0, 7),
48 OPC_CHMASK
= _OPC(0, 9),
49 OPC_CHSH
= _OPC(0, 10),
50 OPC_FLOW_REV
= _OPC(0, 11),
56 OPC_ADD_F
= _OPC(2, 0),
57 OPC_MIN_F
= _OPC(2, 1),
58 OPC_MAX_F
= _OPC(2, 2),
59 OPC_MUL_F
= _OPC(2, 3),
60 OPC_SIGN_F
= _OPC(2, 4),
61 OPC_CMPS_F
= _OPC(2, 5),
62 OPC_ABSNEG_F
= _OPC(2, 6),
63 OPC_CMPV_F
= _OPC(2, 7),
65 OPC_FLOOR_F
= _OPC(2, 9),
66 OPC_CEIL_F
= _OPC(2, 10),
67 OPC_RNDNE_F
= _OPC(2, 11),
68 OPC_RNDAZ_F
= _OPC(2, 12),
69 OPC_TRUNC_F
= _OPC(2, 13),
71 OPC_ADD_U
= _OPC(2, 16),
72 OPC_ADD_S
= _OPC(2, 17),
73 OPC_SUB_U
= _OPC(2, 18),
74 OPC_SUB_S
= _OPC(2, 19),
75 OPC_CMPS_U
= _OPC(2, 20),
76 OPC_CMPS_S
= _OPC(2, 21),
77 OPC_MIN_U
= _OPC(2, 22),
78 OPC_MIN_S
= _OPC(2, 23),
79 OPC_MAX_U
= _OPC(2, 24),
80 OPC_MAX_S
= _OPC(2, 25),
81 OPC_ABSNEG_S
= _OPC(2, 26),
83 OPC_AND_B
= _OPC(2, 28),
84 OPC_OR_B
= _OPC(2, 29),
85 OPC_NOT_B
= _OPC(2, 30),
86 OPC_XOR_B
= _OPC(2, 31),
88 OPC_CMPV_U
= _OPC(2, 33),
89 OPC_CMPV_S
= _OPC(2, 34),
91 OPC_MUL_U
= _OPC(2, 48),
92 OPC_MUL_S
= _OPC(2, 49),
93 OPC_MULL_U
= _OPC(2, 50),
94 OPC_BFREV_B
= _OPC(2, 51),
95 OPC_CLZ_S
= _OPC(2, 52),
96 OPC_CLZ_B
= _OPC(2, 53),
97 OPC_SHL_B
= _OPC(2, 54),
98 OPC_SHR_B
= _OPC(2, 55),
99 OPC_ASHR_B
= _OPC(2, 56),
100 OPC_BARY_F
= _OPC(2, 57),
101 OPC_MGEN_B
= _OPC(2, 58),
102 OPC_GETBIT_B
= _OPC(2, 59),
103 OPC_SETRM
= _OPC(2, 60),
104 OPC_CBITS_B
= _OPC(2, 61),
105 OPC_SHB
= _OPC(2, 62),
106 OPC_MSAD
= _OPC(2, 63),
109 OPC_MAD_U16
= _OPC(3, 0),
110 OPC_MADSH_U16
= _OPC(3, 1),
111 OPC_MAD_S16
= _OPC(3, 2),
112 OPC_MADSH_M16
= _OPC(3, 3), /* should this be .s16? */
113 OPC_MAD_U24
= _OPC(3, 4),
114 OPC_MAD_S24
= _OPC(3, 5),
115 OPC_MAD_F16
= _OPC(3, 6),
116 OPC_MAD_F32
= _OPC(3, 7),
117 OPC_SEL_B16
= _OPC(3, 8),
118 OPC_SEL_B32
= _OPC(3, 9),
119 OPC_SEL_S16
= _OPC(3, 10),
120 OPC_SEL_S32
= _OPC(3, 11),
121 OPC_SEL_F16
= _OPC(3, 12),
122 OPC_SEL_F32
= _OPC(3, 13),
123 OPC_SAD_S16
= _OPC(3, 14),
124 OPC_SAD_S32
= _OPC(3, 15),
127 OPC_RCP
= _OPC(4, 0),
128 OPC_RSQ
= _OPC(4, 1),
129 OPC_LOG2
= _OPC(4, 2),
130 OPC_EXP2
= _OPC(4, 3),
131 OPC_SIN
= _OPC(4, 4),
132 OPC_COS
= _OPC(4, 5),
133 OPC_SQRT
= _OPC(4, 6),
137 OPC_ISAM
= _OPC(5, 0),
138 OPC_ISAML
= _OPC(5, 1),
139 OPC_ISAMM
= _OPC(5, 2),
140 OPC_SAM
= _OPC(5, 3),
141 OPC_SAMB
= _OPC(5, 4),
142 OPC_SAML
= _OPC(5, 5),
143 OPC_SAMGQ
= _OPC(5, 6),
144 OPC_GETLOD
= _OPC(5, 7),
145 OPC_CONV
= _OPC(5, 8),
146 OPC_CONVM
= _OPC(5, 9),
147 OPC_GETSIZE
= _OPC(5, 10),
148 OPC_GETBUF
= _OPC(5, 11),
149 OPC_GETPOS
= _OPC(5, 12),
150 OPC_GETINFO
= _OPC(5, 13),
151 OPC_DSX
= _OPC(5, 14),
152 OPC_DSY
= _OPC(5, 15),
153 OPC_GATHER4R
= _OPC(5, 16),
154 OPC_GATHER4G
= _OPC(5, 17),
155 OPC_GATHER4B
= _OPC(5, 18),
156 OPC_GATHER4A
= _OPC(5, 19),
157 OPC_SAMGP0
= _OPC(5, 20),
158 OPC_SAMGP1
= _OPC(5, 21),
159 OPC_SAMGP2
= _OPC(5, 22),
160 OPC_SAMGP3
= _OPC(5, 23),
161 OPC_DSXPP_1
= _OPC(5, 24),
162 OPC_DSYPP_1
= _OPC(5, 25),
163 OPC_RGETPOS
= _OPC(5, 26),
164 OPC_RGETINFO
= _OPC(5, 27),
167 OPC_LDG
= _OPC(6, 0), /* load-global */
168 OPC_LDL
= _OPC(6, 1),
169 OPC_LDP
= _OPC(6, 2),
170 OPC_STG
= _OPC(6, 3), /* store-global */
171 OPC_STL
= _OPC(6, 4),
172 OPC_STP
= _OPC(6, 5),
173 OPC_STI
= _OPC(6, 6),
174 OPC_G2L
= _OPC(6, 7),
175 OPC_L2G
= _OPC(6, 8),
176 OPC_PREFETCH
= _OPC(6, 9),
177 OPC_LDLW
= _OPC(6, 10),
178 OPC_STLW
= _OPC(6, 11),
179 OPC_RESFMT
= _OPC(6, 14),
180 OPC_RESINFO
= _OPC(6, 15),
181 OPC_ATOMIC_ADD
= _OPC(6, 16),
182 OPC_ATOMIC_SUB
= _OPC(6, 17),
183 OPC_ATOMIC_XCHG
= _OPC(6, 18),
184 OPC_ATOMIC_INC
= _OPC(6, 19),
185 OPC_ATOMIC_DEC
= _OPC(6, 20),
186 OPC_ATOMIC_CMPXCHG
= _OPC(6, 21),
187 OPC_ATOMIC_MIN
= _OPC(6, 22),
188 OPC_ATOMIC_MAX
= _OPC(6, 23),
189 OPC_ATOMIC_AND
= _OPC(6, 24),
190 OPC_ATOMIC_OR
= _OPC(6, 25),
191 OPC_ATOMIC_XOR
= _OPC(6, 26),
192 OPC_LDGB_TYPED_4D
= _OPC(6, 27),
193 OPC_STGB_4D_4
= _OPC(6, 28),
194 OPC_STIB
= _OPC(6, 29),
195 OPC_LDC_4
= _OPC(6, 30),
196 OPC_LDLV
= _OPC(6, 31),
198 /* meta instructions (category -1): */
199 /* placeholder instr to mark shader inputs: */
200 OPC_META_INPUT
= _OPC(-1, 0),
201 OPC_META_PHI
= _OPC(-1, 1),
202 /* The "fan-in" and "fan-out" instructions are used for keeping
203 * track of instructions that write to multiple dst registers
204 * (fan-out) like texture sample instructions, or read multiple
205 * consecutive scalar registers (fan-in) (bary.f, texture samp)
207 OPC_META_FO
= _OPC(-1, 2),
208 OPC_META_FI
= _OPC(-1, 3),
212 #define opc_cat(opc) ((int)((opc) >> NOPC_BITS))
213 #define opc_op(opc) ((unsigned)((opc) & ((1 << NOPC_BITS) - 1)))
223 TYPE_S8
= 7, // XXX I assume?
226 static inline uint32_t type_size(type_t type
)
241 assert(0); /* invalid type */
246 static inline int type_float(type_t type
)
248 return (type
== TYPE_F32
) || (type
== TYPE_F16
);
251 static inline int type_uint(type_t type
)
253 return (type
== TYPE_U32
) || (type
== TYPE_U16
) || (type
== TYPE_U8
);
256 static inline int type_sint(type_t type
)
258 return (type
== TYPE_S32
) || (type
== TYPE_S16
) || (type
== TYPE_S8
);
261 typedef union PACKED
{
262 /* normal gpr or const src register: */
267 /* for immediate val: */
268 int32_t iim_val
: 11;
269 /* to make compiler happy: */
271 uint32_t dummy10
: 10;
272 int32_t idummy10
: 10;
273 uint32_t dummy11
: 11;
274 uint32_t dummy12
: 12;
275 uint32_t dummy13
: 13;
279 /* special registers: */
280 #define REG_A0 61 /* address register */
281 #define REG_P0 62 /* predicate register */
283 static inline int reg_special(reg_t reg
)
285 return (reg
.num
== REG_A0
) || (reg
.num
== REG_P0
);
288 typedef struct PACKED
{
293 uint32_t dummy1
: 16;
297 uint32_t dummy1
: 12;
313 uint32_t jmp_tgt
: 1;
315 uint32_t opc_cat
: 3;
318 typedef struct PACKED
{
321 /* for normal src register: */
324 /* at least low bit of pad must be zero or it will
325 * look like a address relative src
329 /* for address relative: */
332 uint32_t src_rel_c
: 1;
333 uint32_t src_rel
: 1;
334 uint32_t unknown
: 20;
348 uint32_t dst_type
: 3;
349 uint32_t dst_rel
: 1;
350 uint32_t src_type
: 3;
354 uint32_t pos_inf
: 1;
355 uint32_t must_be_0
: 2;
356 uint32_t jmp_tgt
: 1;
358 uint32_t opc_cat
: 3;
361 typedef struct PACKED
{
366 uint32_t must_be_zero1
: 2;
367 uint32_t src1_im
: 1; /* immediate */
368 uint32_t src1_neg
: 1; /* negate */
369 uint32_t src1_abs
: 1; /* absolute value */
373 uint32_t src1_c
: 1; /* relative-const */
374 uint32_t src1_rel
: 1; /* relative address */
375 uint32_t must_be_zero
: 1;
380 uint32_t src1_c
: 1; /* const */
388 uint32_t must_be_zero2
: 2;
389 uint32_t src2_im
: 1; /* immediate */
390 uint32_t src2_neg
: 1; /* negate */
391 uint32_t src2_abs
: 1; /* absolute value */
395 uint32_t src2_c
: 1; /* relative-const */
396 uint32_t src2_rel
: 1; /* relative address */
397 uint32_t must_be_zero
: 1;
402 uint32_t src2_c
: 1; /* const */
412 uint32_t ul
: 1; /* dunno */
413 uint32_t dst_half
: 1; /* or widen/narrow.. ie. dst hrN <-> rN */
417 uint32_t full
: 1; /* not half */
419 uint32_t jmp_tgt
: 1;
421 uint32_t opc_cat
: 3;
424 typedef struct PACKED
{
429 uint32_t must_be_zero1
: 2;
431 uint32_t src1_neg
: 1;
437 uint32_t src1_rel
: 1;
438 uint32_t must_be_zero
: 1;
451 uint32_t must_be_zero2
: 2;
453 uint32_t src2_neg
: 1;
454 uint32_t src3_neg
: 1;
459 uint32_t src3_rel
: 1;
460 uint32_t must_be_zero
: 1;
476 uint32_t dst_half
: 1; /* or widen/narrow.. ie. dst hrN <-> rN */
479 uint32_t jmp_tgt
: 1;
481 uint32_t opc_cat
: 3;
484 static inline bool instr_cat3_full(instr_cat3_t
*cat3
)
486 switch (_OPC(3, cat3
->opc
)) {
494 case OPC_SAD_S32
: // really??
501 typedef struct PACKED
{
506 uint32_t must_be_zero1
: 2;
507 uint32_t src_im
: 1; /* immediate */
508 uint32_t src_neg
: 1; /* negate */
509 uint32_t src_abs
: 1; /* absolute value */
513 uint32_t src_c
: 1; /* relative-const */
514 uint32_t src_rel
: 1; /* relative address */
515 uint32_t must_be_zero
: 1;
520 uint32_t src_c
: 1; /* const */
524 uint32_t dummy1
: 16; /* seem to be ignored */
532 uint32_t dst_half
: 1; /* or widen/narrow.. ie. dst hrN <-> rN */
533 uint32_t dummy2
: 5; /* seem to be ignored */
534 uint32_t full
: 1; /* not half */
536 uint32_t jmp_tgt
: 1;
538 uint32_t opc_cat
: 3;
541 typedef struct PACKED
{
546 uint32_t full
: 1; /* not half */
549 uint32_t dummy1
: 4; /* seem to be ignored */
555 uint32_t full
: 1; /* not half */
562 /* same in either case: */
563 // XXX I think, confirm this
565 uint32_t full
: 1; /* not half */
573 uint32_t wrmask
: 4; /* write-mask */
575 uint32_t dummy2
: 1; /* seems to be ignored */
580 uint32_t is_s2en
: 1;
585 uint32_t jmp_tgt
: 1;
587 uint32_t opc_cat
: 3;
590 /* dword0 encoding for src_off: [src1 + off], src2: */
591 typedef struct PACKED
{
593 uint32_t mustbe1
: 1;
596 uint32_t src1_im
: 1;
597 uint32_t src2_im
: 1;
604 /* dword0 encoding for !src_off: [src1], src2 */
605 typedef struct PACKED
{
607 uint32_t mustbe0
: 1;
609 uint32_t ignore0
: 8;
610 uint32_t src1_im
: 1;
611 uint32_t src2_im
: 1;
618 /* dword1 encoding for dst_off: */
619 typedef struct PACKED
{
623 /* note: there is some weird stuff going on where sometimes
624 * cat6->a.off is involved.. but that seems like a bug in
625 * the blob, since it is used even if !cat6->src_off
626 * It would make sense for there to be some more bits to
627 * bring us to 11 bits worth of offset, but not sure..
630 uint32_t mustbe1
: 1;
635 /* dword1 encoding for !dst_off: */
636 typedef struct PACKED
{
641 uint32_t mustbe0
: 1;
645 /* I think some of the other cat6 instructions use additional
649 typedef union PACKED
{
656 uint32_t src_off
: 1;
661 uint32_t dst_off
: 1;
664 uint32_t g
: 1; /* or in some cases it means dst immed */
667 uint32_t jmp_tgt
: 1;
669 uint32_t opc_cat
: 3;
673 typedef union PACKED
{
684 uint32_t repeat
: 3; /* cat0-cat4 */
686 uint32_t ss
: 1; /* cat1-cat4 (cat0??) */
687 uint32_t ul
: 1; /* cat2-cat4 (and cat1 in blob.. which may be bug??) */
689 uint32_t jmp_tgt
: 1;
691 uint32_t opc_cat
: 3;
696 static inline uint32_t instr_opc(instr_t
*instr
)
698 switch (instr
->opc_cat
) {
699 case 0: return instr
->cat0
.opc
;
701 case 2: return instr
->cat2
.opc
;
702 case 3: return instr
->cat3
.opc
;
703 case 4: return instr
->cat4
.opc
;
704 case 5: return instr
->cat5
.opc
;
705 case 6: return instr
->cat6
.opc
;
710 static inline bool is_mad(opc_t opc
)
725 static inline bool is_madsh(opc_t opc
)
736 #endif /* INSTR_A3XX_H_ */