1 #include <stdint.h>
2 #include <stddef.h>
3 #include <stdlib.h>
4
5 #include "../../../include/libbase64.h"
6 #include "../../tables/tables.h"
7 #include "../../codecs.h"
8 #include "config.h"
9 #include "../../env.h"
10
11 #if HAVE_AVX
12 #include <immintrin.h>
13
14 // Only enable inline assembly on supported compilers and on 64-bit CPUs.
15 #ifndef BASE64_AVX_USE_ASM
16 # if (defined(__GNUC__) || defined(__clang__)) && BASE64_WORDSIZE == 64
17 # define BASE64_AVX_USE_ASM 1
18 # else
19 # define BASE64_AVX_USE_ASM 0
20 # endif
21 #endif
22
23 #include "../ssse3/dec_reshuffle.c"
24 #include "../ssse3/dec_loop.c"
25
26 #if BASE64_AVX_USE_ASM
27 # include "enc_loop_asm.c"
28 #else
29 # include "../ssse3/enc_translate.c"
30 # include "../ssse3/enc_reshuffle.c"
31 # include "../ssse3/enc_loop.c"
32 #endif
33
34 #endif // HAVE_AVX
35
BASE64_ENC_FUNCTION(avx)36 BASE64_ENC_FUNCTION(avx)
37 {
38 #if HAVE_AVX
39 #include "../generic/enc_head.c"
40
41 // For supported compilers, use a hand-optimized inline assembly
42 // encoder. Otherwise fall back on the SSSE3 encoder, but compiled with
43 // AVX flags to generate better optimized AVX code.
44
45 #if BASE64_AVX_USE_ASM
46 enc_loop_avx(&s, &slen, &o, &olen);
47 #else
48 enc_loop_ssse3(&s, &slen, &o, &olen);
49 #endif
50
51 #include "../generic/enc_tail.c"
52 #else
53 BASE64_ENC_STUB
54 #endif
55 }
56
BASE64_DEC_FUNCTION(avx)57 BASE64_DEC_FUNCTION(avx)
58 {
59 #if HAVE_AVX
60 #include "../generic/dec_head.c"
61 dec_loop_ssse3(&s, &slen, &o, &olen);
62 #include "../generic/dec_tail.c"
63 #else
64 BASE64_DEC_STUB
65 #endif
66 }
67