mem_ops_aligned.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VPX_PORTS_MEM_OPS_ALIGNED_H_
  11. #define VPX_PORTS_MEM_OPS_ALIGNED_H_
  12. #include "vpx/vpx_integer.h"
  13. /* \file
  14. * \brief Provides portable memory access primitives for operating on aligned
  15. * data
  16. *
  17. * This file is split from mem_ops.h for easier maintenance. See mem_ops.h
  18. * for a more detailed description of these primitives.
  19. */
  20. #ifndef INCLUDED_BY_MEM_OPS_H
  21. #error Include mem_ops.h, not mem_ops_aligned.h directly.
  22. #endif
  23. /* Architectures that provide instructions for doing this byte swapping
  24. * could redefine these macros.
  25. */
  26. #define swap_endian_16(val,raw) do {\
  27. val = (uint16_t)(((raw>>8) & 0x00ff) \
  28. | ((raw<<8) & 0xff00));\
  29. } while(0)
  30. #define swap_endian_32(val,raw) do {\
  31. val = ((raw>>24) & 0x000000ff) \
  32. | ((raw>>8) & 0x0000ff00) \
  33. | ((raw<<8) & 0x00ff0000) \
  34. | ((raw<<24) & 0xff000000); \
  35. } while(0)
  36. #define swap_endian_16_se(val,raw) do {\
  37. swap_endian_16(val,raw);\
  38. val = ((val << 16) >> 16);\
  39. } while(0)
  40. #define swap_endian_32_se(val,raw) swap_endian_32(val,raw)
  41. #define mem_get_ne_aligned_generic(end,sz) \
  42. static VPX_INLINE unsigned MEM_VALUE_T \
  43. mem_get_##end##sz##_aligned(const void *vmem) {\
  44. const uint##sz##_t *mem = (const uint##sz##_t *)vmem;\
  45. return *mem;\
  46. }
  47. #define mem_get_sne_aligned_generic(end,sz) \
  48. static VPX_INLINE signed MEM_VALUE_T \
  49. mem_get_s##end##sz##_aligned(const void *vmem) {\
  50. const int##sz##_t *mem = (const int##sz##_t *)vmem;\
  51. return *mem;\
  52. }
  53. #define mem_get_se_aligned_generic(end,sz) \
  54. static VPX_INLINE unsigned MEM_VALUE_T \
  55. mem_get_##end##sz##_aligned(const void *vmem) {\
  56. const uint##sz##_t *mem = (const uint##sz##_t *)vmem;\
  57. unsigned MEM_VALUE_T val, raw = *mem;\
  58. swap_endian_##sz(val,raw);\
  59. return val;\
  60. }
  61. #define mem_get_sse_aligned_generic(end,sz) \
  62. static VPX_INLINE signed MEM_VALUE_T \
  63. mem_get_s##end##sz##_aligned(const void *vmem) {\
  64. const int##sz##_t *mem = (const int##sz##_t *)vmem;\
  65. unsigned MEM_VALUE_T val, raw = *mem;\
  66. swap_endian_##sz##_se(val,raw);\
  67. return val;\
  68. }
  69. #define mem_put_ne_aligned_generic(end,sz) \
  70. static VPX_INLINE void \
  71. mem_put_##end##sz##_aligned(void *vmem, MEM_VALUE_T val) {\
  72. uint##sz##_t *mem = (uint##sz##_t *)vmem;\
  73. *mem = (uint##sz##_t)val;\
  74. }
  75. #define mem_put_se_aligned_generic(end,sz) \
  76. static VPX_INLINE void \
  77. mem_put_##end##sz##_aligned(void *vmem, MEM_VALUE_T val) {\
  78. uint##sz##_t *mem = (uint##sz##_t *)vmem, raw;\
  79. swap_endian_##sz(raw,val);\
  80. *mem = (uint##sz##_t)raw;\
  81. }
  82. #include "vpx_config.h"
  83. #if CONFIG_BIG_ENDIAN
  84. #define mem_get_be_aligned_generic(sz) mem_get_ne_aligned_generic(be,sz)
  85. #define mem_get_sbe_aligned_generic(sz) mem_get_sne_aligned_generic(be,sz)
  86. #define mem_get_le_aligned_generic(sz) mem_get_se_aligned_generic(le,sz)
  87. #define mem_get_sle_aligned_generic(sz) mem_get_sse_aligned_generic(le,sz)
  88. #define mem_put_be_aligned_generic(sz) mem_put_ne_aligned_generic(be,sz)
  89. #define mem_put_le_aligned_generic(sz) mem_put_se_aligned_generic(le,sz)
  90. #else
  91. #define mem_get_be_aligned_generic(sz) mem_get_se_aligned_generic(be,sz)
  92. #define mem_get_sbe_aligned_generic(sz) mem_get_sse_aligned_generic(be,sz)
  93. #define mem_get_le_aligned_generic(sz) mem_get_ne_aligned_generic(le,sz)
  94. #define mem_get_sle_aligned_generic(sz) mem_get_sne_aligned_generic(le,sz)
  95. #define mem_put_be_aligned_generic(sz) mem_put_se_aligned_generic(be,sz)
  96. #define mem_put_le_aligned_generic(sz) mem_put_ne_aligned_generic(le,sz)
  97. #endif
  98. #undef mem_get_be16_aligned
  99. #define mem_get_be16_aligned mem_ops_wrap_symbol(mem_get_be16_aligned)
  100. mem_get_be_aligned_generic(16)
  101. #undef mem_get_be32_aligned
  102. #define mem_get_be32_aligned mem_ops_wrap_symbol(mem_get_be32_aligned)
  103. mem_get_be_aligned_generic(32)
  104. #undef mem_get_le16_aligned
  105. #define mem_get_le16_aligned mem_ops_wrap_symbol(mem_get_le16_aligned)
  106. mem_get_le_aligned_generic(16)
  107. #undef mem_get_le32_aligned
  108. #define mem_get_le32_aligned mem_ops_wrap_symbol(mem_get_le32_aligned)
  109. mem_get_le_aligned_generic(32)
  110. #undef mem_get_sbe16_aligned
  111. #define mem_get_sbe16_aligned mem_ops_wrap_symbol(mem_get_sbe16_aligned)
  112. mem_get_sbe_aligned_generic(16)
  113. #undef mem_get_sbe32_aligned
  114. #define mem_get_sbe32_aligned mem_ops_wrap_symbol(mem_get_sbe32_aligned)
  115. mem_get_sbe_aligned_generic(32)
  116. #undef mem_get_sle16_aligned
  117. #define mem_get_sle16_aligned mem_ops_wrap_symbol(mem_get_sle16_aligned)
  118. mem_get_sle_aligned_generic(16)
  119. #undef mem_get_sle32_aligned
  120. #define mem_get_sle32_aligned mem_ops_wrap_symbol(mem_get_sle32_aligned)
  121. mem_get_sle_aligned_generic(32)
  122. #undef mem_put_be16_aligned
  123. #define mem_put_be16_aligned mem_ops_wrap_symbol(mem_put_be16_aligned)
  124. mem_put_be_aligned_generic(16)
  125. #undef mem_put_be32_aligned
  126. #define mem_put_be32_aligned mem_ops_wrap_symbol(mem_put_be32_aligned)
  127. mem_put_be_aligned_generic(32)
  128. #undef mem_put_le16_aligned
  129. #define mem_put_le16_aligned mem_ops_wrap_symbol(mem_put_le16_aligned)
  130. mem_put_le_aligned_generic(16)
  131. #undef mem_put_le32_aligned
  132. #define mem_put_le32_aligned mem_ops_wrap_symbol(mem_put_le32_aligned)
  133. mem_put_le_aligned_generic(32)
  134. #undef mem_get_ne_aligned_generic
  135. #undef mem_get_se_aligned_generic
  136. #undef mem_get_sne_aligned_generic
  137. #undef mem_get_sse_aligned_generic
  138. #undef mem_put_ne_aligned_generic
  139. #undef mem_put_se_aligned_generic
  140. #undef swap_endian_16
  141. #undef swap_endian_32
  142. #undef swap_endian_16_se
  143. #undef swap_endian_32_se
  144. #endif // VPX_PORTS_MEM_OPS_ALIGNED_H_