xz_config.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Private includes and definitions for userspace use of XZ Embedded
  3. *
  4. * Author: Lasse Collin <lasse.collin@tukaani.org>
  5. *
  6. * This file has been put into the public domain.
  7. * You can do whatever you want with this file.
  8. */
  9. #ifndef XZ_CONFIG_H
  10. #define XZ_CONFIG_H
  11. /* Uncomment as needed to enable BCJ filter decoders. */
  12. /* #define XZ_DEC_X86 */
  13. /* #define XZ_DEC_POWERPC */
  14. /* #define XZ_DEC_IA64 */
  15. /* #define XZ_DEC_ARM */
  16. /* #define XZ_DEC_ARMTHUMB */
  17. /* #define XZ_DEC_SPARC */
  18. #include <stdbool.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "xz.h"
  22. #define kmalloc(size, flags) malloc(size)
  23. #define kfree(ptr) free(ptr)
  24. #define vmalloc(size) malloc(size)
  25. #define vfree(ptr) free(ptr)
  26. #define memeq(a, b, size) (memcmp(a, b, size) == 0)
  27. #define memzero(buf, size) memset(buf, 0, size)
  28. #undef min
  29. #undef min_t
  30. #define min(x, y) ((x) < (y) ? (x) : (y))
  31. #define min_t(type, x, y) min(x, y)
  32. /*
  33. * Some functions have been marked with __always_inline to keep the
  34. * performance reasonable even when the compiler is optimizing for
  35. * small code size. You may be able to save a few bytes by #defining
  36. * __always_inline to plain inline, but don't complain if the code
  37. * becomes slow.
  38. *
  39. * NOTE: System headers on GNU/Linux may #define this macro already,
  40. * so if you want to change it, you need to #undef it first.
  41. */
  42. #ifndef __always_inline
  43. # ifdef __GNUC__
  44. # define __always_inline \
  45. inline __attribute__((__always_inline__))
  46. # else
  47. # define __always_inline inline
  48. # endif
  49. #endif
  50. /*
  51. * Some functions are marked to never be inlined to reduce stack usage.
  52. * If you don't care about stack usage, you may want to modify this so
  53. * that noinline_for_stack is #defined to be empty even when using GCC.
  54. * Doing so may save a few bytes in binary size.
  55. */
  56. #ifndef noinline_for_stack
  57. # ifdef __GNUC__
  58. # define noinline_for_stack __attribute__((__noinline__))
  59. # else
  60. # define noinline_for_stack
  61. # endif
  62. #endif
  63. /* Inline functions to access unaligned unsigned 32-bit integers */
  64. #ifndef get_unaligned_le32
  65. static inline uint32_t XZ_FUNC get_unaligned_le32(const uint8_t *buf)
  66. {
  67. return (uint32_t)buf[0]
  68. | ((uint32_t)buf[1] << 8)
  69. | ((uint32_t)buf[2] << 16)
  70. | ((uint32_t)buf[3] << 24);
  71. }
  72. #endif
  73. #ifndef get_unaligned_be32
  74. static inline uint32_t XZ_FUNC get_unaligned_be32(const uint8_t *buf)
  75. {
  76. return (uint32_t)(buf[0] << 24)
  77. | ((uint32_t)buf[1] << 16)
  78. | ((uint32_t)buf[2] << 8)
  79. | (uint32_t)buf[3];
  80. }
  81. #endif
  82. #ifndef put_unaligned_le32
  83. static inline void XZ_FUNC put_unaligned_le32(uint32_t val, uint8_t *buf)
  84. {
  85. buf[0] = (uint8_t)val;
  86. buf[1] = (uint8_t)(val >> 8);
  87. buf[2] = (uint8_t)(val >> 16);
  88. buf[3] = (uint8_t)(val >> 24);
  89. }
  90. #endif
  91. #ifndef put_unaligned_be32
  92. static inline void XZ_FUNC put_unaligned_be32(uint32_t val, uint8_t *buf)
  93. {
  94. buf[0] = (uint8_t)(val >> 24);
  95. buf[1] = (uint8_t)(val >> 16);
  96. buf[2] = (uint8_t)(val >> 8);
  97. buf[3] = (uint8_t)val;
  98. }
  99. #endif
  100. /*
  101. * Use get_unaligned_le32() also for aligned access for simplicity. On
  102. * little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
  103. * could save a few bytes in code size.
  104. */
  105. #ifndef get_le32
  106. # define get_le32 get_unaligned_le32
  107. #endif
  108. #endif