functable.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* functable.h -- Struct containing function pointers to optimized functions
  2. * Copyright (C) 2017 Hans Kristian Rosbach
  3. * For conditions of distribution and use, see copyright notice in zlib.h
  4. */
  5. #ifndef FUNCTABLE_H_
  6. #define FUNCTABLE_H_
  7. #include "deflate.h"
  8. #include "crc32.h"
  9. #ifdef DISABLE_RUNTIME_CPU_DETECTION
  10. # include "arch_functions.h"
  11. /* When compiling with native instructions it is not necessary to use functable.
  12. * Instead we use native_ macro indicating the best available variant of arch-specific
  13. * functions for the current platform.
  14. */
  15. # define FUNCTABLE_INIT ((void)0)
  16. # define FUNCTABLE_CALL(name) native_ ## name
  17. # define FUNCTABLE_FPTR(name) &native_ ## name
  18. #else
  19. struct functable_s {
  20. void (* force_init) (void);
  21. uint32_t (* adler32) (uint32_t adler, const uint8_t *buf, size_t len);
  22. uint32_t (* adler32_fold_copy) (uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len);
  23. uint8_t* (* chunkmemset_safe) (uint8_t *out, unsigned dist, unsigned len, unsigned left);
  24. uint32_t (* chunksize) (void);
  25. uint32_t (* compare256) (const uint8_t *src0, const uint8_t *src1);
  26. uint32_t (* crc32) (uint32_t crc, const uint8_t *buf, size_t len);
  27. void (* crc32_fold) (struct crc32_fold_s *crc, const uint8_t *src, size_t len, uint32_t init_crc);
  28. void (* crc32_fold_copy) (struct crc32_fold_s *crc, uint8_t *dst, const uint8_t *src, size_t len);
  29. uint32_t (* crc32_fold_final) (struct crc32_fold_s *crc);
  30. uint32_t (* crc32_fold_reset) (struct crc32_fold_s *crc);
  31. void (* inflate_fast) (PREFIX3(stream) *strm, uint32_t start);
  32. uint32_t (* longest_match) (deflate_state *const s, Pos cur_match);
  33. uint32_t (* longest_match_slow) (deflate_state *const s, Pos cur_match);
  34. void (* slide_hash) (deflate_state *s);
  35. };
  36. Z_INTERNAL extern struct functable_s functable;
  37. /* Explicitly indicate functions are conditionally dispatched.
  38. */
  39. # define FUNCTABLE_INIT functable.force_init()
  40. # define FUNCTABLE_CALL(name) functable.name
  41. # define FUNCTABLE_FPTR(name) functable.name
  42. #endif
  43. #endif