Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / third_party / om-file-format-sys / c / src / bitpack.c
bitpack.c442 lines · 25.0 KiBRaw
| 1 | /** |
| 2 | Copyright (C) powturbo 2013-2019 |
| 3 | GPL v2 License |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along |
| 16 | with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | - homepage : https://sites.google.com/site/powturbo/ |
| 20 | - github : https://github.com/powturbo |
| 21 | - twitter : https://twitter.com/powturbo |
| 22 | - email : powturbo [_AT_] gmail [_DOT_] com |
| 23 | **/ |
| 24 | // "Integer Compression" bit packing |
| 25 | |
| 26 | #ifdef GUARDED |
| 27 | |
| 28 | #pragma clang diagnostic ignored "-Wmacro-redefined" |
| 29 | #pragma clang diagnostic ignored "-Wshorten-64-to-32" |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> // for memcp |
| 33 | #define BITUTIL_IN |
| 34 | #define VINT_IN |
| 35 | #include "conf.h" |
| 36 | #include "bitutil.h" |
| 37 | #include "vint.h" |
| 38 | #include "bitpack.h" |
| 39 | #define PAD8(_x_) ( (((_x_)+8-1)/8) ) |
| 40 | |
| 41 | #ifdef __ARM_NEON |
| 42 | #define PREFETCH(_ip_,_rw_) |
| 43 | #else |
| 44 | #define PREFETCH(_ip_,_rw_) __builtin_prefetch(_ip_,_rw_) |
| 45 | #endif |
| 46 | |
| 47 | #pragma clang diagnostic ignored "-Wunknown-pragmas" |
| 48 | |
| 49 | #pragma warning( disable : 4005) |
| 50 | #pragma warning( disable : 4090) |
| 51 | #pragma warning( disable : 4068) |
| 52 | #pragma clang diagnostic push |
| 53 | #pragma clang diagnostic ignored "-Wunsequenced" |
| 54 | #pragma clang diagnostic ignored "-Wincompatible-pointer-types" |
| 55 | #pragma clang diagnostic ignored "-Wunused-variable" |
| 56 | #pragma clang diagnostic ignored "-Wmacro-redefined" |
| 57 | #pragma clang diagnostic ignored "-Wshift-op-parentheses" |
| 58 | #pragma clang diagnostic ignored "-Wshorten-64-to-32" |
| 59 | #pragma clang diagnostic ignored "-Wunused-parameter" |
| 60 | |
| 61 | #if !defined(SSE2_ON) && !defined(AVX2_ON) //----------------------------------- Plain ----------------------------------------------------------------------- |
| 62 | typedef unsigned char *(*BITPACK_F8)( uint8_t *__restrict out, unsigned n, const unsigned char *__restrict in); |
| 63 | typedef unsigned char *(*BITPACK_D8)( uint8_t *__restrict out, unsigned n, const unsigned char *__restrict in, uint8_t start); |
| 64 | typedef unsigned char *(*BITPACK_F16)(uint16_t *__restrict out, unsigned n, const unsigned char *__restrict in); |
| 65 | typedef unsigned char *(*BITPACK_D16)(uint16_t *__restrict out, unsigned n, const unsigned char *__restrict in, uint16_t start); |
| 66 | typedef unsigned char *(*BITPACK_F32)(uint32_t *__restrict out, unsigned n, const unsigned char *__restrict in); |
| 67 | typedef unsigned char *(*BITPACK_D32)(uint32_t *__restrict out, unsigned n, const unsigned char *__restrict in, uint32_t start); |
| 68 | typedef unsigned char *(*BITPACK_F64)(uint64_t *__restrict out, unsigned n, const unsigned char *__restrict in); |
| 69 | typedef unsigned char *(*BITPACK_D64)(uint64_t *__restrict out, unsigned n, const unsigned char *__restrict in, uint64_t start); |
| 70 | |
| 71 | #if 1 //def _MSC_VER |
| 72 | #define VX (v=x) |
| 73 | #define V x |
| 74 | #else |
| 75 | #define VX v |
| 76 | #define V v |
| 77 | #endif |
| 78 | |
| 79 | #if 0 |
| 80 | #define IP0(_ip_,_x_) *_ip_ |
| 81 | #define IP( _ip_,_x_) *_ip_++ |
| 82 | #define IPI(_ip_) |
| 83 | #else |
| 84 | #define IP0(_ip_,_x_) _ip_[_x_] |
| 85 | #define IP( _ip_,_x_) _ip_[_x_] |
| 86 | #define IPI(_ip_) _ip_ += 32 |
| 87 | #endif |
| 88 | |
| 89 | #define IP9(_ip_,_x_, _parm_) |
| 90 | #define IPW(_ip_,_x_) VX |
| 91 | #define IPX(_ip_,_x_) (V = IP(_ip_,_x_)) |
| 92 | |
| 93 | #define IPV(_ip_,_x_) IP(_ip_,_x_) |
| 94 | #define IP16(_ip_,_x_, _parm_) |
| 95 | #define IP32(_ip_,_x_, _parm_) |
| 96 | #define IP64(_ip_,_x_, _parm_) |
| 97 | #define _BITPACK_ bitpack |
| 98 | #include "bitpack_.h" |
| 99 | #undef IP9 |
| 100 | #undef IPV |
| 101 | #undef IPX |
| 102 | #undef IP16 |
| 103 | #undef IP32 |
| 104 | #undef IP64 |
| 105 | |
| 106 | #define DELTA |
| 107 | |
| 108 | #define IP9(_ip_,_x_, _parm_) V = IP0(_ip_,_x_) - start; start = IP(_ip_,_x_) |
| 109 | #define IPV(_ip_,_x_) VX |
| 110 | #define IPX(_ip_,_x_) (V = IP(_ip_,_x_) - start) |
| 111 | #define IP16(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 112 | #define IP32(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 113 | #define IP64(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 114 | #define _BITPACK_ bitdpack |
| 115 | #include "bitpack_.h" |
| 116 | #undef IP9 |
| 117 | #undef IPV |
| 118 | #undef IPX |
| 119 | #undef IP16 |
| 120 | #undef IP32 |
| 121 | #undef IP64 |
| 122 | |
| 123 | #define IP9(_ip_,_x_, _parm_) |
| 124 | #define IPV(_ip_,_x_) IP(_ip_,_x_) - start |
| 125 | #define IPX(_ip_,_x_) (V = IP(_ip_,_x_) - start) |
| 126 | #define IP16(_ip_,_x_, _parm_) |
| 127 | #define IP32(_ip_,_x_, _parm_) |
| 128 | #define IP64(_ip_,_x_, _parm_) |
| 129 | #define _BITPACK_ bitfpack |
| 130 | #include "bitpack_.h" |
| 131 | #undef IP9 |
| 132 | #undef IPV |
| 133 | #undef IPX |
| 134 | #undef IP16 |
| 135 | #undef IP32 |
| 136 | #undef IP64 |
| 137 | |
| 138 | #define IP9( _ip_,_x_, _parm_) V = IP0(_ip_,_x_) - start - 1; start = IP(_ip_,_x_) |
| 139 | #define IPV( _ip_,_x_) VX |
| 140 | #define IPX(_ip_,_x_) (V = IP(_ip_,_x_) - start - 1) |
| 141 | #define IP16(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 142 | #define IP32(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 143 | #define IP64(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 144 | #define _BITPACK_ bitd1pack |
| 145 | #include "bitpack_.h" |
| 146 | #undef IP9 |
| 147 | #undef IPV |
| 148 | #undef IPX |
| 149 | #undef IP16 |
| 150 | #undef IP32 |
| 151 | #undef IP64 |
| 152 | |
| 153 | /*#define IP9( _ip_,_x_, _parm_) v = IP(_ip_,_x_) - start - mdelta; start = IP(_ip_,_x_) |
| 154 | #define IPV( _ip_,_x_) v |
| 155 | #define IPX(_ip_,_x_) (v = IP(_ip_,_x_) - start - mdelta) |
| 156 | #define IP32(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 157 | #define _BITPACK_ bitepack |
| 158 | #include "bitpack_.h"*/ |
| 159 | |
| 160 | #define IP9(_ip_,_x_, _parm_) V = TEMPLATE2(zigzagenc, USIZE)(IP(_ip_,_x_) - start); start = IP(_ip_,_x_) |
| 161 | #define IPV(_ip_,_x_) VX |
| 162 | #define IPX(_ip_,_x_) (V = TEMPLATE2(zigzagenc, USIZE)(IP(_ip_,_x_) - start)) |
| 163 | #define IP16(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 164 | #define IP32(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 165 | #define IP64(_ip_,_x_, _parm_) start = IP(_ip_,_x_) |
| 166 | #define _BITPACK_ bitzpack |
| 167 | #include "bitpack_.h" |
| 168 | #undef IP9 |
| 169 | #undef IPV |
| 170 | #undef IPX |
| 171 | #undef IP16 |
| 172 | #undef IP32 |
| 173 | #undef IP64 |
| 174 | |
| 175 | #define IPI(_ip_) _ip_ += 32; start += 32 |
| 176 | #define IP9(_ip_,_x_, _parm_) |
| 177 | #define IPV(_ip_,_x_) (IP(_ip_,_x_) - start - (_x_) - 1) |
| 178 | #define IPX(_ip_,_x_) (V = IP(_ip_,_x_) - start - (_x_) - 1) |
| 179 | #define IP16(_ip_,_x_, _parm_) |
| 180 | #define IP32(_ip_,_x_, _parm_) |
| 181 | #define IP64(_ip_,_x_, _parm_) |
| 182 | #define _BITPACK_ bitf1pack |
| 183 | #include "bitpack_.h" |
| 184 | #undef IPI |
| 185 | #undef IP9 |
| 186 | #undef IPV |
| 187 | #undef IPX |
| 188 | #undef IP16 |
| 189 | #undef IP32 |
| 190 | #undef IP64 |
| 191 | |
| 192 | #define BITNPACK(in, n, out, _csize_, _usize_) { unsigned char *op = out;\ |
| 193 | for(ip = in, in += n; ip < in;) { \ |
| 194 | TEMPLATE3(uint, _usize_, _t) o,x;\ |
| 195 | unsigned iplen = in - ip,b; \ |
| 196 | if(iplen > _csize_) iplen = _csize_; PREFETCH(ip+512,0);\ |
| 197 | o = TEMPLATE2(bit,_usize_)(ip, iplen, &x); b = TEMPLATE2(bsr,_usize_)(o);\ |
| 198 | *op++ = b; op = TEMPLATE2(bitpacka, _usize_)[b](ip, iplen, op);\ |
| 199 | ip += iplen;\ |
| 200 | }\ |
| 201 | return op - out;\ |
| 202 | } |
| 203 | |
| 204 | #define BITNDPACK(in, n, out, _csize_, _usize_, _bitd_, _bitpacka_) { if(!n) return 0;\ |
| 205 | unsigned char *op = out; \ |
| 206 | TEMPLATE3(uint, _usize_, _t) o,x;\ |
| 207 | start = *in++; \ |
| 208 | TEMPLATE2(vbxput, _usize_)(op, start);\ |
| 209 | for(n--,ip = in; ip != in + (n&~(_csize_-1)); ) { unsigned b; PREFETCH(ip+512,0);\ |
| 210 | o = TEMPLATE2(_bitd_, _usize_)(ip, _csize_, &x, start); b = TEMPLATE2(bsr,_usize_)(o); *op++ = b; op = TEMPLATE2(_bitpacka_,_usize_)[b](ip, _csize_, op, start); ip += _csize_; start = ip[-1];\ |
| 211 | }\ |
| 212 | if(n&=(_csize_-1)) { unsigned b;\ |
| 213 | o = TEMPLATE2(_bitd_, _usize_)(ip, n, &x, start); b = TEMPLATE2(bsr,_usize_)(o); *op++ = b; op = TEMPLATE2(_bitpacka_,_usize_)[b](ip, n, op, start);\ |
| 214 | }\ |
| 215 | return op - out;\ |
| 216 | } |
| 217 | |
| 218 | size_t bitnpack8( uint8_t *__restrict in, size_t n, unsigned char *__restrict out) { uint8_t *ip,start; BITNPACK(in, n, out, 128, 8); } |
| 219 | size_t bitnpack16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; BITNPACK(in, n, out, 128, 16); } |
| 220 | size_t bitnpack32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; BITNPACK(in, n, out, 128, 32); } |
| 221 | size_t bitnpack64( uint64_t *__restrict in, size_t n, unsigned char *__restrict out) { uint64_t *ip,start; BITNPACK(in, n, out, 128, 64); } |
| 222 | |
| 223 | size_t bitndpack8( uint8_t *__restrict in, size_t n, unsigned char *__restrict out) { uint8_t *ip,start; BITNDPACK(in, n, out, 128, 8, bitd, bitdpacka); } |
| 224 | size_t bitndpack16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; BITNDPACK(in, n, out, 128, 16, bitd, bitdpacka); } |
| 225 | size_t bitndpack32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; BITNDPACK(in, n, out, 128, 32, bitd, bitdpacka); } |
| 226 | size_t bitndpack64( uint64_t *__restrict in, size_t n, unsigned char *__restrict out) { uint64_t *ip,start; BITNDPACK(in, n, out, 128, 64, bitd, bitdpacka); } |
| 227 | |
| 228 | size_t bitnd1pack8( uint8_t *__restrict in, size_t n, unsigned char *__restrict out) { uint8_t *ip,start; BITNDPACK(in, n, out, 128, 8, bitd1, bitd1packa); } |
| 229 | size_t bitnd1pack16(uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; BITNDPACK(in, n, out, 128, 16, bitd1, bitd1packa); } |
| 230 | size_t bitnd1pack32(uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; BITNDPACK(in, n, out, 128, 32, bitd1, bitd1packa); } |
| 231 | size_t bitnd1pack64(uint64_t *__restrict in, size_t n, unsigned char *__restrict out) { uint64_t *ip,start; BITNDPACK(in, n, out, 128, 64, bitd1, bitd1packa); } |
| 232 | |
| 233 | size_t bitnzpack8( uint8_t *__restrict in, size_t n, unsigned char *__restrict out) { uint8_t *ip,start; BITNDPACK(in, n, out, 128, 8, bitz, bitzpacka); } |
| 234 | size_t bitnzpack16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; BITNDPACK(in, n, out, 128, 16, bitz, bitzpacka); } |
| 235 | size_t bitnzpack32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; BITNDPACK(in, n, out, 128, 32, bitz, bitzpacka); } |
| 236 | size_t bitnzpack64( uint64_t *__restrict in, size_t n, unsigned char *__restrict out) { uint64_t *ip,start; BITNDPACK(in, n, out, 128, 64, bitz, bitzpacka); } |
| 237 | |
| 238 | size_t bitnfpack8( uint8_t *__restrict in, size_t n, unsigned char *__restrict out) { uint8_t *ip,start; BITNDPACK(in, n, out, 128, 8, bitf, bitfpacka); } |
| 239 | size_t bitnfpack16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; BITNDPACK(in, n, out, 128, 16, bitf, bitfpacka); } |
| 240 | size_t bitnfpack32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; BITNDPACK(in, n, out, 128, 32, bitf, bitfpacka); } |
| 241 | size_t bitnfpack64( uint64_t *__restrict in, size_t n, unsigned char *__restrict out) { uint64_t *ip,start; BITNDPACK(in, n, out, 128, 64, bitf, bitfpacka); } |
| 242 | |
| 243 | #else //--------------------------------------- SIMD ---------------------------------------------------------------------------------------------- |
| 244 | |
| 245 | #define _BITNPACKV(in, n, out, _csize_, _usize_, _bitpackv_) {\ |
| 246 | unsigned char *op = out; TEMPLATE3(uint, _usize_, _t) _o,_x;\ |
| 247 | for(ip = in; ip != in + (n&~(_csize_-1)); ip += _csize_) { PREFETCH(ip+512,0);\ |
| 248 | unsigned _b; _o = TEMPLATE2(bit,_usize_)(ip, _csize_, &_x); _b = TEMPLATE2(bsr,_usize_)(_o); *op++ = _b; op = TEMPLATE2(_bitpackv_, _usize_)(ip, _csize_, op, _b);\ |
| 249 | } if(n&=(_csize_-1)) { unsigned _b; _o = TEMPLATE2(bit,_usize_)(ip, n, &_x); _b = TEMPLATE2(bsr,_usize_)(_o); *op++ = _b; op = TEMPLATE2(bitpack, _usize_)(ip, n, op, _b); }\ |
| 250 | return op - out;\ |
| 251 | } |
| 252 | |
| 253 | #define _BITNDPACKV(in, n, out, _csize_, _usize_, _bitdv_, _bitpackv_, _bitd_, _bitpack_) { if(!n) return 0;\ |
| 254 | unsigned char *op = out; TEMPLATE3(uint, _usize_, _t) _o,_x;\ |
| 255 | start = *in++; \ |
| 256 | TEMPLATE2(vbxput, _usize_)(op, start);\ |
| 257 | for(n--,ip = in; ip != in + (n&~(_csize_-1)); ) { PREFETCH(ip+512,0);\ |
| 258 | unsigned _b; _o = TEMPLATE2(_bitdv_, _usize_)(ip, _csize_, &_x, start); _b = TEMPLATE2(bsr,_usize_)(_o); *op++ = _b; op = TEMPLATE2(_bitpackv_, _usize_)(ip, _csize_, op, start, _b); ip += _csize_; start = ip[-1];\ |
| 259 | } if(n&=(_csize_-1)) { unsigned _b; _o = TEMPLATE2(_bitd_, _usize_)(ip, n, &_x, start); _b = TEMPLATE2(bsr,_usize_)(_o); *op++ = _b; op = TEMPLATE2(_bitpack_, _usize_)(ip, n, op, start, _b); }\ |
| 260 | return op - out;\ |
| 261 | } |
| 262 | |
| 263 | #ifdef AVX2_ON |
| 264 | #include <immintrin.h> |
| 265 | #include "bitpack_.h" |
| 266 | |
| 267 | #define OPPE(__op) |
| 268 | #define IPPE(__op) |
| 269 | |
| 270 | #define PAD8(__x) (((__x)+8-1)/8) |
| 271 | #define OPPE(__op) |
| 272 | #define IPPE(__op) |
| 273 | |
| 274 | #define VI32(ip, i, iv, parm) |
| 275 | #define IP32(ip, i, iv) _mm256_loadu_si256(ip++) |
| 276 | |
| 277 | unsigned char *bitpack256v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned b) { unsigned char *pout = out+PAD8(256*b); BITPACK256V32(in, b, out, 0); return pout; } |
| 278 | #undef VI32 |
| 279 | #undef IP32 |
| 280 | |
| 281 | |
| 282 | #define VI32(_ip_, _i_, _iv_, _sv_) _iv_ = _mm256_sub_epi32(_mm256_loadu_si256(_ip_++),sv) |
| 283 | #define IP32(_ip_, i, _iv_) _iv_ |
| 284 | #include "bitpack_.h" |
| 285 | unsigned char *bitfpack256v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(256*b); |
| 286 | __m256i v, sv = _mm256_set1_epi32(start); |
| 287 | BITPACK256V32(in, b, out, sv); |
| 288 | return pout; |
| 289 | } |
| 290 | |
| 291 | #define VI32(_ip_, _i_, _iv_, _sv_) _iv_ = _mm256_sub_epi32(_mm256_loadu_si256(_ip_++),_sv_); _sv_ = _mm256_add_epi32(_sv_,cv); |
| 292 | #define IP32(ip, i, _iv_) _iv_ |
| 293 | unsigned char *bitf1pack256v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(256*b); |
| 294 | __m256i v, sv = _mm256_set_epi32(start+8,start+7,start+6,start+5,start+4,start+3,start+2,start+1), cv = _mm256_set1_epi32(8); |
| 295 | BITPACK256V32(in, b, out, sv); return pout; |
| 296 | } |
| 297 | |
| 298 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm256_loadu_si256(_ip_++); _iv_ = mm256_delta_epi32(v,_sv_); _sv_ = v |
| 299 | #define IP32(ip, i, _iv_) _iv_ |
| 300 | #include "bitpack_.h" |
| 301 | unsigned char *bitdpack256v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(256*b); |
| 302 | __m256i v,sv = _mm256_set1_epi32(start); |
| 303 | BITPACK256V32(in, b, out, sv); |
| 304 | return pout; |
| 305 | } |
| 306 | |
| 307 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm256_loadu_si256(_ip_++); _iv_ = _mm256_sub_epi32(mm256_delta_epi32(v,_sv_),cv); _sv_ = v |
| 308 | unsigned char *bitd1pack256v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(256*b); |
| 309 | __m256i v, sv = _mm256_set1_epi32(start), cv = _mm256_set1_epi32(1); |
| 310 | BITPACK256V32(in, b, out, sv); |
| 311 | return pout; |
| 312 | } |
| 313 | |
| 314 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm256_loadu_si256(_ip_++); _iv_ = mm256_delta_epi32(v,_sv_); _sv_ = v; _iv_ = mm256_zzage_epi32(_iv_) |
| 315 | unsigned char *bitzpack256v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(256*b); |
| 316 | __m256i v, sv = _mm256_set1_epi32(start), cv = _mm256_set1_epi32(1); |
| 317 | BITPACK256V32(in, b, out, sv); |
| 318 | return pout; |
| 319 | } |
| 320 | |
| 321 | size_t bitnpack256v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip; _BITNPACKV( in, n, out, 256, 32, bitpack256v); } |
| 322 | size_t bitndpack256v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 256, 32, bitd, bitdpack256v, bitd, bitdpack); } |
| 323 | size_t bitnd1pack256v32(uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 256, 32, bitd1, bitd1pack256v,bitd1, bitd1pack); } |
| 324 | size_t bitnzpack256v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 256, 32, bitz, bitzpack256v, bitz, bitzpack); } |
| 325 | size_t bitnfpack256v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 256, 32, bitf, bitfpack256v, bitf, bitfpack); } |
| 326 | |
| 327 | #elif defined(__SSE2__) || defined(__ARM_NEON) //----------------------------- SSE --------------------------------------------------------------- |
| 328 | #define OPPE(__op) |
| 329 | #define IPPE(__op) |
| 330 | |
| 331 | #define VI16(ip, i, iv, parm) |
| 332 | #define VI32(ip, i, iv, parm) |
| 333 | #define IP16(_ip_, i, iv) _mm_loadu_si128(_ip_++) |
| 334 | #define IP32(_ip_, i, iv) _mm_loadu_si128(_ip_++) |
| 335 | #include "bitpack_.h" |
| 336 | unsigned char *bitpack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned b) { unsigned char *pout = out+PAD8(128*b); BITPACK128V16(in, b, out, 0); return pout; } |
| 337 | unsigned char *bitpack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned b) { unsigned char *pout = out+PAD8(128*b); BITPACK128V32(in, b, out, 0); return pout; } |
| 338 | unsigned char *bitpack256w32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned b) { unsigned char *_out=out; unsigned *_in=in; |
| 339 | BITPACK128V32(in, b, out, 0); in = _in+128; out = _out+PAD8(128*b); BITPACK128V32(in, b, out, 0); return _out+PAD8(256*b); } |
| 340 | |
| 341 | #ifdef __ARM_NEON |
| 342 | //#define IP32(_ip_, i, iv) _mm_or_si128(_mm_shuffle_epi32( _mm_loadu_si128(_ip_++),_MM_SHUFFLE(3, 1, 2, 0)), _mm_shuffle_epi32( _mm_loadu_si128(_ip_++),_MM_SHUFFLE(2, 0, 3, 1)) ) |
| 343 | #define IP32(_ip_, _i_, _iv_) _mm_or_si128(mm_shuffle_3120_epi32(_mm_loadu_si128(_ip_++) ), mm_shuffle_2031_epi32(_mm_loadu_si128(_ip++) ) ) // optimized shuffle |
| 344 | #else |
| 345 | #define IP32(_ip_, i, iv) _mm_or_si128(_mm_shuffle_epi32( _mm_loadu_si128(_ip_++),_MM_SHUFFLE(2, 0, 3, 1)), _mm_shuffle_epi32( _mm_loadu_si128(_ip_++),_MM_SHUFFLE(3, 1, 2, 0)) ) |
| 346 | #endif |
| 347 | #include "bitpack_.h" |
| 348 | unsigned char *bitpack128v64(uint64_t *__restrict in, unsigned n, unsigned char *__restrict out, unsigned b) { |
| 349 | if(b<=32) { unsigned char *pout = out+PAD8(128*b); BITPACK128V32(in, b, out, 0); return pout; } else return bitpack64(in,n,out,b); |
| 350 | } |
| 351 | |
| 352 | #define VI16(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = mm_delta_epi16(v,_sv_); _sv_ = v |
| 353 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = mm_delta_epi32(v,_sv_); _sv_ = v |
| 354 | #define IP16(ip, i, _iv_) _iv_ |
| 355 | #define IP32(ip, i, _iv_) _iv_ |
| 356 | #include "bitpack_.h" |
| 357 | unsigned char *bitdpack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned short start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 358 | __m128i v,sv = _mm_set1_epi16(start); BITPACK128V16(in, b, out, sv); return pout; |
| 359 | } |
| 360 | unsigned char *bitdpack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 361 | __m128i v,sv = _mm_set1_epi32(start); BITPACK128V32(in, b, out, sv); return pout; |
| 362 | } |
| 363 | |
| 364 | #define VI16(_ip_, _i_, _iv_, _sv_) |
| 365 | #define VI32(_ip_, _i_, _iv_, _sv_) |
| 366 | #define IP16(_ip_, i, _iv_) _mm_sub_epi16(_mm_loadu_si128(_ip_++),sv) |
| 367 | #define IP32(_ip_, i, _iv_) _mm_sub_epi32(_mm_loadu_si128(_ip_++),sv) |
| 368 | #include "bitpack_.h" |
| 369 | unsigned char *bitfpack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned short start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 370 | __m128i v, sv = _mm_set1_epi16(start); BITPACK128V16(in, b, out, sv); return pout; |
| 371 | } |
| 372 | unsigned char *bitfpack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 373 | __m128i v, sv = _mm_set1_epi32(start); BITPACK128V32(in, b, out, sv); return pout; |
| 374 | } |
| 375 | |
| 376 | #define VI16(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = _mm_sub_epi16(mm_delta_epi16(v,_sv_),cv); _sv_ = v |
| 377 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = _mm_sub_epi32(mm_delta_epi32(v,_sv_),cv); _sv_ = v |
| 378 | #define IP16(ip, i, _iv_) _iv_ |
| 379 | #define IP32(ip, i, _iv_) _iv_ |
| 380 | unsigned char *bitd1pack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned short start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 381 | __m128i sv = _mm_set1_epi16(start), cv = _mm_set1_epi16(1), v; BITPACK128V16(in, b, out, sv); return pout; |
| 382 | } |
| 383 | unsigned char *bitd1pack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 384 | __m128i v, sv = _mm_set1_epi32(start), cv = _mm_set1_epi32(1); BITPACK128V32(in, b, out, sv); return pout; |
| 385 | } |
| 386 | |
| 387 | #define VI16(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = _mm_sub_epi16(SUBI16x8(v,_sv_),cv); _sv_ = v |
| 388 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = _mm_sub_epi32(SUBI32x4(v,_sv_),cv); _sv_ = v |
| 389 | #define IP16(ip, i, _iv_) _iv_ |
| 390 | #define IP32(ip, i, _iv_) _iv_ |
| 391 | unsigned char *bits1pack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned short start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 392 | __m128i v, sv = _mm_set1_epi16(start), cv = _mm_set1_epi16(8); BITPACK128V16(in, b, out, sv); return pout; |
| 393 | } |
| 394 | unsigned char *bits1pack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 395 | __m128i v, sv = _mm_set1_epi32(start), cv = _mm_set1_epi32(4); BITPACK128V32(in, b, out, sv); return pout; |
| 396 | } |
| 397 | |
| 398 | #define VI16(_ip_, _i_, _iv_, _sv_) _iv_ = _mm_sub_epi16(_mm_loadu_si128(_ip_++),_sv_); _sv_ = _mm_add_epi16(_sv_,cv); |
| 399 | #define VI32(_ip_, _i_, _iv_, _sv_) _iv_ = _mm_sub_epi32(_mm_loadu_si128(_ip_++),_sv_); _sv_ = _mm_add_epi32(_sv_,cv); |
| 400 | #define IP16(ip, i, _iv_) _iv_ |
| 401 | #define IP32(ip, i, _iv_) _iv_ |
| 402 | unsigned char *bitf1pack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned short start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 403 | __m128i v, sv = _mm_set_epi16(start+8,start+7,start+6,start+5,start+4,start+3,start+2,start+1), cv = _mm_set1_epi16(8); BITPACK128V16(in, b, out, sv); return pout; |
| 404 | } |
| 405 | unsigned char *bitf1pack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 406 | __m128i v, sv = _mm_set_epi32( start+4,start+3,start+2,start+1), cv = _mm_set1_epi32(4); BITPACK128V32(in, b, out, sv); return pout; |
| 407 | } |
| 408 | |
| 409 | #define VI16(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = mm_delta_epi16(v,_sv_); _sv_ = v; _iv_ = mm_zzage_epi16(_iv_) |
| 410 | unsigned char *bitzpack128v16(unsigned short *__restrict in, unsigned n, unsigned char *__restrict out, unsigned short start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 411 | __m128i v, sv = _mm_set1_epi16(start), cv = _mm_set1_epi16(1); BITPACK128V16(in, b, out, sv); return pout; |
| 412 | } |
| 413 | #define VI32(_ip_, _i_, _iv_, _sv_) v = _mm_loadu_si128(_ip_++); _iv_ = mm_delta_epi32(v,_sv_); _sv_ = v; _iv_ = mm_zzage_epi32(_iv_) |
| 414 | unsigned char *bitzpack128v32(unsigned *__restrict in, unsigned n, unsigned char *__restrict out, unsigned start, unsigned b) { unsigned char *pout = out+PAD8(128*b); |
| 415 | __m128i v, sv = _mm_set1_epi32(start), cv = _mm_set1_epi32(1); BITPACK128V32(in, b, out, sv); return pout; |
| 416 | } |
| 417 | |
| 418 | size_t bitnpack128v16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip; _BITNPACKV( in, n, out, 128, 16, bitpack128v); } |
| 419 | size_t bitnpack128v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip; _BITNPACKV( in, n, out, 128, 32, bitpack128v); } |
| 420 | size_t bitnpack128v64( uint64_t *__restrict in, size_t n, unsigned char *__restrict out) { uint64_t *ip; _BITNPACKV( in, n, out, 128, 64, bitpack128v); } |
| 421 | size_t bitnpack256w32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip; _BITNPACKV( in, n, out, 256, 32, bitpack256w); } |
| 422 | |
| 423 | size_t bitndpack128v16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; _BITNDPACKV(in, n, out, 128, 16, bitd, bitdpack128v, bitd, bitdpack); } |
| 424 | size_t bitndpack128v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 128, 32, bitd, bitdpack128v, bitd, bitdpack); } |
| 425 | |
| 426 | size_t bitnd1pack128v16(uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; _BITNDPACKV(in, n, out, 128, 16, bitd1, bitd1pack128v, bitd1, bitd1pack); } |
| 427 | size_t bitnd1pack128v32(uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 128, 32, bitd1, bitd1pack128v, bitd1, bitd1pack); } |
| 428 | |
| 429 | size_t bitns1pack128v16(uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; _BITNDPACKV(in, n, out, 128, 16, bits128v, bits1pack128v, bitd1, bitd1pack); } |
| 430 | size_t bitns1pack128v32(uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 128, 32, bits128v, bits1pack128v, bitd1, bitd1pack); } |
| 431 | |
| 432 | size_t bitnzpack128v16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; _BITNDPACKV(in, n, out, 128, 16, bitz, bitzpack128v, bitz, bitzpack); } |
| 433 | size_t bitnzpack128v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 128, 32, bitz, bitzpack128v, bitz, bitzpack); } |
| 434 | |
| 435 | size_t bitnfpack128v16( uint16_t *__restrict in, size_t n, unsigned char *__restrict out) { uint16_t *ip,start; _BITNDPACKV(in, n, out, 128, 16, bitf, bitfpack128v, bitf, bitfpack); } |
| 436 | size_t bitnfpack128v32( uint32_t *__restrict in, size_t n, unsigned char *__restrict out) { uint32_t *ip,start; _BITNDPACKV(in, n, out, 128, 32, bitf, bitfpack128v, bitf, bitfpack); } |
| 437 | #endif // SSE |
| 438 | #endif // Plain |
| 439 | |
| 440 | #pragma clang diagnostic pop |
| 441 | |
| 442 | #endif |