mem_ops_aligned.h 5.73 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5 6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9 10
 */

11 12
#ifndef VPX_PORTS_MEM_OPS_ALIGNED_H_
#define VPX_PORTS_MEM_OPS_ALIGNED_H_
John Koleszar's avatar
John Koleszar committed
13

14 15
#include "vpx/vpx_integer.h"

16 17
/* \file
 * \brief Provides portable memory access primitives for operating on aligned
John Koleszar's avatar
John Koleszar committed
18 19
 *        data
 *
20 21
 * This file is split from mem_ops.h for easier maintenance. See mem_ops.h
 * for a more detailed description of these primitives.
John Koleszar's avatar
John Koleszar committed
22 23 24 25 26 27 28 29 30
 */
#ifndef INCLUDED_BY_MEM_OPS_H
#error Include mem_ops.h, not mem_ops_aligned.h directly.
#endif

/* Architectures that provide instructions for doing this byte swapping
 * could redefine these macros.
 */
#define swap_endian_16(val,raw) do {\
John Koleszar's avatar
John Koleszar committed
31 32 33
    val = ((raw>>8) & 0x00ff) \
          | ((raw<<8) & 0xff00);\
  } while(0)
John Koleszar's avatar
John Koleszar committed
34
#define swap_endian_32(val,raw) do {\
John Koleszar's avatar
John Koleszar committed
35 36 37 38 39
    val = ((raw>>24) & 0x000000ff) \
          | ((raw>>8)  & 0x0000ff00) \
          | ((raw<<8)  & 0x00ff0000) \
          | ((raw<<24) & 0xff000000); \
  } while(0)
John Koleszar's avatar
John Koleszar committed
40
#define swap_endian_16_se(val,raw) do {\
John Koleszar's avatar
John Koleszar committed
41 42 43
    swap_endian_16(val,raw);\
    val = ((val << 16) >> 16);\
  } while(0)
John Koleszar's avatar
John Koleszar committed
44 45 46
#define swap_endian_32_se(val,raw) swap_endian_32(val,raw)

#define mem_get_ne_aligned_generic(end,sz) \
47 48
  static VPX_INLINE unsigned MEM_VALUE_T \
    mem_get_##end##sz##_aligned(const void *vmem) {\
John Koleszar's avatar
John Koleszar committed
49 50 51
    const uint##sz##_t *mem = (const uint##sz##_t *)vmem;\
    return *mem;\
  }
John Koleszar's avatar
John Koleszar committed
52 53

#define mem_get_sne_aligned_generic(end,sz) \
54 55
  static VPX_INLINE signed MEM_VALUE_T \
    mem_get_s##end##sz##_aligned(const void *vmem) {\
John Koleszar's avatar
John Koleszar committed
56 57 58
    const int##sz##_t *mem = (const int##sz##_t *)vmem;\
    return *mem;\
  }
John Koleszar's avatar
John Koleszar committed
59 60

#define mem_get_se_aligned_generic(end,sz) \
61 62
  static VPX_INLINE unsigned MEM_VALUE_T \
    mem_get_##end##sz##_aligned(const void *vmem) {\
John Koleszar's avatar
John Koleszar committed
63 64 65 66 67
    const uint##sz##_t *mem = (const uint##sz##_t *)vmem;\
    unsigned MEM_VALUE_T val, raw = *mem;\
    swap_endian_##sz(val,raw);\
    return val;\
  }
John Koleszar's avatar
John Koleszar committed
68 69

#define mem_get_sse_aligned_generic(end,sz) \
70 71
  static VPX_INLINE signed MEM_VALUE_T \
    mem_get_s##end##sz##_aligned(const void *vmem) {\
John Koleszar's avatar
John Koleszar committed
72 73 74 75 76
    const int##sz##_t *mem = (const int##sz##_t *)vmem;\
    unsigned MEM_VALUE_T val, raw = *mem;\
    swap_endian_##sz##_se(val,raw);\
    return val;\
  }
John Koleszar's avatar
John Koleszar committed
77 78

#define mem_put_ne_aligned_generic(end,sz) \
79 80
  static VPX_INLINE void \
    mem_put_##end##sz##_aligned(void *vmem, MEM_VALUE_T val) {\
John Koleszar's avatar
John Koleszar committed
81 82 83
    uint##sz##_t *mem = (uint##sz##_t *)vmem;\
    *mem = (uint##sz##_t)val;\
  }
John Koleszar's avatar
John Koleszar committed
84 85

#define mem_put_se_aligned_generic(end,sz) \
86 87
  static VPX_INLINE void \
    mem_put_##end##sz##_aligned(void *vmem, MEM_VALUE_T val) {\
John Koleszar's avatar
John Koleszar committed
88 89 90 91
    uint##sz##_t *mem = (uint##sz##_t *)vmem, raw;\
    swap_endian_##sz(raw,val);\
    *mem = (uint##sz##_t)raw;\
  }
John Koleszar's avatar
John Koleszar committed
92

