/src/libvpx/vpx_ports/mem_ops.h
Line | Count | Source (jump to first uncovered line) |
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_VPX_PORTS_MEM_OPS_H_ |
12 | | #define VPX_VPX_PORTS_MEM_OPS_H_ |
13 | | |
14 | | /* \file |
15 | | * \brief Provides portable memory access primitives |
16 | | * |
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. |
21 | | * |
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. |
25 | | * |
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. |
33 | | * |
34 | | * NOTE: This code is not supported on platforms where char > 1 octet ATM. |
35 | | */ |
36 | | |
37 | | #ifndef MAU_T |
38 | | /* Minimum Access Unit for this target */ |
39 | 2.44k | #define MAU_T unsigned char |
40 | | #endif |
41 | | |
42 | | #ifndef MEM_VALUE_T |
43 | | #define MEM_VALUE_T int |
44 | | #endif |
45 | | |
46 | | #undef MEM_VALUE_T_SZ_BITS |
47 | | #define MEM_VALUE_T_SZ_BITS (sizeof(MEM_VALUE_T) << 3) |
48 | | |
49 | | #undef mem_ops_wrap_symbol |
50 | 2.44k | #define mem_ops_wrap_symbol(fn) mem_ops_wrap_symbol2(fn, MEM_VALUE_T) |
51 | | #undef mem_ops_wrap_symbol2 |
52 | 2.44k | #define mem_ops_wrap_symbol2(fn, typ) mem_ops_wrap_symbol3(fn, typ) |
53 | | #undef mem_ops_wrap_symbol3 |
54 | 2.44k | #define mem_ops_wrap_symbol3(fn, typ) fn##_as_##typ |
55 | | |
56 | | /* |
57 | | * Include aligned access routines |
58 | | */ |
59 | | #define INCLUDED_BY_MEM_OPS_H |
60 | | #include "mem_ops_aligned.h" |
61 | | #undef INCLUDED_BY_MEM_OPS_H |
62 | | |
63 | | #undef mem_get_be16 |
64 | | #define mem_get_be16 mem_ops_wrap_symbol(mem_get_be16) |
65 | 0 | static unsigned MEM_VALUE_T mem_get_be16(const void *vmem) { |
66 | 0 | unsigned MEM_VALUE_T val; |
67 | 0 | const MAU_T *mem = (const MAU_T *)vmem; |
68 | 0 |
|
69 | 0 | val = mem[0] << 8; |
70 | 0 | val |= mem[1]; |
71 | 0 | return val; |
72 | 0 | } |
73 | | |
74 | | #undef mem_get_be24 |
75 | | #define mem_get_be24 mem_ops_wrap_symbol(mem_get_be24) |
76 | 0 | static unsigned MEM_VALUE_T mem_get_be24(const void *vmem) { |
77 | 0 | unsigned MEM_VALUE_T val; |
78 | 0 | const MAU_T *mem = (const MAU_T *)vmem; |
79 | 0 |
|
80 | 0 | val = mem[0] << 16; |
81 | 0 | val |= mem[1] << 8; |
82 | 0 | val |= mem[2]; |
83 | 0 | return val; |
84 | 0 | } |
85 | | |
86 | | #undef mem_get_be32 |
87 | | #define mem_get_be32 mem_ops_wrap_symbol(mem_get_be32) |
88 | 0 | static unsigned MEM_VALUE_T mem_get_be32(const void *vmem) { |
89 | 0 | unsigned MEM_VALUE_T val; |
90 | 0 | const MAU_T *mem = (const MAU_T *)vmem; |
91 | 0 |
|
92 | 0 | val = ((unsigned MEM_VALUE_T)mem[0]) << 24; |
93 | 0 | val |= mem[1] << 16; |
94 | 0 | val |= mem[2] << 8; |
95 | 0 | val |= mem[3]; |
96 | 0 | return val; |
97 | 0 | } |
98 | | |
99 | | #undef mem_get_le16 |
100 | | #define mem_get_le16 mem_ops_wrap_symbol(mem_get_le16) |
101 | 0 | static unsigned MEM_VALUE_T mem_get_le16(const void *vmem) { |
102 | 0 | unsigned MEM_VALUE_T val; |
103 | 0 | const MAU_T *mem = (const MAU_T *)vmem; |
104 | 0 |
|
105 | 0 | val = mem[1] << 8; |
106 | 0 | val |= mem[0]; |
107 | 0 | return val; |
108 | 0 | } |
109 | | |
110 | | #undef mem_get_le24 |
111 | | #define mem_get_le24 mem_ops_wrap_symbol(mem_get_le24) |
112 | 0 | static unsigned MEM_VALUE_T mem_get_le24(const void *vmem) { |
113 | 0 | unsigned MEM_VALUE_T val; |
114 | 0 | const MAU_T *mem = (const MAU_T *)vmem; |
115 | 0 |
|
116 | 0 | val = mem[2] << 16; |
117 | 0 | val |= mem[1] << 8; |
118 | 0 | val |= mem[0]; |
119 | 0 | return val; |
120 | 0 | } |
121 | | |
122 | | #undef mem_get_le32 |
123 | | #define mem_get_le32 mem_ops_wrap_symbol(mem_get_le32) |
124 | 0 | static unsigned MEM_VALUE_T mem_get_le32(const void *vmem) { |
125 | 0 | unsigned MEM_VALUE_T val; |
126 | 0 | const MAU_T *mem = (const MAU_T *)vmem; |
127 | 0 |
|
128 | 0 | val = ((unsigned MEM_VALUE_T)mem[3]) << 24; |
129 | 0 | val |= mem[2] << 16; |
130 | 0 | val |= mem[1] << 8; |
131 | 0 | val |= mem[0]; |
132 | 0 | return val; |
133 | 0 | } |
134 | | |
135 | | #define mem_get_s_generic(end, sz) \ |
136 | 0 | static VPX_INLINE signed MEM_VALUE_T mem_get_s##end##sz(const void *vmem) { \ |
137 | 0 | const MAU_T *mem = (const MAU_T *)vmem; \ |
138 | 0 | signed MEM_VALUE_T val = mem_get_##end##sz(mem); \ |
139 | 0 | return (val << (MEM_VALUE_T_SZ_BITS - sz)) >> (MEM_VALUE_T_SZ_BITS - sz); \ |
140 | 0 | } Unexecuted instantiation: vp9_bitstream.c:mem_get_sbe16_as_int Unexecuted instantiation: vp9_bitstream.c:mem_get_sbe24_as_int Unexecuted instantiation: vp9_bitstream.c:mem_get_sbe32_as_int Unexecuted instantiation: vp9_bitstream.c:mem_get_sle16_as_int Unexecuted instantiation: vp9_bitstream.c:mem_get_sle24_as_int Unexecuted instantiation: vp9_bitstream.c:mem_get_sle32_as_int |
141 | | |
142 | | /* clang-format off */ |
143 | | #undef mem_get_sbe16 |
144 | | #define mem_get_sbe16 mem_ops_wrap_symbol(mem_get_sbe16) |
145 | | mem_get_s_generic(be, 16) |
146 | | |
147 | | #undef mem_get_sbe24 |
148 | | #define mem_get_sbe24 mem_ops_wrap_symbol(mem_get_sbe24) |
149 | | mem_get_s_generic(be, 24) |
150 | | |
151 | | #undef mem_get_sbe32 |
152 | | #define mem_get_sbe32 mem_ops_wrap_symbol(mem_get_sbe32) |
153 | | mem_get_s_generic(be, 32) |
154 | | |
155 | | #undef mem_get_sle16 |
156 | | #define mem_get_sle16 mem_ops_wrap_symbol(mem_get_sle16) |
157 | | mem_get_s_generic(le, 16) |
158 | | |
159 | | #undef mem_get_sle24 |
160 | | #define mem_get_sle24 mem_ops_wrap_symbol(mem_get_sle24) |
161 | | mem_get_s_generic(le, 24) |
162 | | |
163 | | #undef mem_get_sle32 |
164 | | #define mem_get_sle32 mem_ops_wrap_symbol(mem_get_sle32) |
165 | | mem_get_s_generic(le, 32) |
166 | | |
167 | | #undef mem_put_be16 |
168 | | #define mem_put_be16 mem_ops_wrap_symbol(mem_put_be16) |
169 | 0 | static VPX_INLINE void mem_put_be16(void *vmem, MEM_VALUE_T val) { |
170 | 0 | MAU_T *mem = (MAU_T *)vmem; |
171 | 0 |
|
172 | 0 | mem[0] = (MAU_T)((val >> 8) & 0xff); |
173 | 0 | mem[1] = (MAU_T)((val >> 0) & 0xff); |
174 | 0 | } |
175 | | |
176 | | #undef mem_put_be24 |
177 | | #define mem_put_be24 mem_ops_wrap_symbol(mem_put_be24) |
178 | 0 | static VPX_INLINE void mem_put_be24(void *vmem, MEM_VALUE_T val) { |
179 | 0 | MAU_T *mem = (MAU_T *)vmem; |
180 | 0 |
|
181 | 0 | mem[0] = (MAU_T)((val >> 16) & 0xff); |
182 | 0 | mem[1] = (MAU_T)((val >> 8) & 0xff); |
183 | 0 | mem[2] = (MAU_T)((val >> 0) & 0xff); |
184 | 0 | } |
185 | | |
186 | | #undef mem_put_be32 |
187 | 2.44k | #define mem_put_be32 mem_ops_wrap_symbol(mem_put_be32) |
188 | 2.44k | static VPX_INLINE void mem_put_be32(void *vmem, MEM_VALUE_T val) { |
189 | 2.44k | MAU_T *mem = (MAU_T *)vmem; |
190 | | |
191 | 2.44k | mem[0] = (MAU_T)((val >> 24) & 0xff); |
192 | 2.44k | mem[1] = (MAU_T)((val >> 16) & 0xff); |
193 | 2.44k | mem[2] = (MAU_T)((val >> 8) & 0xff); |
194 | 2.44k | mem[3] = (MAU_T)((val >> 0) & 0xff); |
195 | 2.44k | } |
196 | | |
197 | | #undef mem_put_le16 |
198 | | #define mem_put_le16 mem_ops_wrap_symbol(mem_put_le16) |
199 | 0 | static VPX_INLINE void mem_put_le16(void *vmem, MEM_VALUE_T val) { |
200 | 0 | MAU_T *mem = (MAU_T *)vmem; |
201 | 0 |
|
202 | 0 | mem[0] = (MAU_T)((val >> 0) & 0xff); |
203 | 0 | mem[1] = (MAU_T)((val >> 8) & 0xff); |
204 | 0 | } |
205 | | |
206 | | #undef mem_put_le24 |
207 | | #define mem_put_le24 mem_ops_wrap_symbol(mem_put_le24) |
208 | 0 | static VPX_INLINE void mem_put_le24(void *vmem, MEM_VALUE_T val) { |
209 | 0 | MAU_T *mem = (MAU_T *)vmem; |
210 | 0 |
|
211 | 0 | mem[0] = (MAU_T)((val >> 0) & 0xff); |
212 | 0 | mem[1] = (MAU_T)((val >> 8) & 0xff); |
213 | 0 | mem[2] = (MAU_T)((val >> 16) & 0xff); |
214 | 0 | } |
215 | | |
216 | | #undef mem_put_le32 |
217 | | #define mem_put_le32 mem_ops_wrap_symbol(mem_put_le32) |
218 | 0 | static VPX_INLINE void mem_put_le32(void *vmem, MEM_VALUE_T val) { |
219 | 0 | MAU_T *mem = (MAU_T *)vmem; |
220 | 0 |
|
221 | 0 | mem[0] = (MAU_T)((val >> 0) & 0xff); |
222 | 0 | mem[1] = (MAU_T)((val >> 8) & 0xff); |
223 | 0 | mem[2] = (MAU_T)((val >> 16) & 0xff); |
224 | 0 | mem[3] = (MAU_T)((val >> 24) & 0xff); |
225 | 0 | } |
226 | | /* clang-format on */ |
227 | | #endif // VPX_VPX_PORTS_MEM_OPS_H_ |