gallium: remove the swizzling parts of ExtSwizzle
[mesa.git] / src / gallium / drivers / cell / spu / spu_util.c
1
2 #include "cell/common.h"
3 #include "pipe/p_shader_tokens.h"
4 #include "util/u_debug.h"
5 #include "tgsi/tgsi_parse.h"
6 //#include "tgsi_build.h"
7 #include "tgsi/tgsi_util.h"
8
9 unsigned
10 tgsi_util_get_src_register_swizzle(
11 const struct tgsi_src_register *reg,
12 unsigned component )
13 {
14 switch( component ) {
15 case 0:
16 return reg->SwizzleX;
17 case 1:
18 return reg->SwizzleY;
19 case 2:
20 return reg->SwizzleZ;
21 case 3:
22 return reg->SwizzleW;
23 default:
24 ASSERT( 0 );
25 }
26 return 0;
27 }
28
29
30 unsigned
31 tgsi_util_get_full_src_register_extswizzle(
32 const struct tgsi_full_src_register *reg,
33 unsigned component )
34 {
35 return tgsi_util_get_src_register_swizzle(
36 reg->SrcRegister,
37 component );
38 }
39
40 unsigned
41 tgsi_util_get_src_register_extnegate(
42 const struct tgsi_src_register_ext_swz *reg,
43 unsigned component )
44 {
45 switch( component ) {
46 case 0:
47 return reg->NegateX;
48 case 1:
49 return reg->NegateY;
50 case 2:
51 return reg->NegateZ;
52 case 3:
53 return reg->NegateW;
54 default:
55 ASSERT( 0 );
56 }
57 return 0;
58 }
59
60 void
61 tgsi_util_set_src_register_extnegate(
62 struct tgsi_src_register_ext_swz *reg,
63 unsigned negate,
64 unsigned component )
65 {
66 switch( component ) {
67 case 0:
68 reg->NegateX = negate;
69 break;
70 case 1:
71 reg->NegateY = negate;
72 break;
73 case 2:
74 reg->NegateZ = negate;
75 break;
76 case 3:
77 reg->NegateW = negate;
78 break;
79 default:
80 ASSERT( 0 );
81 }
82 }
83
84 unsigned
85 tgsi_util_get_full_src_register_sign_mode(
86 const struct tgsi_full_src_register *reg,
87 unsigned component )
88 {
89 unsigned sign_mode;
90
91 if( reg->SrcRegisterExtMod.Absolute ) {
92 /* Consider only the post-abs negation. */
93
94 if( reg->SrcRegisterExtMod.Negate ) {
95 sign_mode = TGSI_UTIL_SIGN_SET;
96 }
97 else {
98 sign_mode = TGSI_UTIL_SIGN_CLEAR;
99 }
100 }
101 else {
102 /* Accumulate the three negations. */
103
104 unsigned negate;
105
106 negate = reg->SrcRegister.Negate;
107 if( tgsi_util_get_src_register_extnegate( &reg->SrcRegisterExtSwz, component ) ) {
108 negate = !negate;
109 }
110 if( reg->SrcRegisterExtMod.Negate ) {
111 negate = !negate;
112 }
113
114 if( negate ) {
115 sign_mode = TGSI_UTIL_SIGN_TOGGLE;
116 }
117 else {
118 sign_mode = TGSI_UTIL_SIGN_KEEP;
119 }
120 }
121
122 return sign_mode;
123 }