Bring in ppc spe rtasm into gallium's rtasm module.
[mesa.git] / src / gallium / drivers / cell / spu / spu_colorpack.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, 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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29
30 #ifndef SPU_COLORPACK_H
31 #define SPU_COLORPACK_H
32
33
34 #include <spu_intrinsics.h>
35
36
37 static INLINE unsigned int
38 spu_pack_R8G8B8A8(vector float rgba)
39 {
40 vector unsigned int out = spu_convtu(rgba, 32);
41
42 out = spu_shuffle(out, out, ((vector unsigned char) {
43 0, 4, 8, 12, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0 }) );
45
46 return spu_extract(out, 0);
47 }
48
49
50 static INLINE unsigned int
51 spu_pack_A8R8G8B8(vector float rgba)
52 {
53 vector unsigned int out = spu_convtu(rgba, 32);
54 out = spu_shuffle(out, out, ((vector unsigned char) {
55 12, 0, 4, 8, 0, 0, 0, 0,
56 0, 0, 0, 0, 0, 0, 0, 0}) );
57 return spu_extract(out, 0);
58 }
59
60
61 static INLINE unsigned int
62 spu_pack_B8G8R8A8(vector float rgba)
63 {
64 vector unsigned int out = spu_convtu(rgba, 32);
65 out = spu_shuffle(out, out, ((vector unsigned char) {
66 8, 4, 0, 12, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0}) );
68 return spu_extract(out, 0);
69 }
70
71
72 static INLINE unsigned int
73 spu_pack_color_shuffle(vector float rgba, vector unsigned char shuffle)
74 {
75 vector unsigned int out = spu_convtu(rgba, 32);
76 out = spu_shuffle(out, out, shuffle);
77 return spu_extract(out, 0);
78 }
79
80
81 static INLINE vector float
82 spu_unpack_color(uint color)
83 {
84 vector unsigned int color_u4 = spu_splats(color);
85 color_u4 = spu_shuffle(color_u4, color_u4,
86 ((vector unsigned char) {
87 0, 0, 0, 0,
88 5, 5, 5, 5,
89 10, 10, 10, 10,
90 15, 15, 15, 15}) );
91 return spu_convtf(color_u4, 32);
92 }
93
94
95 static INLINE vector float
96 spu_unpack_A8R8G8B8(uint color)
97 {
98 vector unsigned int color_u4 = spu_splats(color);
99 color_u4 = spu_shuffle(color_u4, color_u4,
100 ((vector unsigned char) {
101 5, 5, 5, 5,
102 10, 10, 10, 10,
103 15, 15, 15, 15,
104 0, 0, 0, 0}) );
105
106 return spu_convtf(color_u4, 32);
107 }
108
109
110 #endif /* SPU_COLORPACK_H */