JASSv2
compress_integer_elias_delta_simd.h
Go to the documentation of this file.
1 /*
2  COMPRESS_INTEGER_ELIAS_DELTA_SIMD.H
3  -----------------------------------
4  Copyright (c) 2018 Andrew Trotman
5  Released under the 2-clause BSD license (See:https://en.wikipedia.org/wiki/BSD_licenses)
6 */
14 #pragma once
15 
16 #include <stdint.h>
17 #include <immintrin.h>
18 
19 
20 #include "forceinline.h"
21 #include "compress.h"
22 
23 namespace JASS
24  {
25  /*
26  CLASS COMPRESS_INTEGER_ELIAS_DELTA_SIMD
27  ---------------------------------------
28  */
49  {
50  protected:
51  uint32_t selector_bits_used;
52  uint64_t accumulated_selector;
53  typedef uint32_t integer;
54 
55  protected:
56  /*
57  COMPRESS_INTEGER_ELIAS_DELTA_SIMD::FIND_FIRST_SET_BIT()
58  -------------------------------------------------------
59  */
65  static forceinline uint64_t find_first_set_bit(uint64_t value)
66  {
67  return _tzcnt_u64(value) + 1;
68  }
69 
70  forceinline void push_selector(uint32_t *&destination, uint8_t raw);
71  uint8_t forceinline decode_selector(const uint32_t *&selector_set);
72 
73  public:
74  /*
75  COMPRESS_INTEGER_ELIAS_DELTA_SIMD::ENCODE()
76  -------------------------------------------
77  */
86  virtual size_t encode(void *encoded, size_t encoded_buffer_length, const integer *source, size_t source_integers);
87 
88  /*
89  COMPRESS_INTEGER_ELIAS_DELTA_SIMD::DECODE()
90  -------------------------------------------
91  */
99  virtual void decode(integer *decoded, size_t integers_to_decode, const void *source, size_t source_length);
100 
101  /*
102  COMPRESS_INTEGER_ELIAS_DELTA_SIMD::UNITTEST()
103  ---------------------------------------------
104  */
108  static void unittest(void);
109 
110 
111  /*
112  For JASS V1
113  */
114  virtual long long compress(unsigned char *destination, long long destination_length, uint32_t *source, long long source_integers)
115  {
116  return encode(destination, destination_length, source, source_integers);
117  }
118 
119  virtual void decompress(uint32_t *destination, unsigned char *source, long long destination_integers)
120  {
121  /* Nothing */
122  }
123  };
124  }
virtual void decode(integer *decoded, size_t integers_to_decode, const void *source, size_t source_length)
Decode a sequence of integers encoded with this codex.
Definition: compress_integer_elias_delta_simd.cpp:320
virtual size_t encode(void *encoded, size_t encoded_buffer_length, const integer *source, size_t source_integers)
Encode a sequence of integers returning the number of bytes used for the encoding, or 0 if the encoded sequence doesn&#39;t fit in the buffer.
Definition: compress_integer_elias_delta_simd.c:100
static forceinline uint64_t find_first_set_bit(uint64_t value)
return the position of the least significant set bit (using a single machine code instruction) ...
Definition: compress_integer_elias_delta_simd.h:65
static void unittest(void)
Unit test this class.
Definition: compress_integer_elias_delta_simd.c:457
operating system and compiler independant definition of forceinline
Definition: compress.h:14
SIMD compression (line Simple-9) using Elias delta to encode the selectors.
Definition: compress_integer_elias_delta_simd.h:48
Definition: compress_integer_elias_delta_simd.c:23