coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] blake2-impl.h: use the C99's inline keyword


From: nightquick
Subject: [PATCH] blake2-impl.h: use the C99's inline keyword
Date: Tue, 13 Feb 2024 07:36:27 +0000

Note: I'm aware that there's a GitHub repository (upstream) but it doesn't seem 
like the repository is practically active anymore. There's libb2 which also 
implements blake2 (with C99 inline), but it's a little different than the 
current one. The implementation in libb2 removes *16 (e.g. load16) functions.

Apparently, this patch also "fixes" (or adds) inlining, when the compiler is 
LLVM (Clang). (Previously there was __GNUC__ and without __clang__, inline will 
only going to enabled for GCC.

Patch text
-----------

>From b57efd54ae8f232f5895cab09508a4b48c7c26ed Mon Sep 17 00:00:00 2001
From: rilysh <nightquick@proton.me>
Date: Tue, 13 Feb 2024 12:37:30 +0530
Subject: [PATCH] blake2-impl.h: use the C99's inline keyword

* src/blake2/blake2-impl.h: Use the C99 inline keyword.

C99 had introduced a new inline keyword, which replaces older compiler
style ("__inline__") extension. This also removes additional macros for
compiler check.
---
 src/blake2/blake2-impl.h | 34 +++++++++++-----------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

diff --git a/src/blake2/blake2-impl.h b/src/blake2/blake2-impl.h
index 02a1b8f..aa7e73e 100644
--- a/src/blake2/blake2-impl.h
+++ b/src/blake2/blake2-impl.h
@@ -22,19 +22,7 @@
 #include <stdint.h>
 #include <string.h>
 
-#if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 
199901L)
-  #if   defined(_MSC_VER)
-    #define BLAKE2_INLINE __inline
-  #elif defined(__GNUC__)
-    #define BLAKE2_INLINE __inline__
-  #else
-    #define BLAKE2_INLINE
-  #endif
-#else
-  #define BLAKE2_INLINE inline
-#endif
-
-static BLAKE2_INLINE uint32_t load32( const void *src )
+static inline uint32_t load32( const void *src )
 {
 #if defined(NATIVE_LITTLE_ENDIAN)
   uint32_t w;
@@ -49,7 +37,7 @@ static BLAKE2_INLINE uint32_t load32( const void *src )
 #endif
 }
 
-static BLAKE2_INLINE uint64_t load64( const void *src )
+static inline uint64_t load64( const void *src )
 {
 #if defined(NATIVE_LITTLE_ENDIAN)
   uint64_t w;
@@ -68,7 +56,7 @@ static BLAKE2_INLINE uint64_t load64( const void *src )
 #endif
 }
 
-static BLAKE2_INLINE uint16_t load16( const void *src )
+static inline uint16_t load16( const void *src )
 {
 #if defined(NATIVE_LITTLE_ENDIAN)
   uint16_t w;
@@ -81,7 +69,7 @@ static BLAKE2_INLINE uint16_t load16( const void *src )
 #endif
 }
 
-static BLAKE2_INLINE void store16( void *dst, uint16_t w )
+static inline void store16( void *dst, uint16_t w )
 {
 #if defined(NATIVE_LITTLE_ENDIAN)
   memcpy(dst, &w, sizeof w);
@@ -92,7 +80,7 @@ static BLAKE2_INLINE void store16( void *dst, uint16_t w )
 #endif
 }
 
-static BLAKE2_INLINE void store32( void *dst, uint32_t w )
+static inline void store32( void *dst, uint32_t w )
 {
 #if defined(NATIVE_LITTLE_ENDIAN)
   memcpy(dst, &w, sizeof w);
@@ -105,7 +93,7 @@ static BLAKE2_INLINE void store32( void *dst, uint32_t w )
 #endif
 }
 
-static BLAKE2_INLINE void store64( void *dst, uint64_t w )
+static inline void store64( void *dst, uint64_t w )
 {
 #if defined(NATIVE_LITTLE_ENDIAN)
   memcpy(dst, &w, sizeof w);
@@ -122,7 +110,7 @@ static BLAKE2_INLINE void store64( void *dst, uint64_t w )
 #endif
 }
 
-static BLAKE2_INLINE uint64_t load48( const void *src )
+static inline uint64_t load48( const void *src )
 {
   const uint8_t *p = ( const uint8_t * )src;
   return (( uint64_t )( p[0] ) <<  0) |
@@ -133,7 +121,7 @@ static BLAKE2_INLINE uint64_t load48( const void *src )
          (( uint64_t )( p[5] ) << 40) ;
 }
 
-static BLAKE2_INLINE void store48( void *dst, uint64_t w )
+static inline void store48( void *dst, uint64_t w )
 {
   uint8_t *p = ( uint8_t * )dst;
   p[0] = (uint8_t)(w >>  0);
@@ -144,18 +132,18 @@ static BLAKE2_INLINE void store48( void *dst, uint64_t w )
   p[5] = (uint8_t)(w >> 40);
 }
 
-static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c )
+static inline uint32_t rotr32( const uint32_t w, const unsigned c )
 {
   return ( w >> c ) | ( w << ( 32 - c ) );
 }
 
-static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
+static inline uint64_t rotr64( const uint64_t w, const unsigned c )
 {
   return ( w >> c ) | ( w << ( 64 - c ) );
 }
 
 /* prevents compiler optimizing out memset() */
-static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
+static inline void secure_zero_memory(void *v, size_t n)
 {
   static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
   memset_v(v, 0, n);
-- 
2.39.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]