]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/isa-l/igzip/bitbuf2.h
Import ceph 15.2.8
[ceph.git] / ceph / src / isa-l / igzip / bitbuf2.h
index 0f018b0b1ecef2445e068e00de260e4e684fca57..51bd752d0a914cb02e119ddc70017ceb2eda0f5c 100644 (file)
 #define BITBUF2_H
 
 #include "igzip_lib.h"
-
-/* bit buffer types
- * BITBUF8: (e) Always write 8 bytes of data
- * BITBUFB: (b) Always write data
- */
-#if !(defined(USE_BITBUFB) || defined(USE_BITBUF8) || defined(USE_BITBUF_ELSE))
-# define USE_BITBUFB
-#endif
-
-#if defined (__unix__) || (__APPLE__) || (__MINGW32__)
-#define _mm_stream_si64x(dst, src) *((uint64_t*)dst) = src
-#else
-#include <intrin.h>
-#endif
-
-#ifdef _WIN64
-#pragma warning(disable: 4996)
-#endif
+#include "unaligned.h"
 
 #ifdef _MSC_VER
 #define inline __inline
 /* MAX_BITBUF_BIT WRITE is the maximum number of bits than can be safely written
  * by consecutive calls of write_bits. Note this assumes the bitbuf is in a
  * state that is possible at the exit of write_bits */
-#ifdef USE_BITBUF8 /*Write bits safe */
-# define MAX_BITBUF_BIT_WRITE 63
-#elif defined(USE_BITBUFB) /* Write bits always */
-# define MAX_BITBUF_BIT_WRITE 56
-#else /* USE_BITBUF_ELSE */
-# define MAX_BITBUF_BIT_WRITE 56
-#endif
-
-
-static
- inline void construct(struct BitBuf2 *me)
-{
-       me->m_bits = 0;
-       me->m_bit_count = 0;
-       me->m_out_buf = me->m_out_start = me->m_out_end = NULL;
-}
+#define MAX_BITBUF_BIT_WRITE 56
 
 static inline void init(struct BitBuf2 *me)
 {
@@ -110,7 +78,7 @@ static inline uint32_t buffer_bits_used(struct BitBuf2 *me)
 static inline void flush_bits(struct BitBuf2 *me)
 {
        uint32_t bits;
-       _mm_stream_si64x((int64_t *) me->m_out_buf, me->m_bits);
+       store_u64(me->m_out_buf, me->m_bits);
        bits = me->m_bit_count & ~7;
        me->m_bit_count -= bits;
        me->m_out_buf += bits/8;
@@ -118,6 +86,19 @@ static inline void flush_bits(struct BitBuf2 *me)
 
 }
 
+/* Can write up to 8 bytes to output buffer */
+static inline void flush(struct BitBuf2 *me)
+{
+       uint32_t bytes;
+       if (me->m_bit_count) {
+               store_u64(me->m_out_buf, me->m_bits);
+               bytes = (me->m_bit_count + 7) / 8;
+               me->m_out_buf += bytes;
+       }
+       me->m_bits = 0;
+       me->m_bit_count = 0;
+}
+
 static inline void check_space(struct BitBuf2 *me, uint32_t num_bits)
 {
        /* Checks if bitbuf has num_bits extra space and flushes the bytes in
@@ -133,40 +114,17 @@ static inline void write_bits_unsafe(struct BitBuf2 *me, uint64_t code, uint32_t
 }
 
 static inline void write_bits(struct BitBuf2 *me, uint64_t code, uint32_t count)
-{
-#ifdef USE_BITBUF8 /*Write bits safe */
+{      /* Assumes there is space to fit code into m_bits. */
        me->m_bits |= code << me->m_bit_count;
        me->m_bit_count += count;
-       if (me->m_bit_count >= 64) {
-               _mm_stream_si64x((int64_t *) me->m_out_buf, me->m_bits);
-               me->m_out_buf += 8;
-               me->m_bit_count -= 64;
-               me->m_bits = code >> (count - me->m_bit_count);
-       }
-#elif defined(USE_BITBUFB) /* Write bits always */
-       /* Assumes there is space to fit code into m_bits. */
-       me->m_bits |= code << me->m_bit_count;
-       me->m_bit_count += count;
-       if (me->m_bit_count >= 8)
-               flush_bits(me);
-#else /* USE_BITBUF_ELSE */
-       check_space(me, count);
-       write_bits_unsafe(me, code, count);
-#endif
-
+       flush_bits(me);
 }
 
-/* Can write up to 8 bytes to output buffer */
-static inline void flush(struct BitBuf2 *me)
-{
-       uint32_t bytes;
-       if (me->m_bit_count) {
-               _mm_stream_si64x((int64_t *) me->m_out_buf, me->m_bits);
-               bytes = (me->m_bit_count + 7) / 8;
-               me->m_out_buf += bytes;
-       }
-       me->m_bits = 0;
-       me->m_bit_count = 0;
+static inline void write_bits_flush(struct BitBuf2 *me, uint64_t code, uint32_t count)
+{      /* Assumes there is space to fit code into m_bits. */
+       me->m_bits |= code << me->m_bit_count;
+       me->m_bit_count += count;
+       flush(me);
 }
 
 #endif //BITBUF2_H