2 * Fast C2P (Chunky-to-Planar) Conversion
4 * Copyright (C) 2003-2008 Geert Uytterhoeven
7 * - This code was inspired by Scout's C2P tutorial
8 * - It assumes to run on a big endian system
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive
15 #include <linux/build_bug.h>
19 * Basic transpose step
22 static inline void _transp(u32 d
[], unsigned int i1
, unsigned int i2
,
23 unsigned int shift
, u32 mask
)
25 u32 t
= (d
[i1
] ^ (d
[i2
] >> shift
)) & mask
;
32 static __always_inline u32
get_mask(unsigned int n
)
57 * Transpose operations on 8 32-bit words
60 static __always_inline
void transp8(u32 d
[], unsigned int n
, unsigned int m
)
62 u32 mask
= get_mask(n
);
66 /* First n x 1 block */
67 _transp(d
, 0, 1, n
, mask
);
68 /* Second n x 1 block */
69 _transp(d
, 2, 3, n
, mask
);
70 /* Third n x 1 block */
71 _transp(d
, 4, 5, n
, mask
);
72 /* Fourth n x 1 block */
73 _transp(d
, 6, 7, n
, mask
);
77 /* First n x 2 block */
78 _transp(d
, 0, 2, n
, mask
);
79 _transp(d
, 1, 3, n
, mask
);
80 /* Second n x 2 block */
81 _transp(d
, 4, 6, n
, mask
);
82 _transp(d
, 5, 7, n
, mask
);
86 /* Single n x 4 block */
87 _transp(d
, 0, 4, n
, mask
);
88 _transp(d
, 1, 5, n
, mask
);
89 _transp(d
, 2, 6, n
, mask
);
90 _transp(d
, 3, 7, n
, mask
);
99 * Transpose operations on 4 32-bit words
102 static __always_inline
void transp4(u32 d
[], unsigned int n
, unsigned int m
)
104 u32 mask
= get_mask(n
);
108 /* First n x 1 block */
109 _transp(d
, 0, 1, n
, mask
);
110 /* Second n x 1 block */
111 _transp(d
, 2, 3, n
, mask
);
115 /* Single n x 2 block */
116 _transp(d
, 0, 2, n
, mask
);
117 _transp(d
, 1, 3, n
, mask
);
126 * Transpose operations on 4 32-bit words (reverse order)
129 static __always_inline
void transp4x(u32 d
[], unsigned int n
, unsigned int m
)
131 u32 mask
= get_mask(n
);
135 /* Single n x 2 block */
136 _transp(d
, 2, 0, n
, mask
);
137 _transp(d
, 3, 1, n
, mask
);
146 * Compose two values, using a bitmask as decision value
147 * This is equivalent to (a & mask) | (b & ~mask)
150 static inline u32
comp(u32 a
, u32 b
, u32 mask
)
152 return ((a
^ b
) & mask
) ^ b
;