Debian Codegraph @

src/bitshuffle_core.h

raw
1 /*
2 * Bitshuffle - Filter for improving compression of typed binary data.
3 *
4 * This file is part of Bitshuffle
5 * Author: Kiyoshi Masui <[email protected]>
6 * Website: https://www.github.com/kiyo-masui/bitshuffle
7 * Created: 2014
8 *
9 * See LICENSE file for details about copyright and rights to use.
10 *
11 *
12 * Header File
13 *
14 * Worker routines return an int64_t which is the number of bytes processed
15 * if positive or an error code if negative.
16 *
17 * Error codes:
18 * -1 : Failed to allocate memory.
19 * -11 : Missing SSE.
20 * -12 : Missing AVX.
21 * -13 : Missing Arm Neon.
22 * -14 : Missing AVX512.
23 * -80 : Input size not a multiple of 8.
24 * -81 : block_size not multiple of 8.
25 * -91 : Decompression error, wrong number of bytes processed.
26 * -1YYY : Error internal to compression routine with error code -YYY.
27 */
28
29
30 #ifndef BITSHUFFLE_CORE_H
31 #define BITSHUFFLE_CORE_H
32
33 // We assume GNU g++ defining `__cplusplus` has stdint.h
34 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199900L) || defined(__cplusplus)
35 #include <stdint.h>
36 #else
37 typedef unsigned char uint8_t;
38 typedef unsigned short uint16_t;
39 typedef unsigned int uint32_t;
40 typedef signed int int32_t;
41 typedef unsigned long long uint64_t;
42 typedef long long int64_t;
43 #endif
44
45 #include <stdlib.h>
46
47
48 // These are usually set in the setup.py.
49 #ifndef BSHUF_VERSION_MAJOR
50 #define BSHUF_VERSION_MAJOR 0
51 #define BSHUF_VERSION_MINOR 4
52 #define BSHUF_VERSION_POINT 0
53 #endif
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* --- bshuf_using_SSE2 ----
60 *
61 * Whether routines where compiled with the SSE2 instruction set.
62 *
63 * Returns
64 * -------
65 * 1 if using SSE2, 0 otherwise.
66 *
67 */
68 int bshuf_using_SSE2(void);
69
70
71 /* ---- bshuf_using_NEON ----
72 *
73 * Whether routines where compiled with the NEON instruction set.
74 *
75 * Returns
76 * -------
77 * 1 if using NEON, 0 otherwise.
78 *
79 */
80 int bshuf_using_NEON(void);
81
82
83 /* ---- bshuf_using_AVX2 ----
84 *
85 * Whether routines where compiled with the AVX2 instruction set.
86 *
87 * Returns
88 * -------
89 * 1 if using AVX2, 0 otherwise.
90 *
91 */
92 int bshuf_using_AVX2(void);
93
94
95 /* ---- bshuf_using_AVX512 ----
96 *
97 * Whether routines where compiled with the AVX512 instruction set.
98 *
99 * Returns
100 * -------
101 * 1 if using AVX512, 0 otherwise.
102 *
103 */
104 int bshuf_using_AVX512(void);
105
106
107 /* ---- bshuf_default_block_size ----
108 *
109 * The default block size as function of element size.
110 *
111 * This is the block size used by the blocked routines (any routine
112 * taking a *block_size* argument) when the block_size is not provided
113 * (zero is passed).
114 *
115 * The results of this routine are guaranteed to be stable such that
116 * shuffled/compressed data can always be decompressed.
117 *
118 * Parameters
119 * ----------
120 * elem_size : element size of data to be shuffled/compressed.
121 *
122 */
123 size_t bshuf_default_block_size(const size_t elem_size);
124
125
126 /* ---- bshuf_bitshuffle ----
127 *
128 * Bitshuffle the data.
129 *
130 * Transpose the bits within elements, in blocks of *block_size*
131 * elements.
132 *
133 * Parameters
134 * ----------
135 * in : input buffer, must be of size * elem_size bytes
136 * out : output buffer, must be of size * elem_size bytes
137 * size : number of elements in input
138 * elem_size : element size of typed data
139 * block_size : Do transpose in blocks of this many elements. Pass 0 to
140 * select automatically (recommended).
141 *
142 * Returns
143 * -------
144 * number of bytes processed, negative error-code if failed.
145 *
146 */
147 int64_t bshuf_bitshuffle(const void* in, void* out, const size_t size,
148 const size_t elem_size, size_t block_size);
149
150
151 /* ---- bshuf_bitunshuffle ----
152 *
153 * Unshuffle bitshuffled data.
154 *
155 * Untranspose the bits within elements, in blocks of *block_size*
156 * elements.
157 *
158 * To properly unshuffle bitshuffled data, *size*, *elem_size* and *block_size*
159 * must match the parameters used to shuffle the data.
160 *
161 * Parameters
162 * ----------
163 * in : input buffer, must be of size * elem_size bytes
164 * out : output buffer, must be of size * elem_size bytes
165 * size : number of elements in input
166 * elem_size : element size of typed data
167 * block_size : Do transpose in blocks of this many elements. Pass 0 to
168 * select automatically (recommended).
169 *
170 * Returns
171 * -------
172 * number of bytes processed, negative error-code if failed.
173 *
174 */
175 int64_t bshuf_bitunshuffle(const void* in, void* out, const size_t size,
176 const size_t elem_size, size_t block_size);
177
178 #ifdef __cplusplus
179 } // extern "C"
180 #endif
181
182 #endif // BITSHUFFLE_CORE_H