Tizen 2.0 Release
[profile/ivi/osmesa.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_swizzle(
32    const struct tgsi_full_src_register  *reg,
33    unsigned component )
34 {
35    return tgsi_util_get_src_register_swizzle(
36       reg->Register,
37       component );
38 }
39
40
41 unsigned
42 tgsi_util_get_full_src_register_sign_mode(
43    const struct  tgsi_full_src_register *reg,
44    unsigned component )
45 {
46    unsigned sign_mode;
47
48    if( reg->RegisterExtMod.Absolute ) {
49       /* Consider only the post-abs negation. */
50
51       if( reg->RegisterExtMod.Negate ) {
52          sign_mode = TGSI_UTIL_SIGN_SET;
53       }
54       else {
55          sign_mode = TGSI_UTIL_SIGN_CLEAR;
56       }
57    }
58    else {
59       /* Accumulate the three negations. */
60
61       unsigned negate;
62
63       negate = reg->Register.Negate;
64       if( reg->RegisterExtMod.Negate ) {
65          negate = !negate;
66       }
67
68       if( negate ) {
69          sign_mode = TGSI_UTIL_SIGN_TOGGLE;
70       }
71       else {
72          sign_mode = TGSI_UTIL_SIGN_KEEP;
73       }
74    }
75
76    return sign_mode;
77 }