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

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

Upgrade to latest blosc library

blosc git: e394f327ccc78319d90a06af0b88bce07034b8dd

  • Property mode set to 100644
Line 
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 SHUFFLE_GENERIC_H
16#define SHUFFLE_GENERIC_H
17
18#include "shuffle-common.h"
19#include <stdlib.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25/**
26  Generic (non-hardware-accelerated) shuffle routine.
27  This is the pure element-copying nested loop. It is used by the
28  generic shuffle implementation and also by the vectorized shuffle
29  implementations to process any remaining elements in a block which
30  is not a multiple of (type_size * vector_size).
31*/
32static void shuffle_generic_inline(const size_t type_size,
33    const size_t vectorizable_blocksize, const size_t blocksize,
34    const uint8_t* const _src, uint8_t* const _dest)
35{
36  size_t i, j;
37  /* Calculate the number of elements in the block. */
38  const size_t neblock_quot = blocksize / type_size;
39  const size_t neblock_rem = blocksize % type_size;
40  const size_t vectorizable_elements = vectorizable_blocksize / type_size;
41
42
43  /* Non-optimized shuffle */
44  for (j = 0; j < type_size; j++) {
45    for (i = vectorizable_elements; i < (size_t)neblock_quot; i++) {
46      _dest[j*neblock_quot+i] = _src[i*type_size+j];
47    }
48  }
49
50  /* Copy any leftover bytes in the block without shuffling them. */
51  memcpy(_dest + (blocksize - neblock_rem), _src + (blocksize - neblock_rem), neblock_rem);
52}
53
54/**
55  Generic (non-hardware-accelerated) unshuffle routine.
56  This is the pure element-copying nested loop. It is used by the
57  generic unshuffle implementation and also by the vectorized unshuffle
58  implementations to process any remaining elements in a block which
59  is not a multiple of (type_size * vector_size).
60*/
61static void unshuffle_generic_inline(const size_t type_size,
62  const size_t vectorizable_blocksize, const size_t blocksize,
63  const uint8_t* const _src, uint8_t* const _dest)
64{
65  size_t i, j;
66
67  /* Calculate the number of elements in the block. */
68  const size_t neblock_quot = blocksize / type_size;
69  const size_t neblock_rem = blocksize % type_size;
70  const size_t vectorizable_elements = vectorizable_blocksize / type_size;
71
72  /* Non-optimized unshuffle */
73  for (i = vectorizable_elements; i < (size_t)neblock_quot; i++) {
74    for (j = 0; j < type_size; j++) {
75      _dest[i*type_size+j] = _src[j*neblock_quot+i];
76    }
77  }
78
79  /* Copy any leftover bytes in the block without unshuffling them. */
80  memcpy(_dest + (blocksize - neblock_rem), _src + (blocksize - neblock_rem), neblock_rem);
81}
82
83/**
84  Generic (non-hardware-accelerated) shuffle routine.
85*/
86BLOSC_NO_EXPORT void shuffle_generic(const size_t bytesoftype, const size_t blocksize,
87                                      const uint8_t* const _src, uint8_t* const _dest);
88
89/**
90  Generic (non-hardware-accelerated) unshuffle routine.
91*/
92BLOSC_NO_EXPORT void unshuffle_generic(const size_t bytesoftype, const size_t blocksize,
93                                        const uint8_t* const _src, uint8_t* const _dest);
94
95#ifdef __cplusplus
96}
97#endif
98
99#endif /* SHUFFLE_GENERIC_H */
Note: See TracBrowser for help on using the repository browser.