Skip to content

Commit

Permalink
cleanup: lib/codecs: remove function name macro
Browse files Browse the repository at this point in the history
Remove the macro that generates the function name, and replace it by
just writing out the name of the function. It's maybe a bit less
"clever", but it's much more readable.
  • Loading branch information
aklomp committed Feb 28, 2024
1 parent f477638 commit 06f9989
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 33 deletions.
6 changes: 4 additions & 2 deletions lib/arch/avx/codec.c
Expand Up @@ -33,7 +33,8 @@

#endif // HAVE_AVX

BASE64_ENC_FUNCTION(avx)
void
base64_stream_encode_avx BASE64_ENC_PARAMS
{
#if HAVE_AVX
#include "../generic/enc_head.c"
Expand All @@ -54,7 +55,8 @@ BASE64_ENC_FUNCTION(avx)
#endif
}

BASE64_DEC_FUNCTION(avx)
int
base64_stream_decode_avx BASE64_DEC_PARAMS
{
#if HAVE_AVX
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/avx2/codec.c
Expand Up @@ -33,7 +33,8 @@

#endif // HAVE_AVX2

BASE64_ENC_FUNCTION(avx2)
void
base64_stream_encode_avx2 BASE64_ENC_PARAMS
{
#if HAVE_AVX2
#include "../generic/enc_head.c"
Expand All @@ -44,7 +45,8 @@ BASE64_ENC_FUNCTION(avx2)
#endif
}

BASE64_DEC_FUNCTION(avx2)
int
base64_stream_decode_avx2 BASE64_DEC_PARAMS
{
#if HAVE_AVX2
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/avx512/codec.c
Expand Up @@ -18,7 +18,8 @@

#endif // HAVE_AVX512

BASE64_ENC_FUNCTION(avx512)
void
base64_stream_encode_avx512 BASE64_ENC_PARAMS
{
#if HAVE_AVX512
#include "../generic/enc_head.c"
Expand All @@ -30,7 +31,8 @@ BASE64_ENC_FUNCTION(avx512)
}

// Reuse AVX2 decoding. Not supporting AVX512 at present
BASE64_DEC_FUNCTION(avx512)
int
base64_stream_decode_avx512 BASE64_DEC_PARAMS
{
#if HAVE_AVX512
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/generic/codec.c
Expand Up @@ -18,7 +18,8 @@
# include "32/dec_loop.c"
#endif

BASE64_ENC_FUNCTION(plain)
void
base64_stream_encode_plain BASE64_ENC_PARAMS
{
#include "enc_head.c"
#if BASE64_WORDSIZE == 32
Expand All @@ -29,7 +30,8 @@ BASE64_ENC_FUNCTION(plain)
#include "enc_tail.c"
}

BASE64_DEC_FUNCTION(plain)
int
base64_stream_decode_plain BASE64_DEC_PARAMS
{
#include "dec_head.c"
#if BASE64_WORDSIZE >= 32
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/neon32/codec.c
Expand Up @@ -52,7 +52,8 @@ vqtbl1q_u8 (const uint8x16_t lut, const uint8x16_t indices)
// (48 bytes encode, 32 bytes decode) that we inline the
// uint32 codec to stay performant on smaller inputs.

BASE64_ENC_FUNCTION(neon32)
void
base64_stream_encode_neon32 BASE64_ENC_PARAMS
{
#ifdef BASE64_USE_NEON32
#include "../generic/enc_head.c"
Expand All @@ -64,7 +65,8 @@ BASE64_ENC_FUNCTION(neon32)
#endif
}

BASE64_DEC_FUNCTION(neon32)
int
base64_stream_decode_neon32 BASE64_DEC_PARAMS
{
#ifdef BASE64_USE_NEON32
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/neon64/codec.c
Expand Up @@ -72,7 +72,8 @@ load_64byte_table (const uint8_t *p)
// (48 bytes encode, 64 bytes decode) that we inline the
// uint64 codec to stay performant on smaller inputs.

BASE64_ENC_FUNCTION(neon64)
void
base64_stream_encode_neon64 BASE64_ENC_PARAMS
{
#ifdef BASE64_USE_NEON64
#include "../generic/enc_head.c"
Expand All @@ -84,7 +85,8 @@ BASE64_ENC_FUNCTION(neon64)
#endif
}

BASE64_DEC_FUNCTION(neon64)
int
base64_stream_decode_neon64 BASE64_DEC_PARAMS
{
#ifdef BASE64_USE_NEON64
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/sse41/codec.c
Expand Up @@ -33,7 +33,8 @@

#endif // HAVE_SSE41

BASE64_ENC_FUNCTION(sse41)
void
base64_stream_encode_sse41 BASE64_ENC_PARAMS
{
#if HAVE_SSE41
#include "../generic/enc_head.c"
Expand All @@ -44,7 +45,8 @@ BASE64_ENC_FUNCTION(sse41)
#endif
}

BASE64_DEC_FUNCTION(sse41)
int
base64_stream_decode_sse41 BASE64_DEC_PARAMS
{
#if HAVE_SSE41
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/sse42/codec.c
Expand Up @@ -33,7 +33,8 @@

#endif // HAVE_SSE42

BASE64_ENC_FUNCTION(sse42)
void
base64_stream_encode_sse42 BASE64_ENC_PARAMS
{
#if HAVE_SSE42
#include "../generic/enc_head.c"
Expand All @@ -44,7 +45,8 @@ BASE64_ENC_FUNCTION(sse42)
#endif
}

BASE64_DEC_FUNCTION(sse42)
int
base64_stream_decode_sse42 BASE64_DEC_PARAMS
{
#if HAVE_SSE42
#include "../generic/dec_head.c"
Expand Down
6 changes: 4 additions & 2 deletions lib/arch/ssse3/codec.c
Expand Up @@ -35,7 +35,8 @@

#endif // HAVE_SSSE3

BASE64_ENC_FUNCTION(ssse3)
void
base64_stream_encode_ssse3 BASE64_ENC_PARAMS
{
#if HAVE_SSSE3
#include "../generic/enc_head.c"
Expand All @@ -46,7 +47,8 @@ BASE64_ENC_FUNCTION(ssse3)
#endif
}

BASE64_DEC_FUNCTION(ssse3)
int
base64_stream_decode_ssse3 BASE64_DEC_PARAMS
{
#if HAVE_SSSE3
#include "../generic/dec_head.c"
Expand Down
6 changes: 3 additions & 3 deletions lib/codec_choose.c
Expand Up @@ -78,9 +78,9 @@
#endif

// Function declarations:
#define BASE64_CODEC_FUNCS(arch) \
BASE64_ENC_FUNCTION(arch); \
BASE64_DEC_FUNCTION(arch); \
#define BASE64_CODEC_FUNCS(arch) \
extern void base64_stream_encode_ ## arch BASE64_ENC_PARAMS; \
extern int base64_stream_decode_ ## arch BASE64_DEC_PARAMS;

BASE64_CODEC_FUNCS(avx512)
BASE64_CODEC_FUNCS(avx2)
Expand Down
12 changes: 0 additions & 12 deletions lib/codecs.h
Expand Up @@ -18,18 +18,6 @@
, size_t *outlen \
)

// Function signature for encoding functions:
#define BASE64_ENC_FUNCTION(arch) \
void \
base64_stream_encode_ ## arch \
BASE64_ENC_PARAMS

// Function signature for decoding functions:
#define BASE64_DEC_FUNCTION(arch) \
int \
base64_stream_decode_ ## arch \
BASE64_DEC_PARAMS

// This function is used as a stub when a certain encoder is not compiled in.
// It discards the inputs and returns zero output bytes.
static inline void
Expand Down

0 comments on commit 06f9989

Please sign in to comment.