source: trunk/lib/s2p.h @ 612

Last change on this file since 612 was 612, checked in by lindanl, 9 years ago

Add s2p.h

File size: 4.6 KB
Line 
1/*  s2p - 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 S2P_H
7#define S2P_H
8
9#define BytePack SIMD_type
10#define BitBlock SIMD_type
11
12static inline void s2p(BytePack s0, BytePack s1, BytePack s2, BytePack s3,
13                       BytePack s5, BytePack s6, BytePack s7, BytePack s8,
14                       BitBlock& p0, BitBlock& p1, BitBlock& p2, BitBlock& p3, 
15                       BitBlock& p4, BitBlock& p5, BitBlock& p6, BitBlock& p7);
16
17
18/* Different algorithms may be selected. */
19#ifdef USE_S2P_IDEAL
20#define S2P_ALGORITHM s2p_ideal
21#endif
22
23#ifdef USE_S2P_MOVEMASK
24#define S2P_ALGORITHM s2p_movemask  /* Not yet implemented. */
25#endif
26
27#ifndef S2P_ALGORITHM
28#define S2P_ALGORITHM s2p_bytepack
29#endif
30
31
32
33/*  s2p_ideal is an ideal serial to parallel transposition
34    algorithm given an architecture with native support for
35    simd_pack_{8,4,2}_{hh,ll} operations, achieving transposition
36    of 8 serial bytepacks into 8 parallel bitblocks in only 24 pack
37    operations.
38*/
39
40#define s2p_ideal(s0, s1, s2, s3, s4, s5, s6, s7, p0, p1, p2, p3, p4, p5, p6, p7) \
41  do {\
42        BitBlock bit0123_0, bit0123_1, bit0123_2, bit0123_3,\
43        bit4567_0, bit4567_1, bit4567_2, bit4567_3;\
44        BitBlock bit01_0, bit01_1, bit23_0, bit23_1, bit45_0, bit45_1, bit67_0, bit67_1;\
45        bit0123_0 = simd_pack_8_hh(s0, s1);\
46        bit0123_1 = simd_pack_8_hh(s2, s3);\
47        bit0123_2 = simd_pack_8_hh(s4, s5);\
48        bit0123_3 = simd_pack_8_hh(s6, s7);\
49        bit4567_0 = simd_pack_8_ll(s0, s1);\
50        bit4567_1 = simd_pack_8_ll(s2, s3);\
51        bit4567_2 = simd_pack_8_ll(s4, s5);\
52        bit4567_3 = simd_pack_8_ll(s6, s7);\
53        bit01_0 = simd_pack_4_hh(bit0123_0, bit0123_1);\
54        bit01_1 = simd_pack_4_hh(bit0123_2, bit0123_3);\
55        bit23_0 = simd_pack_4_ll(bit0123_0, bit0123_1);\
56        bit23_1 = simd_pack_4_ll(bit0123_2, bit0123_3);\
57        bit45_0 = simd_pack_4_hh(bit4567_0, bit4567_1);\
58        bit45_1 = simd_pack_4_hh(bit4567_2, bit4567_3);\
59        bit67_0 = simd_pack_4_ll(bit4567_0, bit4567_1);\
60        bit67_1 = simd_pack_4_ll(bit4567_2, bit4567_3);\
61        p0 = simd_pack_2_hh(bit01_0, bit01_1);\
62        p1 = simd_pack_2_ll(bit01_0, bit01_1);\
63        p2 = simd_pack_2_hh(bit23_0, bit23_1);\
64        p3 = simd_pack_2_ll(bit23_0, bit23_1);\
65        p4 = simd_pack_2_hh(bit45_0, bit45_1);\
66        p5 = simd_pack_2_ll(bit45_0, bit45_1);\
67        p6 = simd_pack_2_hh(bit67_0, bit67_1);\
68        p7 = simd_pack_2_ll(bit67_0, bit67_1);\
69  } while(0)
70
71
72/*  s2p_bytepack is a fast serial to parallel transposition
73    algorithm given an architecture with simd_pack_16 operations,
74    but not at small field widths.
75    MMX, SSE, Altivec ...
76*/
77
78#define s2p_step(s0, s1, hi_mask, shift, p0, p1)  \
79  do {\
80        BitBlock t0,t1;\
81        t0 = simd_pack_16_hh(s0, s1);\
82        t1 = simd_pack_16_ll(s0, s1);\
83        p0 = simd_if(hi_mask, t0, simd_srli_16(t1, shift));\
84        p1 = simd_if(hi_mask, simd_slli_16(t0, shift), t1);\
85  } while(0)
86
87#define s2p_bytepack(s0, s1, s2, s3, s4, s5, s6, s7, p0, p1, p2, p3, p4, p5, p6, p7) \
88  do {\
89        BitBlock bit00224466_0,bit00224466_1,bit00224466_2,bit00224466_3;\
90        BitBlock bit11335577_0,bit11335577_1,bit11335577_2,bit11335577_3;\
91        BitBlock bit00004444_0,bit22226666_0,bit00004444_1,bit22226666_1;\
92        BitBlock bit11115555_0,bit33337777_0,bit11115555_1,bit33337777_1;\
93        s2p_step(s0,s1,simd_himask_2,1,bit00224466_0,bit11335577_0);\
94        s2p_step(s2,s3,simd_himask_2,1,bit00224466_1,bit11335577_1);\
95        s2p_step(s4,s5,simd_himask_2,1,bit00224466_2,bit11335577_2);\
96        s2p_step(s6,s7,simd_himask_2,1,bit00224466_3,bit11335577_3);\
97        s2p_step(bit00224466_0,bit00224466_1,simd_himask_4,2,bit00004444_0,bit22226666_0);\
98        s2p_step(bit00224466_2,bit00224466_3,simd_himask_4,2,bit00004444_1,bit22226666_1);\
99        s2p_step(bit11335577_0,bit11335577_1,simd_himask_4,2,bit11115555_0,bit33337777_0);\
100        s2p_step(bit11335577_2,bit11335577_3,simd_himask_4,2,bit11115555_1,bit33337777_1);\
101        s2p_step(bit00004444_0,bit00004444_1,simd_himask_8,4,p0,p4);\
102        s2p_step(bit11115555_0,bit11115555_1,simd_himask_8,4,p1,p5);\
103        s2p_step(bit22226666_0,bit22226666_1,simd_himask_8,4,p2,p6);\
104        s2p_step(bit33337777_0,bit33337777_1,simd_himask_8,4,p3,p7);\
105  } while(0)
106
107
108
109inline void s2p(BytePack s0, BytePack s1, BytePack s2, BytePack s3,
110                       BytePack s4, BytePack s5, BytePack s6, BytePack s7,
111                       BitBlock& p0, BitBlock& p1, BitBlock& p2, BitBlock& p3, 
112                       BitBlock& p4, BitBlock& p5, BitBlock& p6, BitBlock& p7) {
113
114#if (BYTE_ORDER == BIG_ENDIAN)
115  S2P_ALGORITHM(s0, s1, s2, s3, s4, s5, s6, s7, p0, p1, p2, p3, p4, p5, p6, p7);
116#endif
117#if (BYTE_ORDER == LITTLE_ENDIAN)
118  S2P_ALGORITHM(s7, s6, s5, s4, s3, s2, s1, s0, p0, p1, p2, p3, p4, p5, p6, p7);
119#endif
120}
121
122#endif
123
Note: See TracBrowser for help on using the repository browser.