Merge "vp9: Modify logic for gf setting based on up-coming key frame."
[aom.git] / vpx_ports / mem_ops.h
blob1f8f914f159b8572923ad7bfa86bba074edcacd8
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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 */
11 #ifndef VPX_PORTS_MEM_OPS_H_
12 #define VPX_PORTS_MEM_OPS_H_
14 /* \file
15 * \brief Provides portable memory access primitives
17 * This function provides portable primitives for getting and setting of
18 * signed and unsigned integers in 16, 24, and 32 bit sizes. The operations
19 * can be performed on unaligned data regardless of hardware support for
20 * unaligned accesses.
22 * The type used to pass the integral values may be changed by defining
23 * MEM_VALUE_T with the appropriate type. The type given must be an integral
24 * numeric type.
26 * The actual functions instantiated have the MEM_VALUE_T type name pasted
27 * on to the symbol name. This allows the developer to instantiate these
28 * operations for multiple types within the same translation unit. This is
29 * of somewhat questionable utility, but the capability exists nonetheless.
30 * Users not making use of this functionality should call the functions
31 * without the type name appended, and the preprocessor will take care of
32 * it.
34 * NOTE: This code is not supported on platforms where char > 1 octet ATM.
37 #ifndef MAU_T
38 /* Minimum Access Unit for this target */
39 #define MAU_T unsigned char
40 #endif
42 #ifndef MEM_VALUE_T
43 #define MEM_VALUE_T int
44 #endif
46 #undef MEM_VALUE_T_SZ_BITS
47 #define MEM_VALUE_T_SZ_BITS (sizeof(MEM_VALUE_T) << 3)
49 #undef mem_ops_wrap_symbol
50 #define mem_ops_wrap_symbol(fn) mem_ops_wrap_symbol2(fn, MEM_VALUE_T)
51 #undef mem_ops_wrap_symbol2
52 #define mem_ops_wrap_symbol2(fn,typ) mem_ops_wrap_symbol3(fn,typ)
53 #undef mem_ops_wrap_symbol3
54 #define mem_ops_wrap_symbol3(fn,typ) fn##_as_##typ
57 * Include aligned access routines
59 #define INCLUDED_BY_MEM_OPS_H
60 #include "mem_ops_aligned.h"
61 #undef INCLUDED_BY_MEM_OPS_H
63 #undef mem_get_be16
64 #define mem_get_be16 mem_ops_wrap_symbol(mem_get_be16)
65 static unsigned MEM_VALUE_T mem_get_be16(const void *vmem) {
66 unsigned MEM_VALUE_T val;
67 const MAU_T *mem = (const MAU_T *)vmem;
69 val = mem[0] << 8;
70 val |= mem[1];
71 return val;
74 #undef mem_get_be24
75 #define mem_get_be24 mem_ops_wrap_symbol(mem_get_be24)
76 static unsigned MEM_VALUE_T mem_get_be24(const void *vmem) {
77 unsigned MEM_VALUE_T val;
78 const MAU_T *mem = (const MAU_T *)vmem;
80 val = mem[0] << 16;
81 val |= mem[1] << 8;
82 val |= mem[2];
83 return val;
86 #undef mem_get_be32
87 #define mem_get_be32 mem_ops_wrap_symbol(mem_get_be32)
88 static unsigned MEM_VALUE_T mem_get_be32(const void *vmem) {
89 unsigned MEM_VALUE_T val;
90 const MAU_T *mem = (const MAU_T *)vmem;
92 val = mem[0] << 24;
93 val |= mem[1] << 16;
94 val |= mem[2] << 8;
95 val |= mem[3];
96 return val;
99 #undef mem_get_le16
100 #define mem_get_le16 mem_ops_wrap_symbol(mem_get_le16)
101 static unsigned MEM_VALUE_T mem_get_le16(const void *vmem) {
102 unsigned MEM_VALUE_T val;
103 const MAU_T *mem = (const MAU_T *)vmem;
105 val = mem[1] << 8;
106 val |= mem[0];
107 return val;
110 #undef mem_get_le24
111 #define mem_get_le24 mem_ops_wrap_symbol(mem_get_le24)
112 static unsigned MEM_VALUE_T mem_get_le24(const void *vmem) {
113 unsigned MEM_VALUE_T val;
114 const MAU_T *mem = (const MAU_T *)vmem;
116 val = mem[2] << 16;
117 val |= mem[1] << 8;
118 val |= mem[0];
119 return val;
122 #undef mem_get_le32
123 #define mem_get_le32 mem_ops_wrap_symbol(mem_get_le32)
124 static unsigned MEM_VALUE_T mem_get_le32(const void *vmem) {
125 unsigned MEM_VALUE_T val;
126 const MAU_T *mem = (const MAU_T *)vmem;
128 val = mem[3] << 24;
129 val |= mem[2] << 16;
130 val |= mem[1] << 8;
131 val |= mem[0];
132 return val;
135 #define mem_get_s_generic(end,sz) \
136 static VPX_INLINE signed MEM_VALUE_T mem_get_s##end##sz(const void *vmem) {\
137 const MAU_T *mem = (const MAU_T*)vmem;\
138 signed MEM_VALUE_T val = mem_get_##end##sz(mem);\
139 return (val << (MEM_VALUE_T_SZ_BITS - sz)) >> (MEM_VALUE_T_SZ_BITS - sz);\
142 #undef mem_get_sbe16
143 #define mem_get_sbe16 mem_ops_wrap_symbol(mem_get_sbe16)
144 mem_get_s_generic(be, 16)
146 #undef mem_get_sbe24
147 #define mem_get_sbe24 mem_ops_wrap_symbol(mem_get_sbe24)
148 mem_get_s_generic(be, 24)
150 #undef mem_get_sbe32
151 #define mem_get_sbe32 mem_ops_wrap_symbol(mem_get_sbe32)
152 mem_get_s_generic(be, 32)
154 #undef mem_get_sle16
155 #define mem_get_sle16 mem_ops_wrap_symbol(mem_get_sle16)
156 mem_get_s_generic(le, 16)
158 #undef mem_get_sle24
159 #define mem_get_sle24 mem_ops_wrap_symbol(mem_get_sle24)
160 mem_get_s_generic(le, 24)
162 #undef mem_get_sle32
163 #define mem_get_sle32 mem_ops_wrap_symbol(mem_get_sle32)
164 mem_get_s_generic(le, 32)
166 #undef mem_put_be16
167 #define mem_put_be16 mem_ops_wrap_symbol(mem_put_be16)
168 static VPX_INLINE void mem_put_be16(void *vmem, MEM_VALUE_T val) {
169 MAU_T *mem = (MAU_T *)vmem;
171 mem[0] = (MAU_T)((val >> 8) & 0xff);
172 mem[1] = (MAU_T)((val >> 0) & 0xff);
175 #undef mem_put_be24
176 #define mem_put_be24 mem_ops_wrap_symbol(mem_put_be24)
177 static VPX_INLINE void mem_put_be24(void *vmem, MEM_VALUE_T val) {
178 MAU_T *mem = (MAU_T *)vmem;
180 mem[0] = (MAU_T)((val >> 16) & 0xff);
181 mem[1] = (MAU_T)((val >> 8) & 0xff);
182 mem[2] = (MAU_T)((val >> 0) & 0xff);
185 #undef mem_put_be32
186 #define mem_put_be32 mem_ops_wrap_symbol(mem_put_be32)
187 static VPX_INLINE void mem_put_be32(void *vmem, MEM_VALUE_T val) {
188 MAU_T *mem = (MAU_T *)vmem;
190 mem[0] = (MAU_T)((val >> 24) & 0xff);
191 mem[1] = (MAU_T)((val >> 16) & 0xff);
192 mem[2] = (MAU_T)((val >> 8) & 0xff);
193 mem[3] = (MAU_T)((val >> 0) & 0xff);
196 #undef mem_put_le16
197 #define mem_put_le16 mem_ops_wrap_symbol(mem_put_le16)
198 static VPX_INLINE void mem_put_le16(void *vmem, MEM_VALUE_T val) {
199 MAU_T *mem = (MAU_T *)vmem;
201 mem[0] = (MAU_T)((val >> 0) & 0xff);
202 mem[1] = (MAU_T)((val >> 8) & 0xff);
205 #undef mem_put_le24
206 #define mem_put_le24 mem_ops_wrap_symbol(mem_put_le24)
207 static VPX_INLINE void mem_put_le24(void *vmem, MEM_VALUE_T val) {
208 MAU_T *mem = (MAU_T *)vmem;
210 mem[0] = (MAU_T)((val >> 0) & 0xff);
211 mem[1] = (MAU_T)((val >> 8) & 0xff);
212 mem[2] = (MAU_T)((val >> 16) & 0xff);
215 #undef mem_put_le32
216 #define mem_put_le32 mem_ops_wrap_symbol(mem_put_le32)
217 static VPX_INLINE void mem_put_le32(void *vmem, MEM_VALUE_T val) {
218 MAU_T *mem = (MAU_T *)vmem;
220 mem[0] = (MAU_T)((val >> 0) & 0xff);
221 mem[1] = (MAU_T)((val >> 8) & 0xff);
222 mem[2] = (MAU_T)((val >> 16) & 0xff);
223 mem[3] = (MAU_T)((val >> 24) & 0xff);
226 #endif // VPX_PORTS_MEM_OPS_H_