File: bitshuffle-generic.h

package info (click to toggle)
c-blosc 1.21.5%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,564 kB
  • sloc: ansic: 7,675; python: 240; makefile: 61; sh: 3
file content (161 lines) | stat: -rw-r--r-- 6,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*********************************************************************
  Blosc - Blocked Shuffling and Compression Library

  Author: Francesc Alted <francesc@blosc.org>

  See LICENSE.txt for details about copyright and rights to use.
**********************************************************************/

/* Generic (non-hardware-accelerated) shuffle/unshuffle routines.
   These are used when hardware-accelerated functions aren't available
   for a particular platform; they are also used by the hardware-
   accelerated functions to handle any remaining elements in a block
   which isn't a multiple of the hardware's vector size. */

#ifndef BITSHUFFLE_GENERIC_H
#define BITSHUFFLE_GENERIC_H

#include "blosc-common.h"
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif


/*  Macros. */
#define CHECK_MULT_EIGHT(n) if (n % 8) return -80;
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
#define CHECK_ERR(count) if (count < 0) { return count; }


/* ---- Worker code not requiring special instruction sets. ----
 *
 * The following code does not use any x86 specific vectorized instructions
 * and should compile on any machine
 *
 */

/* Transpose 8x8 bit array packed into a single quadword *x*.
 * *t* is workspace. */
#define TRANS_BIT_8X8(x, t) {                                               \
        t = (x ^ (x >> 7)) & 0x00AA00AA00AA00AALL;                          \
        x = x ^ t ^ (t << 7);                                               \
        t = (x ^ (x >> 14)) & 0x0000CCCC0000CCCCLL;                         \
        x = x ^ t ^ (t << 14);                                              \
        t = (x ^ (x >> 28)) & 0x00000000F0F0F0F0LL;                         \
        x = x ^ t ^ (t << 28);                                              \
    }

/* Transpose 8x8 bit array along the diagonal from upper right
   to lower left */
#define TRANS_BIT_8X8_BE(x, t) {                                            \
        t = (x ^ (x >> 9)) & 0x0055005500550055LL;                          \
        x = x ^ t ^ (t << 9);                                               \
        t = (x ^ (x >> 18)) & 0x0000333300003333LL;                         \
        x = x ^ t ^ (t << 18);                                              \
        t = (x ^ (x >> 36)) & 0x000000000F0F0F0FLL;                         \
        x = x ^ t ^ (t << 36);                                              \
    }

/* Transpose of an array of arbitrarily typed elements. */
#define TRANS_ELEM_TYPE(in, out, lda, ldb, type_t) {                        \
        type_t* in_type = (type_t*) in;                                     \
        type_t* out_type = (type_t*) out;                                   \
        size_t ii, jj, kk;                                                  \
        for (ii = 0; ii + 7 < lda; ii += 8) {                               \
            for (jj = 0; jj < ldb; jj++) {                                  \
                for (kk = 0; kk < 8; kk++) {                                \
                    out_type[jj*lda + ii + kk] =                            \
                        in_type[ii*ldb + kk * ldb + jj];                    \
                }                                                           \
            }                                                               \
        }                                                                   \
        for (ii = lda - lda % 8; ii < lda; ii ++) {                         \
            for (jj = 0; jj < ldb; jj++) {                                  \
                out_type[jj*lda + ii] = in_type[ii*ldb + jj];               \
            }                                                               \
        }                                                                   \
    }


/* Private functions */
BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_trans_byte_elem_remainder(const void* in, void* out, const size_t size,
                                               const size_t elem_size, const size_t start);

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_trans_byte_elem_scal(const void* in, void* out, const size_t size,
                                          const size_t elem_size);

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_trans_bit_byte_remainder(const void* in, void* out, const size_t size,
                                              const size_t elem_size, const size_t start_byte);

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_trans_elem(const void* in, void* out, const size_t lda,
                                const size_t ldb, const size_t elem_size);

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_trans_bitrow_eight(const void* in, void* out, const size_t size,
                                        const size_t elem_size);

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_shuffle_bit_eightelem_scal(const void* in, void* out,
                                                const size_t size, const size_t elem_size);


/* Bitshuffle the data.
 *
 * Transpose the bits within elements.
 *
 * Parameters
 * ----------
 *  in : input buffer, must be of size * elem_size bytes
 *  out : output buffer, must be of size * elem_size bytes
 *  size : number of elements in input
 *  elem_size : element size of typed data
 *  tmp_buffer : temporary buffer with the same `size` than `in` and `out`
 *
 * Returns
 * -------
 *  nothing -- this cannot fail
 *
 */

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_trans_bit_elem_scal(const void* in, void* out, const size_t size,
                                         const size_t elem_size, void* tmp_buf);

/* Unshuffle bitshuffled data.
 *
 * Untranspose the bits within elements.
 *
 * To properly unshuffle bitshuffled data, *size* and *elem_size* must
 * match the parameters used to shuffle the data.
 *
 * Parameters
 * ----------
 *  in : input buffer, must be of size * elem_size bytes
 *  out : output buffer, must be of size * elem_size bytes
 *  size : number of elements in input
 *  elem_size : element size of typed data
 *  tmp_buffer : temporary buffer with the same `size` than `in` and `out`
 *
 * Returns
 * -------
 *  nothing -- this cannot fail
 *
 */

BLOSC_NO_EXPORT int64_t
blosc_internal_bshuf_untrans_bit_elem_scal(const void* in, void* out, const size_t size,
                                           const size_t elem_size, void* tmp_buf);


#ifdef __cplusplus
}
#endif

#endif /* BITSHUFFLE_GENERIC_H */