| 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_SSSE3 |
| 12 |
#if defined(__clang__) |
| 13 |
#pragma clang attribute push (__attribute__((target("ssse3"))), apply_to=function) |
| 14 |
#else |
| 15 |
#pragma GCC target("ssse3") |
| 16 |
#endif |
| 17 |
#include <tmmintrin.h> |
| 18 |
|
| 19 |
// Only enable inline assembly on supported compilers and on 64-bit CPUs. |
| 20 |
// 32-bit CPUs with SSSE3 support, such as low-end Atoms, only have eight XMM |
| 21 |
// registers, which is not enough to run the inline assembly. |
| 22 |
#ifndef BASE64_SSSE3_USE_ASM |
| 23 |
# if (defined(__GNUC__) || defined(__clang__)) && BASE64_WORDSIZE == 64 |
| 24 |
# define BASE64_SSSE3_USE_ASM 1 |
| 25 |
# else |
| 26 |
# define BASE64_SSSE3_USE_ASM 0 |
| 27 |
# endif |
| 28 |
#endif |
| 29 |
|
| 30 |
#include "dec_reshuffle.c" |
| 31 |
#include "dec_loop.c" |
| 32 |
|
| 33 |
#if BASE64_SSSE3_USE_ASM |
| 34 |
# include "enc_loop_asm.c" |
| 35 |
#else |
| 36 |
# include "enc_reshuffle.c" |
| 37 |
# include "enc_translate.c" |
| 38 |
# include "enc_loop.c" |
| 39 |
#endif |
| 40 |
|
| 41 |
#endif // HAVE_SSSE3 |
| 42 |
|
| 43 |
void |
| 44 |
base64_stream_encode_ssse3 BASE64_ENC_PARAMS |
| 45 |
{ |
| 46 |
#if HAVE_SSSE3 |
| 47 |
#include "../generic/enc_head.c" |
| 48 |
enc_loop_ssse3(&s, &slen, &o, &olen); |
| 49 |
#include "../generic/enc_tail.c" |
| 50 |
#else |
| 51 |
base64_enc_stub(state, src, srclen, out, outlen); |
| 52 |
#endif |
| 53 |
} |
| 54 |
|
| 55 |
int |
| 56 |
base64_stream_decode_ssse3 BASE64_DEC_PARAMS |
| 57 |
{ |
| 58 |
#if HAVE_SSSE3 |
| 59 |
#include "../generic/dec_head.c" |
| 60 |
dec_loop_ssse3(&s, &slen, &o, &olen); |
| 61 |
#include "../generic/dec_tail.c" |
| 62 |
#if defined(__clang__) |
| 63 |
#pragma clang attribute pop |
| 64 |
#endif |
| 65 |
#else |
| 66 |
return base64_dec_stub(state, src, srclen, out, outlen); |
| 67 |
#endif |
| 68 |
} |