diff --git a/lib/codec_avx2.c b/lib/codec_avx2.c index ef931f66..934a7273 100644 --- a/lib/codec_avx2.c +++ b/lib/codec_avx2.c @@ -1,5 +1,6 @@ #include #include +#include #include "../include/libbase64.h" #include "codecs.h" diff --git a/lib/codec_neon32.c b/lib/codec_neon32.c index b70b91c6..41f0b1f1 100644 --- a/lib/codec_neon32.c +++ b/lib/codec_neon32.c @@ -4,6 +4,7 @@ #include #include +#include #ifdef __ARM_NEON__ #include #endif diff --git a/lib/codec_neon64.c b/lib/codec_neon64.c index 920ab222..aafa27f5 100644 --- a/lib/codec_neon64.c +++ b/lib/codec_neon64.c @@ -4,6 +4,7 @@ #include #include +#include #ifdef __ARM_NEON__ #include #endif diff --git a/lib/codec_plain.c b/lib/codec_plain.c index 02f5f369..1d987fae 100644 --- a/lib/codec_plain.c +++ b/lib/codec_plain.c @@ -1,5 +1,6 @@ #include #include +#include #include "../include/libbase64.h" #include "codecs.h" @@ -7,9 +8,9 @@ BASE64_ENC_FUNCTION(plain) { #include "enc/head.c" -#if __WORDSIZE == 32 +#if BASE64_WORDSIZE == 32 #include "enc/uint32.c" -#elif __WORDSIZE == 64 +#elif BASE64_WORDSIZE == 64 #include "enc/uint64.c" #endif #include "enc/tail.c" @@ -18,9 +19,9 @@ BASE64_ENC_FUNCTION(plain) BASE64_DEC_FUNCTION(plain) { #include "dec/head.c" -#if __WORDSIZE == 32 +#if BASE64_WORDSIZE == 32 #include "dec/uint32.c" -#elif __WORDSIZE == 64 +#elif BASE64_WORDSIZE == 64 #include "dec/uint64.c" #endif #include "dec/tail.c" diff --git a/lib/codec_ssse3.c b/lib/codec_ssse3.c index d561521c..dbadf31c 100644 --- a/lib/codec_ssse3.c +++ b/lib/codec_ssse3.c @@ -1,5 +1,6 @@ #include #include +#include #include "../include/libbase64.h" #include "codecs.h" diff --git a/lib/codecs.h b/lib/codecs.h index 586db25c..c90b5cd1 100644 --- a/lib/codecs.h +++ b/lib/codecs.h @@ -58,31 +58,45 @@ struct codec // Define machine endianness. This is for GCC: #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - #define LITTLE_ENDIAN 1 + #define BASE64_LITTLE_ENDIAN 1 #else - #define LITTLE_ENDIAN 0 + #define BASE64_LITTLE_ENDIAN 0 #endif // This is for Clang: #ifdef __LITTLE_ENDIAN__ - #define LITTLE_ENDIAN 1 + #define BASE64_LITTLE_ENDIAN 1 #endif #ifdef __BIG_ENDIAN__ - #define LITTLE_ENDIAN 0 + #define BASE64_LITTLE_ENDIAN 0 #endif // Endian conversion functions -#if LITTLE_ENDIAN +#if BASE64_LITTLE_ENDIAN +#ifdef _MSC_VER + #define cpu_to_be32(x) _byteswap_ulong(x) + #define cpu_to_be64(x) _byteswap_uint64(x) + #define be32_to_cpu(x) _byteswap_ulong(x) + #define be64_to_cpu(x) _byteswap_uint64(x) +#else #define cpu_to_be32(x) __builtin_bswap32(x) #define cpu_to_be64(x) __builtin_bswap64(x) #define be32_to_cpu(x) __builtin_bswap32(x) #define be64_to_cpu(x) __builtin_bswap64(x) +#endif #else #define cpu_to_be32(x) (x) #define cpu_to_be64(x) (x) #define be32_to_cpu(x) (x) #define be64_to_cpu(x) (x) +#endif + +// detect word size +#ifdef _INTEGRAL_MAX_BITS +#define BASE64_WORDSIZE _INTEGRAL_MAX_BITS +#else +#define BASE64_WORDSIZE __WORDSIZE #endif void codec_choose (struct codec *, int flags); diff --git a/lib/lib_openmp.c b/lib/lib_openmp.c index c61b0776..7369a725 100644 --- a/lib/lib_openmp.c +++ b/lib/lib_openmp.c @@ -24,7 +24,7 @@ base64_encode_openmp size_t t; size_t sum = 0, len, last_len; struct base64_state state, initial_state; - int num_threads; + int num_threads, i; // Request a number of threads but not necessarily get them: #pragma omp parallel @@ -50,7 +50,7 @@ base64_encode_openmp // Single has an implicit barrier for all threads to wait here // for the above to complete: #pragma omp for firstprivate(state) private(s) reduction(+:sum) schedule(static,1) - for (int i = 0; i < num_threads; i++) + for (i = 0; i < num_threads; i++) { // Feed each part of the string to the stream reader: base64_stream_encode(&state, src + i * len, len, out + i * len * 4 / 3, &s); @@ -82,7 +82,7 @@ base64_decode_openmp , int flags ) { - int num_threads, result = 0; + int num_threads, result = 0, i; size_t sum = 0, len, last_len, s; struct base64_state state, initial_state; @@ -111,7 +111,7 @@ base64_decode_openmp // Single has an implicit barrier to wait here for the above to // complete: #pragma omp for firstprivate(state) private(s) reduction(+:sum, result) schedule(static,1) - for (int i = 0; i < num_threads; i++) + for (i = 0; i < num_threads; i++) { int this_result;