2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keithw@vmware.com>
34 * This file defines struct brw_reg, which is our representation for EU
35 * registers. They're not a hardware specific format, just an abstraction
36 * that intends to capture the full flexibility of the hardware registers.
38 * The brw_eu_emit.c layer's brw_set_dest/brw_set_src[01] functions encode
39 * the abstract brw_reg type into the actual hardware instruction encoding.
46 #include "main/compiler.h"
47 #include "main/macros.h"
48 #include "program/prog_instruction.h"
49 #include "brw_defines.h"
55 struct brw_device_info
;
57 /** Number of general purpose registers (VS, WM, etc) */
58 #define BRW_MAX_GRF 128
61 * First GRF used for the MRF hack.
63 * On gen7, MRFs are no longer used, and contiguous GRFs are used instead. We
64 * haven't converted our compiler to be aware of this, so it asks for MRFs and
65 * brw_eu_emit.c quietly converts them to be accesses of the top GRFs. The
66 * register allocators have to be careful of this to avoid corrupting the "MRF"s
67 * with actual GRF allocations.
69 #define GEN7_MRF_HACK_START 112
71 /** Number of message register file registers */
72 #define BRW_MAX_MRF(gen) (gen == 6 ? 24 : 16)
74 #define BRW_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<2) | ((c)<<4) | ((d)<<6))
75 #define BRW_GET_SWZ(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
77 #define BRW_SWIZZLE_NOOP BRW_SWIZZLE4(0,1,2,3)
78 #define BRW_SWIZZLE_XYZW BRW_SWIZZLE4(0,1,2,3)
79 #define BRW_SWIZZLE_XXXX BRW_SWIZZLE4(0,0,0,0)
80 #define BRW_SWIZZLE_YYYY BRW_SWIZZLE4(1,1,1,1)
81 #define BRW_SWIZZLE_ZZZZ BRW_SWIZZLE4(2,2,2,2)
82 #define BRW_SWIZZLE_WWWW BRW_SWIZZLE4(3,3,3,3)
83 #define BRW_SWIZZLE_XYXY BRW_SWIZZLE4(0,1,0,1)
84 #define BRW_SWIZZLE_YZXW BRW_SWIZZLE4(1,2,0,3)
85 #define BRW_SWIZZLE_ZXYW BRW_SWIZZLE4(2,0,1,3)
86 #define BRW_SWIZZLE_ZWZW BRW_SWIZZLE4(2,3,2,3)
87 #define BRW_SWIZZLE_WZYX BRW_SWIZZLE4(3,2,1,0)
90 brw_is_single_value_swizzle(unsigned swiz
)
92 return (swiz
== BRW_SWIZZLE_XXXX
||
93 swiz
== BRW_SWIZZLE_YYYY
||
94 swiz
== BRW_SWIZZLE_ZZZZ
||
95 swiz
== BRW_SWIZZLE_WWWW
);
99 * Compute the swizzle obtained from the application of \p swz0 on the result
100 * of \p swz1. The argument ordering is expected to match function
103 static inline unsigned
104 brw_compose_swizzle(unsigned swz0
, unsigned swz1
)
107 BRW_GET_SWZ(swz1
, BRW_GET_SWZ(swz0
, 0)),
108 BRW_GET_SWZ(swz1
, BRW_GET_SWZ(swz0
, 1)),
109 BRW_GET_SWZ(swz1
, BRW_GET_SWZ(swz0
, 2)),
110 BRW_GET_SWZ(swz1
, BRW_GET_SWZ(swz0
, 3)));
114 * Return the result of applying swizzle \p swz to shuffle the bits of \p mask
117 static inline unsigned
118 brw_apply_swizzle_to_mask(unsigned swz
, unsigned mask
)
122 for (unsigned i
= 0; i
< 4; i
++) {
123 if (mask
& (1 << BRW_GET_SWZ(swz
, i
)))
131 * Return the result of applying the inverse of swizzle \p swz to shuffle the
132 * bits of \p mask (AKA preimage). Useful to find out which components are
133 * read from a swizzled source given the instruction writemask.
135 static inline unsigned
136 brw_apply_inv_swizzle_to_mask(unsigned swz
, unsigned mask
)
140 for (unsigned i
= 0; i
< 4; i
++) {
142 result
|= 1 << BRW_GET_SWZ(swz
, i
);
149 * Construct an identity swizzle for the set of enabled channels given by \p
150 * mask. The result will only reference channels enabled in the provided \p
151 * mask, assuming that \p mask is non-zero. The constructed swizzle will
152 * satisfy the property that for any instruction OP and any mask:
154 * brw_OP(p, brw_writemask(dst, mask),
155 * brw_swizzle(src, brw_swizzle_for_mask(mask)));
157 * will be equivalent to the same instruction without swizzle:
159 * brw_OP(p, brw_writemask(dst, mask), src);
161 static inline unsigned
162 brw_swizzle_for_mask(unsigned mask
)
164 unsigned last
= (mask
? ffs(mask
) - 1 : 0);
167 for (unsigned i
= 0; i
< 4; i
++)
168 last
= swz
[i
] = (mask
& (1 << i
) ? i
: last
);
170 return BRW_SWIZZLE4(swz
[0], swz
[1], swz
[2], swz
[3]);
174 * Construct an identity swizzle for the first \p n components of a vector.
175 * When only a subset of channels of a vec4 are used we don't want to
176 * reference the other channels, as that will tell optimization passes that
177 * those other channels are used.
179 static inline unsigned
180 brw_swizzle_for_size(unsigned n
)
182 return brw_swizzle_for_mask((1 << n
) - 1);
186 * Converse of brw_swizzle_for_mask(). Returns the mask of components
187 * accessed by the specified swizzle \p swz.
189 static inline unsigned
190 brw_mask_for_swizzle(unsigned swz
)
192 return brw_apply_inv_swizzle_to_mask(swz
, ~0);
195 enum PACKED brw_reg_type
{
196 BRW_REGISTER_TYPE_UD
= 0,
198 BRW_REGISTER_TYPE_UW
,
202 /** Non-immediates only: @{ */
203 BRW_REGISTER_TYPE_UB
,
207 /** Immediates only: @{ */
208 BRW_REGISTER_TYPE_UV
, /* Gen6+ */
210 BRW_REGISTER_TYPE_VF
,
213 BRW_REGISTER_TYPE_DF
, /* Gen7+ (no immediates until Gen8+) */
216 BRW_REGISTER_TYPE_HF
,
217 BRW_REGISTER_TYPE_UQ
,
221 unsigned brw_reg_type_to_hw_type(const struct brw_device_info
*devinfo
,
222 enum brw_reg_type type
, enum brw_reg_file file
);
223 const char *brw_reg_type_letters(unsigned brw_reg_type
);
225 #define REG_SIZE (8*4)
227 /* These aren't hardware structs, just something useful for us to pass around:
229 * Align1 operation has a lot of control over input ranges. Used in
230 * WM programs to implement shaders decomposed into "channel serial"
231 * or "structure of array" form:
234 enum brw_reg_type type
:4;
235 enum brw_reg_file file
:3; /* :2 hardware format */
236 unsigned negate
:1; /* source only */
237 unsigned abs
:1; /* source only */
238 unsigned address_mode
:1; /* relative addressing, hopefully! */
240 unsigned subnr
:5; /* :1 in align16 */
245 unsigned swizzle
:8; /* src only, align16 only */
246 unsigned writemask
:4; /* dest only, align16 only */
247 int indirect_offset
:10; /* relative addressing offset */
248 unsigned vstride
:4; /* source only */
249 unsigned width
:3; /* src only, align1 only */
250 unsigned hstride
:2; /* align1 only */
261 struct brw_indirect
{
262 unsigned addr_subnr
:4;
268 static inline unsigned
269 type_sz(unsigned type
)
272 case BRW_REGISTER_TYPE_UQ
:
273 case BRW_REGISTER_TYPE_Q
:
275 case BRW_REGISTER_TYPE_UD
:
276 case BRW_REGISTER_TYPE_D
:
277 case BRW_REGISTER_TYPE_F
:
279 case BRW_REGISTER_TYPE_UW
:
280 case BRW_REGISTER_TYPE_W
:
282 case BRW_REGISTER_TYPE_UB
:
283 case BRW_REGISTER_TYPE_B
:
291 * Construct a brw_reg.
292 * \param file one of the BRW_x_REGISTER_FILE values
293 * \param nr register number/index
294 * \param subnr register sub number
295 * \param negate register negate modifier
296 * \param abs register abs modifier
297 * \param type one of BRW_REGISTER_TYPE_x
298 * \param vstride one of BRW_VERTICAL_STRIDE_x
299 * \param width one of BRW_WIDTH_x
300 * \param hstride one of BRW_HORIZONTAL_STRIDE_x
301 * \param swizzle one of BRW_SWIZZLE_x
302 * \param writemask WRITEMASK_X/Y/Z/W bitfield
304 static inline struct brw_reg
305 brw_reg(enum brw_reg_file file
,
310 enum brw_reg_type type
,
318 if (file
== BRW_GENERAL_REGISTER_FILE
)
319 assert(nr
< BRW_MAX_GRF
);
320 else if (file
== BRW_ARCHITECTURE_REGISTER_FILE
)
321 assert(nr
<= BRW_ARF_TIMESTAMP
);
322 /* Asserting on the MRF register number requires to know the hardware gen
323 * (gen6 has 24 MRF registers), which we don't know here, so we assert
324 * for that in the generators and in brw_eu_emit.c
331 reg
.address_mode
= BRW_ADDRESS_DIRECT
;
333 reg
.subnr
= subnr
* type_sz(type
);
336 /* Could do better: If the reg is r5.3<0;1,0>, we probably want to
337 * set swizzle and writemask to W, as the lower bits of subnr will
338 * be lost when converted to align16. This is probably too much to
339 * keep track of as you'd want it adjusted by suboffset(), etc.
340 * Perhaps fix up when converting to align16?
342 reg
.swizzle
= swizzle
;
343 reg
.writemask
= writemask
;
344 reg
.indirect_offset
= 0;
345 reg
.vstride
= vstride
;
347 reg
.hstride
= hstride
;
352 /** Construct float[16] register */
353 static inline struct brw_reg
354 brw_vec16_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
362 BRW_VERTICAL_STRIDE_16
,
364 BRW_HORIZONTAL_STRIDE_1
,
369 /** Construct float[8] register */
370 static inline struct brw_reg
371 brw_vec8_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
379 BRW_VERTICAL_STRIDE_8
,
381 BRW_HORIZONTAL_STRIDE_1
,
386 /** Construct float[4] register */
387 static inline struct brw_reg
388 brw_vec4_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
396 BRW_VERTICAL_STRIDE_4
,
398 BRW_HORIZONTAL_STRIDE_1
,
403 /** Construct float[2] register */
404 static inline struct brw_reg
405 brw_vec2_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
413 BRW_VERTICAL_STRIDE_2
,
415 BRW_HORIZONTAL_STRIDE_1
,
420 /** Construct float[1] register */
421 static inline struct brw_reg
422 brw_vec1_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
430 BRW_VERTICAL_STRIDE_0
,
432 BRW_HORIZONTAL_STRIDE_0
,
437 static inline struct brw_reg
438 brw_vecn_reg(unsigned width
, enum brw_reg_file file
,
439 unsigned nr
, unsigned subnr
)
443 return brw_vec1_reg(file
, nr
, subnr
);
445 return brw_vec2_reg(file
, nr
, subnr
);
447 return brw_vec4_reg(file
, nr
, subnr
);
449 return brw_vec8_reg(file
, nr
, subnr
);
451 return brw_vec16_reg(file
, nr
, subnr
);
453 unreachable("Invalid register width");
457 static inline struct brw_reg
458 retype(struct brw_reg reg
, enum brw_reg_type type
)
464 static inline struct brw_reg
465 firsthalf(struct brw_reg reg
)
470 static inline struct brw_reg
471 sechalf(struct brw_reg reg
)
478 static inline struct brw_reg
479 suboffset(struct brw_reg reg
, unsigned delta
)
481 reg
.subnr
+= delta
* type_sz(reg
.type
);
486 static inline struct brw_reg
487 offset(struct brw_reg reg
, unsigned delta
)
494 static inline struct brw_reg
495 byte_offset(struct brw_reg reg
, unsigned bytes
)
497 unsigned newoffset
= reg
.nr
* REG_SIZE
+ reg
.subnr
+ bytes
;
498 reg
.nr
= newoffset
/ REG_SIZE
;
499 reg
.subnr
= newoffset
% REG_SIZE
;
504 /** Construct unsigned word[16] register */
505 static inline struct brw_reg
506 brw_uw16_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
508 return suboffset(retype(brw_vec16_reg(file
, nr
, 0), BRW_REGISTER_TYPE_UW
), subnr
);
511 /** Construct unsigned word[8] register */
512 static inline struct brw_reg
513 brw_uw8_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
515 return suboffset(retype(brw_vec8_reg(file
, nr
, 0), BRW_REGISTER_TYPE_UW
), subnr
);
518 /** Construct unsigned word[1] register */
519 static inline struct brw_reg
520 brw_uw1_reg(enum brw_reg_file file
, unsigned nr
, unsigned subnr
)
522 return suboffset(retype(brw_vec1_reg(file
, nr
, 0), BRW_REGISTER_TYPE_UW
), subnr
);
525 static inline struct brw_reg
526 brw_imm_reg(enum brw_reg_type type
)
528 return brw_reg(BRW_IMMEDIATE_VALUE
,
534 BRW_VERTICAL_STRIDE_0
,
536 BRW_HORIZONTAL_STRIDE_0
,
541 /** Construct float immediate register */
542 static inline struct brw_reg
545 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_F
);
550 /** Construct integer immediate register */
551 static inline struct brw_reg
554 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_D
);
559 /** Construct uint immediate register */
560 static inline struct brw_reg
561 brw_imm_ud(unsigned ud
)
563 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_UD
);
568 /** Construct ushort immediate register */
569 static inline struct brw_reg
570 brw_imm_uw(uint16_t uw
)
572 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_UW
);
573 imm
.ud
= uw
| (uw
<< 16);
577 /** Construct short immediate register */
578 static inline struct brw_reg
581 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_W
);
582 imm
.d
= w
| (w
<< 16);
586 /* brw_imm_b and brw_imm_ub aren't supported by hardware - the type
587 * numbers alias with _V and _VF below:
590 /** Construct vector of eight signed half-byte values */
591 static inline struct brw_reg
592 brw_imm_v(unsigned v
)
594 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_V
);
599 /** Construct vector of eight unsigned half-byte values */
600 static inline struct brw_reg
601 brw_imm_uv(unsigned uv
)
603 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_UV
);
608 /** Construct vector of four 8-bit float values */
609 static inline struct brw_reg
610 brw_imm_vf(unsigned v
)
612 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_VF
);
617 static inline struct brw_reg
618 brw_imm_vf4(unsigned v0
, unsigned v1
, unsigned v2
, unsigned v3
)
620 struct brw_reg imm
= brw_imm_reg(BRW_REGISTER_TYPE_VF
);
621 imm
.vstride
= BRW_VERTICAL_STRIDE_0
;
622 imm
.width
= BRW_WIDTH_4
;
623 imm
.hstride
= BRW_HORIZONTAL_STRIDE_1
;
624 imm
.ud
= ((v0
<< 0) | (v1
<< 8) | (v2
<< 16) | (v3
<< 24));
629 static inline struct brw_reg
630 brw_address(struct brw_reg reg
)
632 return brw_imm_uw(reg
.nr
* REG_SIZE
+ reg
.subnr
);
635 /** Construct float[1] general-purpose register */
636 static inline struct brw_reg
637 brw_vec1_grf(unsigned nr
, unsigned subnr
)
639 return brw_vec1_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
642 /** Construct float[2] general-purpose register */
643 static inline struct brw_reg
644 brw_vec2_grf(unsigned nr
, unsigned subnr
)
646 return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
649 /** Construct float[4] general-purpose register */
650 static inline struct brw_reg
651 brw_vec4_grf(unsigned nr
, unsigned subnr
)
653 return brw_vec4_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
656 /** Construct float[8] general-purpose register */
657 static inline struct brw_reg
658 brw_vec8_grf(unsigned nr
, unsigned subnr
)
660 return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
663 /** Construct float[16] general-purpose register */
664 static inline struct brw_reg
665 brw_vec16_grf(unsigned nr
, unsigned subnr
)
667 return brw_vec16_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
671 static inline struct brw_reg
672 brw_uw8_grf(unsigned nr
, unsigned subnr
)
674 return brw_uw8_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
677 static inline struct brw_reg
678 brw_uw16_grf(unsigned nr
, unsigned subnr
)
680 return brw_uw16_reg(BRW_GENERAL_REGISTER_FILE
, nr
, subnr
);
684 /** Construct null register (usually used for setting condition codes) */
685 static inline struct brw_reg
688 return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE
, BRW_ARF_NULL
, 0);
691 static inline struct brw_reg
692 brw_null_vec(unsigned width
)
694 return brw_vecn_reg(width
, BRW_ARCHITECTURE_REGISTER_FILE
, BRW_ARF_NULL
, 0);
697 static inline struct brw_reg
698 brw_address_reg(unsigned subnr
)
700 return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE
, BRW_ARF_ADDRESS
, subnr
);
703 /* If/else instructions break in align16 mode if writemask & swizzle
704 * aren't xyzw. This goes against the convention for other scalar
707 static inline struct brw_reg
710 return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE
,
715 BRW_REGISTER_TYPE_UD
,
716 BRW_VERTICAL_STRIDE_4
, /* ? */
718 BRW_HORIZONTAL_STRIDE_0
,
719 BRW_SWIZZLE_XYZW
, /* NOTE! */
720 WRITEMASK_XYZW
); /* NOTE! */
723 static inline struct brw_reg
724 brw_notification_reg(void)
726 return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE
,
727 BRW_ARF_NOTIFICATION_COUNT
,
731 BRW_REGISTER_TYPE_UD
,
732 BRW_VERTICAL_STRIDE_0
,
734 BRW_HORIZONTAL_STRIDE_0
,
739 static inline struct brw_reg
740 brw_acc_reg(unsigned width
)
742 return brw_vecn_reg(width
, BRW_ARCHITECTURE_REGISTER_FILE
,
743 BRW_ARF_ACCUMULATOR
, 0);
746 static inline struct brw_reg
747 brw_flag_reg(int reg
, int subreg
)
749 return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE
,
750 BRW_ARF_FLAG
+ reg
, subreg
);
754 * Return the mask register present in Gen4-5, or the related register present
755 * in Gen7.5 and later hardware referred to as "channel enable" register in
758 static inline struct brw_reg
759 brw_mask_reg(unsigned subnr
)
761 return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE
, BRW_ARF_MASK
, subnr
);
764 static inline struct brw_reg
765 brw_message_reg(unsigned nr
)
767 return brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE
, nr
, 0);
770 static inline struct brw_reg
771 brw_uvec_mrf(unsigned width
, unsigned nr
, unsigned subnr
)
773 return retype(brw_vecn_reg(width
, BRW_MESSAGE_REGISTER_FILE
, nr
, subnr
),
774 BRW_REGISTER_TYPE_UD
);
777 /* This is almost always called with a numeric constant argument, so
778 * make things easy to evaluate at compile time:
780 static inline unsigned cvt(unsigned val
)
794 static inline struct brw_reg
795 stride(struct brw_reg reg
, unsigned vstride
, unsigned width
, unsigned hstride
)
797 reg
.vstride
= cvt(vstride
);
798 reg
.width
= cvt(width
) - 1;
799 reg
.hstride
= cvt(hstride
);
804 * Multiply the vertical and horizontal stride of a register by the given
807 static inline struct brw_reg
808 spread(struct brw_reg reg
, unsigned s
)
811 assert(_mesa_is_pow_two(s
));
814 reg
.hstride
+= cvt(s
) - 1;
817 reg
.vstride
+= cvt(s
) - 1;
821 return stride(reg
, 0, 1, 0);
825 static inline struct brw_reg
826 vec16(struct brw_reg reg
)
828 return stride(reg
, 16,16,1);
831 static inline struct brw_reg
832 vec8(struct brw_reg reg
)
834 return stride(reg
, 8,8,1);
837 static inline struct brw_reg
838 vec4(struct brw_reg reg
)
840 return stride(reg
, 4,4,1);
843 static inline struct brw_reg
844 vec2(struct brw_reg reg
)
846 return stride(reg
, 2,2,1);
849 static inline struct brw_reg
850 vec1(struct brw_reg reg
)
852 return stride(reg
, 0,1,0);
856 static inline struct brw_reg
857 get_element(struct brw_reg reg
, unsigned elt
)
859 return vec1(suboffset(reg
, elt
));
862 static inline struct brw_reg
863 get_element_ud(struct brw_reg reg
, unsigned elt
)
865 return vec1(suboffset(retype(reg
, BRW_REGISTER_TYPE_UD
), elt
));
868 static inline struct brw_reg
869 get_element_d(struct brw_reg reg
, unsigned elt
)
871 return vec1(suboffset(retype(reg
, BRW_REGISTER_TYPE_D
), elt
));
875 static inline struct brw_reg
876 brw_swizzle(struct brw_reg reg
, unsigned x
, unsigned y
, unsigned z
, unsigned w
)
878 assert(reg
.file
!= BRW_IMMEDIATE_VALUE
);
880 reg
.swizzle
= brw_compose_swizzle(BRW_SWIZZLE4(x
, y
, z
, w
),
886 static inline struct brw_reg
887 brw_swizzle1(struct brw_reg reg
, unsigned x
)
889 return brw_swizzle(reg
, x
, x
, x
, x
);
892 static inline struct brw_reg
893 brw_writemask(struct brw_reg reg
, unsigned mask
)
895 assert(reg
.file
!= BRW_IMMEDIATE_VALUE
);
896 reg
.writemask
&= mask
;
900 static inline struct brw_reg
901 brw_set_writemask(struct brw_reg reg
, unsigned mask
)
903 assert(reg
.file
!= BRW_IMMEDIATE_VALUE
);
904 reg
.writemask
= mask
;
908 static inline unsigned
909 brw_writemask_for_size(unsigned n
)
914 static inline struct brw_reg
915 negate(struct brw_reg reg
)
921 static inline struct brw_reg
922 brw_abs(struct brw_reg reg
)
929 /************************************************************************/
931 static inline struct brw_reg
932 brw_vec4_indirect(unsigned subnr
, int offset
)
934 struct brw_reg reg
= brw_vec4_grf(0, 0);
936 reg
.address_mode
= BRW_ADDRESS_REGISTER_INDIRECT_REGISTER
;
937 reg
.indirect_offset
= offset
;
941 static inline struct brw_reg
942 brw_vec1_indirect(unsigned subnr
, int offset
)
944 struct brw_reg reg
= brw_vec1_grf(0, 0);
946 reg
.address_mode
= BRW_ADDRESS_REGISTER_INDIRECT_REGISTER
;
947 reg
.indirect_offset
= offset
;
951 static inline struct brw_reg
952 brw_VxH_indirect(unsigned subnr
, int offset
)
954 struct brw_reg reg
= brw_vec1_grf(0, 0);
955 reg
.vstride
= BRW_VERTICAL_STRIDE_ONE_DIMENSIONAL
;
957 reg
.address_mode
= BRW_ADDRESS_REGISTER_INDIRECT_REGISTER
;
958 reg
.indirect_offset
= offset
;
962 static inline struct brw_reg
963 deref_4f(struct brw_indirect ptr
, int offset
)
965 return brw_vec4_indirect(ptr
.addr_subnr
, ptr
.addr_offset
+ offset
);
968 static inline struct brw_reg
969 deref_1f(struct brw_indirect ptr
, int offset
)
971 return brw_vec1_indirect(ptr
.addr_subnr
, ptr
.addr_offset
+ offset
);
974 static inline struct brw_reg
975 deref_4b(struct brw_indirect ptr
, int offset
)
977 return retype(deref_4f(ptr
, offset
), BRW_REGISTER_TYPE_B
);
980 static inline struct brw_reg
981 deref_1uw(struct brw_indirect ptr
, int offset
)
983 return retype(deref_1f(ptr
, offset
), BRW_REGISTER_TYPE_UW
);
986 static inline struct brw_reg
987 deref_1d(struct brw_indirect ptr
, int offset
)
989 return retype(deref_1f(ptr
, offset
), BRW_REGISTER_TYPE_D
);
992 static inline struct brw_reg
993 deref_1ud(struct brw_indirect ptr
, int offset
)
995 return retype(deref_1f(ptr
, offset
), BRW_REGISTER_TYPE_UD
);
998 static inline struct brw_reg
999 get_addr_reg(struct brw_indirect ptr
)
1001 return brw_address_reg(ptr
.addr_subnr
);
1004 static inline struct brw_indirect
1005 brw_indirect_offset(struct brw_indirect ptr
, int offset
)
1007 ptr
.addr_offset
+= offset
;
1011 static inline struct brw_indirect
1012 brw_indirect(unsigned addr_subnr
, int offset
)
1014 struct brw_indirect ptr
;
1015 ptr
.addr_subnr
= addr_subnr
;
1016 ptr
.addr_offset
= offset
;
1022 region_matches(struct brw_reg reg
, enum brw_vertical_stride v
,
1023 enum brw_width w
, enum brw_horizontal_stride h
)
1025 return reg
.vstride
== v
&&
1030 #define has_scalar_region(reg) \
1031 region_matches(reg, BRW_VERTICAL_STRIDE_0, BRW_WIDTH_1, \
1032 BRW_HORIZONTAL_STRIDE_0)
1034 /* brw_packed_float.c */
1035 int brw_float_to_vf(float f
);
1036 float brw_vf_to_float(unsigned char vf
);