#if defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
#if !defined(_M_ARM64EC)
+#if defined(HAVE_AVX2_INTRINSICS)
#define STRINGIFY_IMPLEMENTATION_(a) #a
#define STRINGIFY(a) STRINGIFY_IMPLEMENTATION_(a)
return (size_t)(out - (uint8_t *)dst) + evp_encodeblock_int(ctx, out, src + i, srclen - i, final_wrap_cnt);
}
OPENSSL_UNTARGET_AVX2
+#endif /* defined(HAVE_AVX2_INTRINSICS) */
#endif /* !defined(_M_ARM64EC) */
#endif
#include <openssl/evp.h>
#include <stddef.h>
+#if defined(__clang__)
+#define HAVE_AVX2_INTRINSICS 1
+#elif defined(__GNUC__) && (__GNUC__ >= 8)
+#define HAVE_AVX2_INTRINSICS 1
+#elif defined(_MSC_VER) && (_MSC_VER >= 1920) /* MSVC 2019 */
+#define HAVE_AVX2_INTRINSICS 1
+#endif
+
#if defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64)
#if !defined(_M_ARM64EC)
+#if defined(HAVE_AVX2_INTRINSICS)
size_t encode_base64_avx2(EVP_ENCODE_CTX *ctx,
unsigned char *out, const unsigned char *src, int srclen,
int newlines, int *wrap_cnt);
+#endif /* defined(HAVE_AVX2_INTRINSICS) */
#endif /* !defined(_M_ARM64EC) */
#endif
j = evp_encodeblock_int(ctx, out, in, inl - (inl % EVP_ENCODE_B64_LENGTH),
&wrap_cnt);
} else {
-#if defined(__AVX2__)
+#if defined(__AVX2__) && defined(HAVE_AVX2_INTRINSICS)
const int newlines = !(ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) ? EVP_ENCODE_B64_LENGTH : 0;
j = encode_base64_avx2(ctx,
(unsigned char *)out,
(const unsigned char *)in,
inl - (inl % EVP_ENCODE_B64_LENGTH), newlines, &wrap_cnt);
-#elif defined(HAS_IA32CAP_IS_64)
+#elif defined(HAS_IA32CAP_IS_64) && defined(HAVE_AVX2_INTRINSICS)
if ((OPENSSL_ia32cap_P[2] & (1u << 5)) != 0) {
const int newlines = !(ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) ? EVP_ENCODE_B64_LENGTH : 0;
{
int wrap_cnt = 0;
-#if defined(__AVX2__)
+#if defined(__AVX2__) && defined(HAVE_AVX2_INTRINSICS)
return (int)encode_base64_avx2(NULL, t, f, dlen, 0, &wrap_cnt);
-#elif defined(HAS_IA32CAP_IS_64)
+#elif defined(HAS_IA32CAP_IS_64) && defined(HAVE_AVX2_INTRINSICS)
if ((OPENSSL_ia32cap_P[2] & (1u << 5)) != 0)
return (int)encode_base64_avx2(NULL, t, f, dlen, 0, &wrap_cnt);
else