JASSv2
compress_integer_elias_gamma_simd.h
Go to the documentation of this file.
1 /*
2  COMPRESS_INTEGER_ELIAS_GAMMA_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 */
13 #pragma once
14 
15 #include <stdint.h>
16 #include <string.h>
17 #include <immintrin.h>
18 
19 #include "forceinline.h"
20 #include "compress.h"
21 
22 namespace JASS
23  {
24  /*
25  CLASS COMPRESS_INTEGER_ELIAS_GAMMA_SIMD
26  ---------------------------------------
27  */
32  {
33  protected:
34  typedef uint32_t integer;
35 
36  private:
37 
38  /*
39  COMPRESS_INTEGER_ELIAS_GAMMA_SIMD::COMPUTE_SELECTOR()
40  -----------------------------------------------------
41  */
47  static uint32_t compute_selector(const uint8_t *encodings);
48 
49  /*
50  COMPRESS_INTEGER_ELIAS_GAMMA_SIMD::FIND_FIRST_SET_BIT()
51  -------------------------------------------------------
52  */
58  static forceinline uint64_t find_first_set_bit(uint64_t value)
59  {
60  return _tzcnt_u64(value) + 1;
61  }
62 
63  public:
64  /*
65  COMPRESS_INTEGER_ELIAS_GAMMA_SIMD::ENCODE()
66  -------------------------------------------
67  */
76  virtual size_t encode(void *encoded, size_t encoded_buffer_length, const integer *source, size_t source_integers);
77 
78  /*
79  COMPRESS_INTEGER_ELIAS_GAMMA_SIMD::DECODE()
80  -------------------------------------------
81  */
89  virtual void decode(integer *decoded, size_t integers_to_decode, const void *source, size_t source_length);
90 
91  /*
92  COMPRESS_INTEGER_ELIAS_GAMMA_SIMD::UNITTEST()
93  ---------------------------------------------
94  */
98  static void unittest(void);
99 
100  /*
101  For JASS V1
102  */
103  virtual long long compress(unsigned char *destination, long long destination_length, uint32_t *source, long long source_integers)
104  {
105  return encode(destination, destination_length, source, source_integers);
106  }
107 
108  virtual void decompress(uint32_t *destination, unsigned char *source, long long destination_integers)
109  {
110  /* Nothing */
111  }
112 
113  };
114  }
115 
116 
static uint32_t compute_selector(const uint8_t *encodings)
Computer the selector to use for this encoding.
Definition: compress_integer_elias_gamma_simd.c:64
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_gamma_simd.h:58
static void unittest(void)
Unit test this class.
Definition: compress_integer_elias_gamma_simd.c:386
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_gamma_simd.c:90
Pack 32-bit integers into 512-bit SIMD words using prn and carryover.
Definition: compress_integer_elias_gamma_simd.h:31
operating system and compiler independant definition of forceinline
Definition: compress.h:14
Definition: compress_integer_elias_delta_simd.c:23
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_gamma_simd.cpp:249