2 * Fast C2P (Chunky-to-Planar) Conversion
5 * - This code was inspired by Scout's C2P tutorial
6 * - It assumes to run on a big endian system
8 * Copyright © 2003-2008 Geert Uytterhoeven
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice (including the next
18 * paragraph) shall be included in all copies or substantial portions of the
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
32 * Basic transpose step
35 static inline void _transp(CARD32 d
[], unsigned int i1
, unsigned int i2
,
36 unsigned int shift
, CARD32 mask
)
38 CARD32 t
= (d
[i1
] ^ (d
[i2
] >> shift
)) & mask
;
45 static inline void c2p_unsupported(void) {
49 static inline CARD32
get_mask(unsigned int n
)
74 * Transpose operations on 8 32-bit words
77 static inline void transp8(CARD32 d
[], unsigned int n
, unsigned int m
)
79 CARD32 mask
= get_mask(n
);
83 /* First n x 1 block */
84 _transp(d
, 0, 1, n
, mask
);
85 /* Second n x 1 block */
86 _transp(d
, 2, 3, n
, mask
);
87 /* Third n x 1 block */
88 _transp(d
, 4, 5, n
, mask
);
89 /* Fourth n x 1 block */
90 _transp(d
, 6, 7, n
, mask
);
94 /* First n x 2 block */
95 _transp(d
, 0, 2, n
, mask
);
96 _transp(d
, 1, 3, n
, mask
);
97 /* Second n x 2 block */
98 _transp(d
, 4, 6, n
, mask
);
99 _transp(d
, 5, 7, n
, mask
);
103 /* Single n x 4 block */
104 _transp(d
, 0, 4, n
, mask
);
105 _transp(d
, 1, 5, n
, mask
);
106 _transp(d
, 2, 6, n
, mask
);
107 _transp(d
, 3, 7, n
, mask
);
116 * Transpose operations on 4 32-bit words
119 static inline void transp4(CARD32 d
[], unsigned int n
, unsigned int m
)
121 CARD32 mask
= get_mask(n
);
125 /* First n x 1 block */
126 _transp(d
, 0, 1, n
, mask
);
127 /* Second n x 1 block */
128 _transp(d
, 2, 3, n
, mask
);
132 /* Single n x 2 block */
133 _transp(d
, 0, 2, n
, mask
);
134 _transp(d
, 1, 3, n
, mask
);
143 * Transpose operations on 4 32-bit words (reverse order)
146 static inline void transp4x(CARD32 d
[], unsigned int n
, unsigned int m
)
148 CARD32 mask
= get_mask(n
);
152 /* Single n x 2 block */
153 _transp(d
, 2, 0, n
, mask
);
154 _transp(d
, 3, 1, n
, mask
);
163 * Transpose operations on 2 32-bit words
166 static inline void transp2(CARD32 d
[], unsigned int n
)
168 CARD32 mask
= get_mask(n
);
170 /* Single n x 1 block */
171 _transp(d
, 0, 1, n
, mask
);
177 * Transpose operations on 2 32-bit words (reverse order)
180 static inline void transp2x(CARD32 d
[], unsigned int n
)
182 CARD32 mask
= get_mask(n
);
184 /* Single n x 1 block */
185 _transp(d
, 1, 0, n
, mask
);