codec.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_AVX2
  10. #include <immintrin.h>
  11. // Only enable inline assembly on supported compilers and on 64-bit CPUs.
  12. #ifndef BASE64_AVX2_USE_ASM
  13. # if (defined(__GNUC__) || defined(__clang__)) && BASE64_WORDSIZE == 64
  14. # define BASE64_AVX2_USE_ASM 1
  15. # else
  16. # define BASE64_AVX2_USE_ASM 0
  17. # endif
  18. #endif
  19. #include "dec_reshuffle.c"
  20. #include "dec_loop.c"
  21. #if BASE64_AVX2_USE_ASM
  22. # include "enc_loop_asm.c"
  23. #else
  24. # include "enc_translate.c"
  25. # include "enc_reshuffle.c"
  26. # include "enc_loop.c"
  27. #endif
  28. #endif // HAVE_AVX2
  29. BASE64_ENC_FUNCTION(avx2)
  30. {
  31. #if HAVE_AVX2
  32. #include "../generic/enc_head.c"
  33. enc_loop_avx2(&s, &slen, &o, &olen);
  34. #include "../generic/enc_tail.c"
  35. #else
  36. BASE64_ENC_STUB
  37. #endif
  38. }
  39. BASE64_DEC_FUNCTION(avx2)
  40. {
  41. #if HAVE_AVX2
  42. #include "../generic/dec_head.c"
  43. dec_loop_avx2(&s, &slen, &o, &olen);
  44. #include "../generic/dec_tail.c"
  45. #else
  46. BASE64_DEC_STUB
  47. #endif
  48. }