00001 /* 00002 * Bitshuffle - Filter for improving compression of typed binary data. 00003 * 00004 * This file is part of Bitshuffle 00005 * Author: Kiyoshi Masui <kiyo@physics.ubc.ca> 00006 * Website: http://www.github.com/kiyo-masui/bitshuffle 00007 * Created: 2014 00008 * 00009 * See LICENSE file for details about copyright and rights to use. 00010 * 00011 * 00012 * Header File 00013 * 00014 * Worker routines return an int64_t which is the number of bytes processed 00015 * if positive or an error code if negative. 00016 * 00017 * Error codes: 00018 * -1 : Failed to allocate memory. 00019 * -11 : Missing SSE. 00020 * -12 : Missing AVX. 00021 * -80 : Input size not a multiple of 8. 00022 * -81 : block_size not multiple of 8. 00023 * -91 : Decompression error, wrong number of bytes processed. 00024 * -1YYY : Error internal to compression routine with error code -YYY. 00025 */ 00026 00027 00028 #ifndef BITSHUFFLE_CORE_H 00029 #define BITSHUFFLE_CORE_H 00030 00031 // We assume GNU g++ defining `__cplusplus` has stdint.h 00032 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199900L) || defined(__cplusplus) 00033 #include <stdint.h> 00034 #else 00035 /* 00036 typedef unsigned char uint8_t; 00037 typedef unsigned short uint16_t; 00038 typedef unsigned int uint32_t; 00039 typedef signed int int32_t; 00040 typedef unsigned long long uint64_t; 00041 typedef long long int64_t; 00042 */ 00043 #endif 00044 00045 #include <stdlib.h> 00046 00047 00048 // These are usually set in the setup.py. 00049 #ifndef BSHUF_VERSION_MAJOR 00050 #define BSHUF_VERSION_MAJOR 0 00051 #define BSHUF_VERSION_MINOR 3 00052 #define BSHUF_VERSION_POINT 4 00053 #endif 00054 00055 #ifdef __cplusplus 00056 extern "C" { 00057 #endif 00058 00059 /* --- bshuf_using_SSE2 ---- 00060 * 00061 * Whether routines where compiled with the SSE2 instruction set. 00062 * 00063 * Returns 00064 * ------- 00065 * 1 if using SSE2, 0 otherwise. 00066 * 00067 */ 00068 int bshuf_using_SSE2(void); 00069 00070 00071 /* ---- bshuf_using_AVX2 ---- 00072 * 00073 * Whether routines where compiled with the AVX2 instruction set. 00074 * 00075 * Returns 00076 * ------- 00077 * 1 if using AVX2, 0 otherwise. 00078 * 00079 */ 00080 int bshuf_using_AVX2(void); 00081 00082 00083 /* ---- bshuf_default_block_size ---- 00084 * 00085 * The default block size as function of element size. 00086 * 00087 * This is the block size used by the blocked routines (any routine 00088 * taking a *block_size* argument) when the block_size is not provided 00089 * (zero is passed). 00090 * 00091 * The results of this routine are guaranteed to be stable such that 00092 * shuffled/compressed data can always be decompressed. 00093 * 00094 * Parameters 00095 * ---------- 00096 * elem_size : element size of data to be shuffled/compressed. 00097 * 00098 */ 00099 size_t bshuf_default_block_size(const size_t elem_size); 00100 00101 00102 /* ---- bshuf_bitshuffle ---- 00103 * 00104 * Bitshuffle the data. 00105 * 00106 * Transpose the bits within elements, in blocks of *block_size* 00107 * elements. 00108 * 00109 * Parameters 00110 * ---------- 00111 * in : input buffer, must be of size * elem_size bytes 00112 * out : output buffer, must be of size * elem_size bytes 00113 * size : number of elements in input 00114 * elem_size : element size of typed data 00115 * block_size : Do transpose in blocks of this many elements. Pass 0 to 00116 * select automatically (recommended). 00117 * 00118 * Returns 00119 * ------- 00120 * number of bytes processed, negative error-code if failed. 00121 * 00122 */ 00123 int64_t bshuf_bitshuffle(const void* in, void* out, const size_t size, 00124 const size_t elem_size, size_t block_size); 00125 00126 00127 /* ---- bshuf_bitunshuffle ---- 00128 * 00129 * Unshuffle bitshuffled data. 00130 * 00131 * Untranspose the bits within elements, in blocks of *block_size* 00132 * elements. 00133 * 00134 * To properly unshuffle bitshuffled data, *size*, *elem_size* and *block_size* 00135 * must match the parameters used to shuffle the data. 00136 * 00137 * Parameters 00138 * ---------- 00139 * in : input buffer, must be of size * elem_size bytes 00140 * out : output buffer, must be of size * elem_size bytes 00141 * size : number of elements in input 00142 * elem_size : element size of typed data 00143 * block_size : Do transpose in blocks of this many elements. Pass 0 to 00144 * select automatically (recommended). 00145 * 00146 * Returns 00147 * ------- 00148 * number of bytes processed, negative error-code if failed. 00149 * 00150 */ 00151 int64_t bshuf_bitunshuffle(const void* in, void* out, const size_t size, 00152 const size_t elem_size, size_t block_size); 00153 00154 #ifdef __cplusplus 00155 } // extern "C" 00156 #endif 00157 00158 #endif // BITSHUFFLE_CORE_H