Debian Codegraph @

mypyc/lib-rt/base64/arch/avx/codec.c

raw
1 #include <stdint.h>
2 #include <stddef.h>
3 #include <stdlib.h>
4
5 #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 #if defined(__clang__)
13 #pragma clang attribute push (__attribute__((target("avx"))), apply_to=function)
14 #else
15 #pragma GCC target("avx")
16 #endif
17 #include <immintrin.h>
18
19 // Only enable inline assembly on supported compilers and on 64-bit CPUs.
20 #ifndef BASE64_AVX_USE_ASM
21 # if (defined(__GNUC__) || defined(__clang__)) && BASE64_WORDSIZE == 64
22 # define BASE64_AVX_USE_ASM 1
23 # else
24 # define BASE64_AVX_USE_ASM 0
25 # endif
26 #endif
27
28 #include "../ssse3/dec_reshuffle.c"
29 #include "../ssse3/dec_loop.c"
30
31 #if BASE64_AVX_USE_ASM
32 # include "./enc_loop_asm.c"
33 #else
34 # include "../ssse3/enc_translate.c"
35 # include "../ssse3/enc_reshuffle.c"
36 # include "../ssse3/enc_loop.c"
37 #endif
38
39 #endif // HAVE_AVX
40
41 void
42 base64_stream_encode_avx BASE64_ENC_PARAMS
43 {
44 #if HAVE_AVX
45 #include "../generic/enc_head.c"
46
47 // For supported compilers, use a hand-optimized inline assembly
48 // encoder. Otherwise fall back on the SSSE3 encoder, but compiled with
49 // AVX flags to generate better optimized AVX code.
50
51 #if BASE64_AVX_USE_ASM
52 enc_loop_avx(&s, &slen, &o, &olen);
53 #else
54 enc_loop_ssse3(&s, &slen, &o, &olen);
55 #endif
56
57 #include "../generic/enc_tail.c"
58 #else
59 base64_enc_stub(state, src, srclen, out, outlen);
60 #endif
61 }
62
63 int
64 base64_stream_decode_avx BASE64_DEC_PARAMS
65 {
66 #if HAVE_AVX
67 #include "../generic/dec_head.c"
68 dec_loop_ssse3(&s, &slen, &o, &olen);
69 #include "../generic/dec_tail.c"
70 #if defined(__clang__)
71 #pragma clang attribute pop
72 #endif
73 #else
74 return base64_dec_stub(state, src, srclen, out, outlen);
75 #endif
76 }