93
#include "vpx_config.h"
John Koleszar's avatar
John Koleszar committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
#if CONFIG_BIG_ENDIAN
#define mem_get_be_aligned_generic(sz)  mem_get_ne_aligned_generic(be,sz)
#define mem_get_sbe_aligned_generic(sz) mem_get_sne_aligned_generic(be,sz)
#define mem_get_le_aligned_generic(sz)  mem_get_se_aligned_generic(le,sz)
#define mem_get_sle_aligned_generic(sz) mem_get_sse_aligned_generic(le,sz)
#define mem_put_be_aligned_generic(sz)  mem_put_ne_aligned_generic(be,sz)
#define mem_put_le_aligned_generic(sz)  mem_put_se_aligned_generic(le,sz)
#else
#define mem_get_be_aligned_generic(sz)  mem_get_se_aligned_generic(be,sz)
#define mem_get_sbe_aligned_generic(sz) mem_get_sse_aligned_generic(be,sz)
#define mem_get_le_aligned_generic(sz)  mem_get_ne_aligned_generic(le,sz)
#define mem_get_sle_aligned_generic(sz) mem_get_sne_aligned_generic(le,sz)
#define mem_put_be_aligned_generic(sz)  mem_put_se_aligned_generic(be,sz)
#define mem_put_le_aligned_generic(sz)  mem_put_ne_aligned_generic(le,sz)
#endif

#undef  mem_get_be16_aligned
#define mem_get_be16_aligned mem_ops_wrap_symbol(mem_get_be16_aligned)
112
mem_get_be_aligned_generic(16)
John Koleszar's avatar
John Koleszar committed
113 114 115

#undef  mem_get_be32_aligned
#define mem_get_be32_aligned mem_ops_wrap_symbol(mem_get_be32_aligned)
116
mem_get_be_aligned_generic(32)
John Koleszar's avatar
John Koleszar committed
117 118 119

#undef  mem_get_le16_aligned
#define mem_get_le16_aligned mem_ops_wrap_symbol(mem_get_le16_aligned)
120
mem_get_le_aligned_generic(16)
John Koleszar's avatar
John Koleszar committed
121 122 123

#undef  mem_get_le32_aligned
#define mem_get_le32_aligned mem_ops_wrap_symbol(mem_get_le32_aligned)
124
mem_get_le_aligned_generic(32)
John Koleszar's avatar
John Koleszar committed
125 126 127

#undef  mem_get_sbe16_aligned
#define mem_get_sbe16_aligned mem_ops_wrap_symbol(mem_get_sbe16_aligned)
128
mem_get_sbe_aligned_generic(16)
John Koleszar's avatar
John Koleszar committed
129 130 131

#undef  mem_get_sbe32_aligned
#define mem_get_sbe32_aligned mem_ops_wrap_symbol(mem_get_sbe32_aligned)
132
mem_get_sbe_aligned_generic(32)
John Koleszar's avatar
John Koleszar committed
133 134 135

#undef  mem_get_sle16_aligned
#define mem_get_sle16_aligned mem_ops_wrap_symbol(mem_get_sle16_aligned)
136
mem_get_sle_aligned_generic(16)
John Koleszar's avatar
John Koleszar committed
137 138 139

#undef  mem_get_sle32_aligned
#define mem_get_sle32_aligned mem_ops_wrap_symbol(mem_get_sle32_aligned)
140
mem_get_sle_aligned_generic(32)
John Koleszar's avatar
John Koleszar committed
141 142 143

#undef  mem_put_be16_aligned
#define mem_put_be16_aligned mem_ops_wrap_symbol(mem_put_be16_aligned)
144
mem_put_be_aligned_generic(16)
John Koleszar's avatar
John Koleszar committed
145 146 147

#undef  mem_put_be32_aligned
#define mem_put_be32_aligned mem_ops_wrap_symbol(mem_put_be32_aligned)
148
mem_put_be_aligned_generic(32)
John Koleszar's avatar
John Koleszar committed
149 150 151

#undef  mem_put_le16_aligned
#define mem_put_le16_aligned mem_ops_wrap_symbol(mem_put_le16_aligned)
152
mem_put_le_aligned_generic(16)
John Koleszar's avatar
John Koleszar committed
153 154 155

#undef  mem_put_le32_aligned
#define mem_put_le32_aligned mem_ops_wrap_symbol(mem_put_le32_aligned)
156
mem_put_le_aligned_generic(32)
John Koleszar's avatar
John Koleszar committed
157 158 159 160 161 162 163 164 165 166 167

#undef mem_get_ne_aligned_generic
#undef mem_get_se_aligned_generic
#undef mem_get_sne_aligned_generic
#undef mem_get_sse_aligned_generic
#undef mem_put_ne_aligned_generic
#undef mem_put_se_aligned_generic
#undef swap_endian_16
#undef swap_endian_32
#undef swap_endian_16_se
#undef swap_endian_32_se
168 169

#endif  // VPX_PORTS_MEM_OPS_ALIGNED_H_