source: trunk/lib/p2s.h @ 1580

Last change on this file since 1580 was 623, checked in by cameron, 9 years ago

fix s2p -> p2s

File size: 4.6 KB
Line 
1/*  p2s - Serial to Parallel Bit Stream Transposition
2    Copyright (c) 2007, 2008, 2010, Robert D. Cameron.
3    Licensed to the public under the Open Software License 3.0.
4*/
5
6#ifndef P2S_H
7#define P2S_H
8
9#define BytePack SIMD_type
10#define BitBlock SIMD_type
11
12
13/*
14/* Given 8 parallel bitstream blocks p0, p1, ..., p7, inverse transpose
15   the data into a block of bytes in 8 consecutive registers s0, s1, ..., s7.
16
17   The following header shows the intent, although a macro is used for
18   speed.
19static inline void p2s(BitBlock p0, BitBlock p1, BitBlock p2, BitBlock p3,
20                       BitBlock p4, BitBlock p5, BitBlock p6, BitBlock p7,
21                       BytePack& s0, BytePack& s1, BytePack& s2, BytePack& s3,
22                       BytePack& s5, BytePack& s6, BytePack& s7, BytePack& s8,
23                       );
24
25*/
26
27/* Different algorithms may be selected. */
28#ifdef USE_P2S_IDEAL
29#define P2S_ALGORITHM p2s_ideal
30#endif
31
32#ifndef P2S_ALGORITHM
33#define P2S_ALGORITHM p2s_bytemerge
34#endif
35
36
37
38/*  p2s_ideal is an ideal parallel to serial transposition
39    algorithm given an architecture with native support for
40    simd_merge{h,l}_{8,4,2} operations, achieving transposition
41    of 8 parallel bitblocks into 8 serial bytepacks in only 24 merge
42    operations.
43*/
44
45
46#define p2s_ideal(p0,p1,p2,p3,p4,p5,p6,p7,s0,s1,s2,s3,s4,s5,s6,s7)  \
47  do { \
48        BitBlock bit01_r0,bit01_r1,bit23_r0,bit23_r1,bit45_r0,bit45_r1,bit67_r0,bit67_r1; \
49        BitBlock bit0123_r0,bit0123_r1,bit0123_r2,bit0123_r3, \
50        bit4567_r0,bit4567_r1,bit4567_r2,bit4567_r3; \
51        bit01_r0= simd_mergeh_1(p0,p1) ; \
52        bit01_r1= simd_mergel_1(p0,p1) ; \
53        bit23_r0= simd_mergeh_1(p2,p3) ; \
54        bit23_r1= simd_mergel_1(p2,p3) ; \
55        bit45_r0= simd_mergeh_1(p4,p5) ; \
56        bit45_r1= simd_mergel_1(p4,p5) ; \
57        bit67_r0= simd_mergeh_1(p6,p7) ; \
58        bit67_r1= simd_mergel_1(p6,p7) ; \
59        bit0123_r0= simd_mergeh_2(bit01_r0,bit23_r0) ; \
60        bit0123_r1= simd_mergel_2(bit01_r0,bit23_r0) ; \
61        bit0123_r2= simd_mergeh_2(bit01_r1,bit23_r1) ; \
62        bit0123_r3= simd_mergel_2(bit01_r1,bit23_r1) ; \
63        bit4567_r0= simd_mergeh_2(bit45_r0,bit67_r0) ; \
64        bit4567_r1= simd_mergel_2(bit45_r0,bit67_r0) ; \
65        bit4567_r2= simd_mergeh_2(bit45_r1,bit67_r1) ; \
66        bit4567_r3= simd_mergel_2(bit45_r1,bit67_r1) ; \
67        s0= simd_mergeh_4(bit0123_r0,bit4567_r0) ; \
68        s1= simd_mergel_4(bit0123_r0,bit4567_r0) ; \
69        s2= simd_mergeh_4(bit0123_r1,bit4567_r1) ; \
70        s3= simd_mergel_4(bit0123_r1,bit4567_r1) ; \
71        s4= simd_mergeh_4(bit0123_r2,bit4567_r2) ; \
72        s5= simd_mergel_4(bit0123_r2,bit4567_r2) ; \
73        s6= simd_mergeh_4(bit0123_r3,bit4567_r3) ; \
74        s7= simd_mergel_4(bit0123_r3,bit4567_r3) ; \
75  } while(0)
76
77/*  p2s_bytemerge is a fast parallel to serial transposition
78    algorithm given an architecture with simd_merge{h,l}_8 operations,
79    but not at small field widths.
80    MMX, SSE, Altivec ...
81*/
82 
83#define p2s_step(p0,p1,hi_mask,shift,s0,s1)  \
84  do { \
85        BitBlock t0,t1; \
86        t0= simd_if(hi_mask,p0,simd_srli_16(p1,shift) ) ; \
87        t1= simd_if(hi_mask,simd_slli_16(p0,shift) ,p1) ; \
88        s0= simd_mergeh_8(t0,t1) ; \
89        s1= simd_mergel_8(t0,t1) ; \
90  } while(0)
91
92#define p2s_bytemerge(p0,p1,p2,p3,p4,p5,p6,p7,s0,s1,s2,s3,s4,s5,s6,s7)  \
93  do { \
94        BitBlock bit00004444_0,bit22226666_0,bit00004444_1,bit22226666_1; \
95        BitBlock bit11115555_0,bit33337777_0,bit11115555_1,bit33337777_1; \
96        BitBlock bit00224466_0,bit00224466_1,bit00224466_2,bit00224466_3; \
97        BitBlock bit11335577_0,bit11335577_1,bit11335577_2,bit11335577_3; \
98        p2s_step(p0,p4,simd_himask_8,4,bit00004444_0,bit00004444_1);  \
99        p2s_step(p1,p5,simd_himask_8,4,bit11115555_0,bit11115555_1);  \
100        p2s_step(p2,p6,simd_himask_8,4,bit22226666_0,bit22226666_1);  \
101        p2s_step(p3,p7,simd_himask_8,4,bit33337777_0,bit33337777_1);  \
102        p2s_step(bit00004444_0,bit22226666_0,simd_himask_4,2,bit00224466_0,bit00224466_1);  \
103        p2s_step(bit11115555_0,bit33337777_0,simd_himask_4,2,bit11335577_0,bit11335577_1);  \
104        p2s_step(bit00004444_1,bit22226666_1,simd_himask_4,2,bit00224466_2,bit00224466_3);  \
105        p2s_step(bit11115555_1,bit33337777_1,simd_himask_4,2,bit11335577_2,bit11335577_3);  \
106        p2s_step(bit00224466_0,bit11335577_0,simd_himask_2,1,s0,s1);  \
107        p2s_step(bit00224466_1,bit11335577_1,simd_himask_2,1,s2,s3);  \
108        p2s_step(bit00224466_2,bit11335577_2,simd_himask_2,1,s4,s5);  \
109        p2s_step(bit00224466_3,bit11335577_3,simd_himask_2,1,s6,s7);  \
110  } while(0)
111
112#if (BYTE_ORDER == BIG_ENDIAN)
113#define p2s(p0, p1, p2, p3, p4, p5, p6, p7, s0, s1, s2, s3, s4, s5, s6, s7)\
114  P2S_ALGORITHM(p0, p1, p2, p3, p4, p5, p6, p7, s0, s1, s2, s3, s4, s5, s6, s7)
115#endif
116#if (BYTE_ORDER == LITTLE_ENDIAN)
117#define p2s(p0, p1, p2, p3, p4, p5, p6, p7, s0, s1, s2, s3, s4, s5, s6, s7)\
118  P2S_ALGORITHM(p0, p1, p2, p3, p4, p5, p6, p7, s7, s6, s5, s4, s3, s2, s1, s0)
119#endif
120
121#endif
122
Note: See TracBrowser for help on using the repository browser.