source: thirdparty/blosc/bitshuffle-generic.h @ 981e22c

Revision 981e22c, 5.4 KB checked in by Hal Finkel <hfinkel@…>, 8 years ago (diff)

Upgrade to latest blosc library

blosc git: e394f327ccc78319d90a06af0b88bce07034b8dd

  • Property mode set to 100644
RevLine 
[981e22c]1/*********************************************************************
2  Blosc - Blocked Shuffling and Compression Library
3
4  Author: Francesc Alted <[email protected]>
5
6  See LICENSES/BLOSC.txt for details about copyright and rights to use.
7**********************************************************************/
8
9/* Generic (non-hardware-accelerated) shuffle/unshuffle routines.
10   These are used when hardware-accelerated functions aren't available
11   for a particular platform; they are also used by the hardware-
12   accelerated functions to handle any remaining elements in a block
13   which isn't a multiple of the hardware's vector size. */
14
15#ifndef BITSHUFFLE_GENERIC_H
16#define BITSHUFFLE_GENERIC_H
17
18#include "shuffle-common.h"
19#include <stdlib.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25
26/*  Macros. */
27#define CHECK_MULT_EIGHT(n) if (n % 8) return -80;
28#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
29#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
30#define CHECK_ERR(count) if (count < 0) { return count; }
31
32
33/* ---- Worker code not requiring special instruction sets. ----
34 *
35 * The following code does not use any x86 specific vectorized instructions
36 * and should compile on any machine
37 *
38 */
39
40/* Transpose 8x8 bit array packed into a single quadword *x*.
41 * *t* is workspace. */
42#define TRANS_BIT_8X8(x, t) {                                               \
43        t = (x ^ (x >> 7)) & 0x00AA00AA00AA00AALL;                          \
44        x = x ^ t ^ (t << 7);                                               \
45        t = (x ^ (x >> 14)) & 0x0000CCCC0000CCCCLL;                         \
46        x = x ^ t ^ (t << 14);                                              \
47        t = (x ^ (x >> 28)) & 0x00000000F0F0F0F0LL;                         \
48        x = x ^ t ^ (t << 28);                                              \
49    }
50
51
52/* Transpose of an array of arbitrarily typed elements. */
53#define TRANS_ELEM_TYPE(in, out, lda, ldb, type_t) {                        \
54        type_t* in_type = (type_t*) in;                                     \
55        type_t* out_type = (type_t*) out;                                   \
56        size_t ii, jj, kk;                                                  \
57        for (ii = 0; ii + 7 < lda; ii += 8) {                               \
58            for (jj = 0; jj < ldb; jj++) {                                  \
59                for (kk = 0; kk < 8; kk++) {                                \
60                    out_type[jj*lda + ii + kk] =                            \
61                        in_type[ii*ldb + kk * ldb + jj];                    \
62                }                                                           \
63            }                                                               \
64        }                                                                   \
65        for (ii = lda - lda % 8; ii < lda; ii ++) {                         \
66            for (jj = 0; jj < ldb; jj++) {                                  \
67                out_type[jj*lda + ii] = in_type[ii*ldb + jj];               \
68            }                                                               \
69        }                                                                   \
70    }
71
72
73/* Private functions */
74BLOSC_NO_EXPORT int64_t
75bshuf_trans_byte_elem_remainder(void* in, void* out, const size_t size,
76                                const size_t elem_size, const size_t start);
77
78BLOSC_NO_EXPORT int64_t
79bshuf_trans_byte_elem_scal(void* in, void* out, const size_t size,
80                           const size_t elem_size);
81
82BLOSC_NO_EXPORT int64_t
83bshuf_trans_bit_byte_remainder(void* in, void* out, const size_t size,
84                               const size_t elem_size, const size_t start_byte);
85
86BLOSC_NO_EXPORT int64_t
87bshuf_trans_elem(void* in, void* out, const size_t lda,
88                 const size_t ldb, const size_t elem_size);
89
90BLOSC_NO_EXPORT int64_t
91bshuf_trans_bitrow_eight(void* in, void* out, const size_t size,
92                         const size_t elem_size);
93
94BLOSC_NO_EXPORT int64_t
95bshuf_shuffle_bit_eightelem_scal(void* in, void* out,
96                                 const size_t size, const size_t elem_size);
97
98
99/* Bitshuffle the data.
100 *
101 * Transpose the bits within elements.
102 *
103 * Parameters
104 * ----------
105 *  in : input buffer, must be of size * elem_size bytes
106 *  out : output buffer, must be of size * elem_size bytes
107 *  size : number of elements in input
108 *  elem_size : element size of typed data
109 *  tmp_buffer : temporary buffer with the same `size` than `in` and `out`
110 *
111 * Returns
112 * -------
113 *  nothing -- this cannot fail
114 *
115 */
116
117BLOSC_NO_EXPORT int64_t
118bshuf_trans_bit_elem_scal(void* in, void* out, const size_t size,
119                          const size_t elem_size, void* tmp_buf);
120
121/* Unshuffle bitshuffled data.
122 *
123 * Untranspose the bits within elements.
124 *
125 * To properly unshuffle bitshuffled data, *size* and *elem_size* must
126 * match the parameters used to shuffle the data.
127 *
128 * Parameters
129 * ----------
130 *  in : input buffer, must be of size * elem_size bytes
131 *  out : output buffer, must be of size * elem_size bytes
132 *  size : number of elements in input
133 *  elem_size : element size of typed data
134 *  tmp_buffer : temporary buffer with the same `size` than `in` and `out`
135 *
136 * Returns
137 * -------
138 *  nothing -- this cannot fail
139 *
140 */
141
142BLOSC_NO_EXPORT int64_t
143bshuf_untrans_bit_elem_scal(void* in, void* out, const size_t size,
144                            const size_t elem_size, void* tmp_buf);
145
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif /* BITSHUFFLE_GENERIC_H */
Note: See TracBrowser for help on using the repository browser.