]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix : unused attribute for FORCE_INLINE functions
authorYann Collet <cyan@fb.com>
Wed, 14 Jun 2023 23:32:51 +0000 (16:32 -0700)
committerYann Collet <cyan@fb.com>
Wed, 14 Jun 2023 23:32:51 +0000 (16:32 -0700)
fix2 : reloadDStreamFast is used by decompress4x2,
modified the entry point, so that it works fine in this case too.

lib/common/bitstream.h
lib/common/compiler.h
lib/legacy/zstd_v04.c

index 374f2b6890279a3158c8d4cdeb3ea75c746accbb..a737f011cb53e885ef8180d12f600dbcebc72ef4 100644 (file)
@@ -375,23 +375,34 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
     return value;
 }
 
-/*! BIT_reloadDStreamFast() :
+/*! BIT_reloadDStream_internal() :
  *  Simple variant of BIT_reloadDStream(), with two conditions:
- *  1. bitsConsumed <= sizeof(bitD->bitContainer)*8
- *  2. bitD->ptr >= bitD->limitPtr
- *  These conditions guarantee that bitstream is in a valid state,
- *  and shifting the position of the look window is safe.
+ *  1. bitstream is valid : bitsConsumed <= sizeof(bitD->bitContainer)*8
+ *  2. look window is valid after shifted down : bitD->ptr >= bitD->start
  */
-MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
+MEM_STATIC BIT_DStream_status BIT_reloadDStream_internal(BIT_DStream_t* bitD)
 {
     assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
-    assert(bitD->ptr >= bitD->limitPtr);
     bitD->ptr -= bitD->bitsConsumed >> 3;
+    assert(bitD->ptr >= bitD->start);
     bitD->bitsConsumed &= 7;
     bitD->bitContainer = MEM_readLEST(bitD->ptr);
     return BIT_DStream_unfinished;
 }
 
+/*! BIT_reloadDStreamFast() :
+ *  Similar to BIT_reloadDStream(), but with two differences:
+ *  1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
+ *  2. Returns BIT_DStream_overflow when bitD->ptr < bitD->limitPtr, at this
+ *     point you must use BIT_reloadDStream() to reload.
+ */
+MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
+{
+    if (UNLIKELY(bitD->ptr < bitD->limitPtr))
+        return BIT_DStream_overflow;
+    return BIT_reloadDStream_internal(bitD);
+}
+
 /*! BIT_reloadDStream() :
  *  Refill `bitD` from buffer previously set in BIT_initDStream() .
  *  This function is safe, it guarantees it will not never beyond src buffer.
@@ -410,7 +421,7 @@ FORCE_INLINE_TEMPLATE BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
     assert(bitD->ptr >= bitD->start);
 
     if (bitD->ptr >= bitD->limitPtr) {
-        return BIT_reloadDStreamFast(bitD);
+        return BIT_reloadDStream_internal(bitD);
     }
     if (bitD->ptr == bitD->start) {
         /* reached end of bitStream => no update */
index 1cde912f911b0a5cbc54bdb942815f07d48b0d23..35b9c138793b539cd7d8aa65a2e0eed95ecbefbb 100644 (file)
 #  define WIN_CDECL
 #endif
 
+/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
+#if defined(__GNUC__)
+#  define UNUSED_ATTR __attribute__((unused))
+#else
+#  define UNUSED_ATTR
+#endif
+
 /**
  * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
  * parameters. They must be inlined for the compiler to eliminate the constant
  * branches.
  */
-#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
+#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR UNUSED_ATTR
 /**
  * HINT_INLINE is used to help the compiler generate better code. It is *not*
  * used for "templates", so it can be tweaked based on the compilers
 #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5
 #  define HINT_INLINE static INLINE_KEYWORD
 #else
-#  define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR
-#endif
-
-/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
-#if defined(__GNUC__)
-#  define UNUSED_ATTR __attribute__((unused))
-#else
-#  define UNUSED_ATTR
+#  define HINT_INLINE FORCE_INLINE_TEMPLATE
 #endif
 
 /* "soft" inline :
index 57be832bd32f4cede8eaaffd64318c02980db97c..fa65160bcc8740fd3b289e5ba3c9c5b43e3d6d1f 100644 (file)
@@ -37,15 +37,6 @@ extern "C" {
 #   include <stdlib.h>  /* _byteswap_ulong */
 #   include <intrin.h>  /* _byteswap_* */
 #endif
-#if defined(__GNUC__)
-#  define MEM_STATIC static __attribute__((unused))
-#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
-#  define MEM_STATIC static inline
-#elif defined(_MSC_VER)
-#  define MEM_STATIC static __inline
-#else
-#  define MEM_STATIC static  /* this version may generate warnings for unused static functions; disable the relevant warning */
-#endif
 
 
 /****************************************************************