codec.c 1.4 KB

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