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 11 #ifndef VPX_PORTS_MEM_OPS_ALIGNED_H_ 12 #define VPX_PORTS_MEM_OPS_ALIGNED_H_ 13 14 #include "vpx/vpx_integer.h" 15 16 /* \file 17 * \brief Provides portable memory access primitives for operating on aligned 18 * data 19 * 20 * This file is split from mem_ops.h for easier maintenance. See mem_ops.h 21 * for a more detailed description of these primitives. 22 */ 23 #ifndef INCLUDED_BY_MEM_OPS_H 24 #error Include mem_ops.h, not mem_ops_aligned.h directly. 25 #endif 26 27 /* Architectures that provide instructions for doing this byte swapping 28 * could redefine these macros. 29 */ 30 #define swap_endian_16(val,raw) do {\ 31 val = ((raw>>8) & 0x00ff) \ 32 | ((raw<<8) & 0xff00);\ 33 } while(0) 34 #define swap_endian_32(val,raw) do {\ 35 val = ((raw>>24) & 0x000000ff) \ 36 | ((raw>>8) & 0x0000ff00) \ 37 | ((raw<<8) & 0x00ff0000) \ 38 | ((raw<<24) & 0xff000000); \ 39 } while(0) 40 #define swap_endian_16_se(val,raw) do {\ 41 swap_endian_16(val,raw);\ 42 val = ((val << 16) >> 16);\ 43 } while(0) 44 #define swap_endian_32_se(val,raw) swap_endian_32(val,raw) 45 46 #define mem_get_ne_aligned_generic(end,sz) \ 47 static VPX_INLINE unsigned MEM_VALUE_T \ 48 mem_get_##end##sz##_aligned(const void *vmem) {\ 49 const uint##sz##_t *mem = (const uint##sz##_t *)vmem;\ 50 return *mem;\ 51 } 52 53 #define mem_get_sne_aligned_generic(end,sz) \ 54 static VPX_INLINE signed MEM_VALUE_T \ 55 mem_get_s##end##sz##_aligned(const void *vmem) {\ 56 const int##sz##_t *mem = (const int##sz##_t *)vmem;\ 57 return *mem;\ 58 } 59 60 #define mem_get_se_aligned_generic(end,sz) \ 61 static VPX_INLINE unsigned MEM_VALUE_T \ 62 mem_get_##end##sz##_aligned(const void *vmem) {\ 63 const uint##sz##_t *mem = (const uint##sz##_t *)vmem;\ 64 unsigned MEM_VALUE_T val, raw = *mem;\ 65 swap_endian_##sz(val,raw);\ 66 return val;\ 67 } 68 69 #define mem_get_sse_aligned_generic(end,sz) \ 70 static VPX_INLINE signed MEM_VALUE_T \ 71 mem_get_s##end##sz##_aligned(const void *vmem) {\ 72 const int##sz##_t *mem = (const int##sz##_t *)vmem;\ 73 unsigned MEM_VALUE_T val, raw = *mem;\ 74 swap_endian_##sz##_se(val,raw);\ 75 return val;\ 76 } 77 78 #define mem_put_ne_aligned_generic(end,sz) \ 79 static VPX_INLINE void \ 80 mem_put_##end##sz##_aligned(void *vmem, MEM_VALUE_T val) {\ 81 uint##sz##_t *mem = (uint##sz##_t *)vmem;\ 82 *mem = (uint##sz##_t)val;\ 83 } 84 85 #define mem_put_se_aligned_generic(end,sz) \ 86 static VPX_INLINE void \ 87 mem_put_##end##sz##_aligned(void *vmem, MEM_VALUE_T val) {\ 88 uint##sz##_t *mem = (uint##sz##_t *)vmem, raw;\ 89 swap_endian_##sz(raw,val);\ 90 *mem = (uint##sz##_t)raw;\ 91 } 92 93 #include "vpx_config.h" 94 #if CONFIG_BIG_ENDIAN 95 #define mem_get_be_aligned_generic(sz) mem_get_ne_aligned_generic(be,sz) 96 #define mem_get_sbe_aligned_generic(sz) mem_get_sne_aligned_generic(be,sz) 97 #define mem_get_le_aligned_generic(sz) mem_get_se_aligned_generic(le,sz) 98 #define mem_get_sle_aligned_generic(sz) mem_get_sse_aligned_generic(le,sz) 99 #define mem_put_be_aligned_generic(sz) mem_put_ne_aligned_generic(be,sz) 100 #define mem_put_le_aligned_generic(sz) mem_put_se_aligned_generic(le,sz) 101 #else 102 #define mem_get_be_aligned_generic(sz) mem_get_se_aligned_generic(be,sz) 103 #define mem_get_sbe_aligned_generic(sz) mem_get_sse_aligned_generic(be,sz) 104 #define mem_get_le_aligned_generic(sz) mem_get_ne_aligned_generic(le,sz) 105 #define mem_get_sle_aligned_generic(sz) mem_get_sne_aligned_generic(le,sz) 106 #define mem_put_be_aligned_generic(sz) mem_put_se_aligned_generic(be,sz) 107 #define mem_put_le_aligned_generic(sz) mem_put_ne_aligned_generic(le,sz) 108 #endif 109 110 #undef mem_get_be16_aligned 111 #define mem_get_be16_aligned mem_ops_wrap_symbol(mem_get_be16_aligned) 112 mem_get_be_aligned_generic(16) 113 114 #undef mem_get_be32_aligned 115 #define mem_get_be32_aligned mem_ops_wrap_symbol(mem_get_be32_aligned) 116 mem_get_be_aligned_generic(32) 117 118 #undef mem_get_le16_aligned 119 #define mem_get_le16_aligned mem_ops_wrap_symbol(mem_get_le16_aligned) 120 mem_get_le_aligned_generic(16) 121 122 #undef mem_get_le32_aligned 123 #define mem_get_le32_aligned mem_ops_wrap_symbol(mem_get_le32_aligned) 124 mem_get_le_aligned_generic(32) 125 126 #undef mem_get_sbe16_aligned 127 #define mem_get_sbe16_aligned mem_ops_wrap_symbol(mem_get_sbe16_aligned) 128 mem_get_sbe_aligned_generic(16) 129 130 #undef mem_get_sbe32_aligned 131 #define mem_get_sbe32_aligned mem_ops_wrap_symbol(mem_get_sbe32_aligned) 132 mem_get_sbe_aligned_generic(32) 133 134 #undef mem_get_sle16_aligned 135 #define mem_get_sle16_aligned mem_ops_wrap_symbol(mem_get_sle16_aligned) 136 mem_get_sle_aligned_generic(16) 137 138 #undef mem_get_sle32_aligned 139 #define mem_get_sle32_aligned mem_ops_wrap_symbol(mem_get_sle32_aligned) 140 mem_get_sle_aligned_generic(32) 141 142 #undef mem_put_be16_aligned 143 #define mem_put_be16_aligned mem_ops_wrap_symbol(mem_put_be16_aligned) 144 mem_put_be_aligned_generic(16) 145 146 #undef mem_put_be32_aligned 147 #define mem_put_be32_aligned mem_ops_wrap_symbol(mem_put_be32_aligned) 148 mem_put_be_aligned_generic(32) 149 150 #undef mem_put_le16_aligned 151 #define mem_put_le16_aligned mem_ops_wrap_symbol(mem_put_le16_aligned) 152 mem_put_le_aligned_generic(16) 153 154 #undef mem_put_le32_aligned 155 #define mem_put_le32_aligned mem_ops_wrap_symbol(mem_put_le32_aligned) 156 mem_put_le_aligned_generic(32) 157 158 #undef mem_get_ne_aligned_generic 159 #undef mem_get_se_aligned_generic 160 #undef mem_get_sne_aligned_generic 161 #undef mem_get_sse_aligned_generic 162 #undef mem_put_ne_aligned_generic 163 #undef mem_put_se_aligned_generic 164 #undef swap_endian_16 165 #undef swap_endian_32 166 #undef swap_endian_16_se 167 #undef swap_endian_32_se 168 169 #endif // VPX_PORTS_MEM_OPS_ALIGNED_H_ 170