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 typedef unsigned char uint8_t; 00036 typedef unsigned short uint16_t; 00037 typedef unsigned int uint32_t; 00038 typedef signed int int32_t; 00039 typedef unsigned long long uint64_t; 00040 typedef long long int64_t; 00041 #endif 00042 00043 #include <stdlib.h> 00044 00045 00046 // These are usually set in the setup.py. 00047 #ifndef BSHUF_VERSION_MAJOR 00048 #define BSHUF_VERSION_MAJOR 0 00049 #define BSHUF_VERSION_MINOR 3 00050 #define BSHUF_VERSION_POINT 4 00051 #endif 00052 00053 #ifdef __cplusplus 00054 extern "C" { 00055 #endif 00056 00057 /* --- bshuf_using_SSE2 ---- 00058 * 00059 * Whether routines where compiled with the SSE2 instruction set. 00060 * 00061 * Returns 00062 * ------- 00063 * 1 if using SSE2, 0 otherwise. 00064 * 00065 */ 00066 int bshuf_using_SSE2(void); 00067 00068 00069 /* ---- bshuf_using_AVX2 ---- 00070 * 00071 * Whether routines where compiled with the AVX2 instruction set. 00072 * 00073 * Returns 00074 * ------- 00075 * 1 if using AVX2, 0 otherwise. 00076 * 00077 */ 00078 int bshuf_using_AVX2(void); 00079 00080 00081 /* ---- bshuf_default_block_size ---- 00082 * 00083 * The default block size as function of element size. 00084 * 00085 * This is the block size used by the blocked routines (any routine 00086 * taking a *block_size* argument) when the block_size is not provided 00087 * (zero is passed). 00088 * 00089 * The results of this routine are guaranteed to be stable such that 00090 * shuffled/compressed data can always be decompressed. 00091 * 00092 * Parameters 00093 * ---------- 00094 * elem_size : element size of data to be shuffled/compressed. 00095 * 00096 */ 00097 size_t bshuf_default_block_size(const size_t elem_size); 00098 00099 00100 /* ---- bshuf_bitshuffle ---- 00101 * 00102 * Bitshuffle the data. 00103 * 00104 * Transpose the bits within elements, in blocks of *block_size* 00105 * elements. 00106 * 00107 * Parameters 00108 * ---------- 00109 * in : input buffer, must be of size * elem_size bytes 00110 * out : output buffer, must be of size * elem_size bytes 00111 * size : number of elements in input 00112 * elem_size : element size of typed data 00113 * block_size : Do transpose in blocks of this many elements. Pass 0 to 00114 * select automatically (recommended). 00115 * 00116 * Returns 00117 * ------- 00118 * number of bytes processed, negative error-code if failed. 00119 * 00120 */ 00121 int64_t bshuf_bitshuffle(const void* in, void* out, const size_t size, 00122 const size_t elem_size, size_t block_size); 00123 00124 00125 /* ---- bshuf_bitunshuffle ---- 00126 * 00127 * Unshuffle bitshuffled data. 00128 * 00129 * Untranspose the bits within elements, in blocks of *block_size* 00130 * elements. 00131 * 00132 * To properly unshuffle bitshuffled data, *size*, *elem_size* and *block_size* 00133 * must match the parameters used to shuffle the data. 00134 * 00135 * Parameters 00136 * ---------- 00137 * in : input buffer, must be of size * elem_size bytes 00138 * out : output buffer, must be of size * elem_size bytes 00139 * size : number of elements in input 00140 * elem_size : element size of typed data 00141 * block_size : Do transpose in blocks of this many elements. Pass 0 to 00142 * select automatically (recommended). 00143 * 00144 * Returns 00145 * ------- 00146 * number of bytes processed, negative error-code if failed. 00147 * 00148 */ 00149 int64_t bshuf_bitunshuffle(const void* in, void* out, const size_t size, 00150 const size_t elem_size, size_t block_size); 00151 00152 #ifdef __cplusplus 00153 } // extern "C" 00154 #endif 00155 00156 #endif // BITSHUFFLE_CORE_H