CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/ext/at3_standalone/intreadwrite.h
Views: 1401
1
/*
2
* This file is part of FFmpeg.
3
*
4
* FFmpeg is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
8
*
9
* FFmpeg is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
13
*
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with FFmpeg; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
#pragma once
20
#include <stdint.h>
21
22
#include "compat.h"
23
24
typedef union {
25
uint64_t u64;
26
uint32_t u32[2];
27
uint16_t u16[4];
28
uint8_t u8 [8];
29
double f64;
30
float f32[2];
31
} av_alias av_alias64;
32
33
typedef union {
34
uint32_t u32;
35
uint16_t u16[2];
36
uint8_t u8 [4];
37
float f32;
38
} av_alias av_alias32;
39
40
typedef union {
41
uint16_t u16;
42
uint8_t u8 [2];
43
} av_alias av_alias16;
44
45
#include "compat.h"
46
47
# if defined(AV_RN16) && !defined(AV_RL16)
48
# define AV_RL16(p) AV_RN16(p)
49
# elif !defined(AV_RN16) && defined(AV_RL16)
50
# define AV_RN16(p) AV_RL16(p)
51
# endif
52
53
# if defined(AV_WN16) && !defined(AV_WL16)
54
# define AV_WL16(p, v) AV_WN16(p, v)
55
# elif !defined(AV_WN16) && defined(AV_WL16)
56
# define AV_WN16(p, v) AV_WL16(p, v)
57
# endif
58
59
# if defined(AV_RN24) && !defined(AV_RL24)
60
# define AV_RL24(p) AV_RN24(p)
61
# elif !defined(AV_RN24) && defined(AV_RL24)
62
# define AV_RN24(p) AV_RL24(p)
63
# endif
64
65
# if defined(AV_WN24) && !defined(AV_WL24)
66
# define AV_WL24(p, v) AV_WN24(p, v)
67
# elif !defined(AV_WN24) && defined(AV_WL24)
68
# define AV_WN24(p, v) AV_WL24(p, v)
69
# endif
70
71
# if defined(AV_RN32) && !defined(AV_RL32)
72
# define AV_RL32(p) AV_RN32(p)
73
# elif !defined(AV_RN32) && defined(AV_RL32)
74
# define AV_RN32(p) AV_RL32(p)
75
# endif
76
77
# if defined(AV_WN32) && !defined(AV_WL32)
78
# define AV_WL32(p, v) AV_WN32(p, v)
79
# elif !defined(AV_WN32) && defined(AV_WL32)
80
# define AV_WN32(p, v) AV_WL32(p, v)
81
# endif
82
83
# if defined(AV_RN48) && !defined(AV_RL48)
84
# define AV_RL48(p) AV_RN48(p)
85
# elif !defined(AV_RN48) && defined(AV_RL48)
86
# define AV_RN48(p) AV_RL48(p)
87
# endif
88
89
# if defined(AV_WN48) && !defined(AV_WL48)
90
# define AV_WL48(p, v) AV_WN48(p, v)
91
# elif !defined(AV_WN48) && defined(AV_WL48)
92
# define AV_WN48(p, v) AV_WL48(p, v)
93
# endif
94
95
# if defined(AV_RN64) && !defined(AV_RL64)
96
# define AV_RL64(p) AV_RN64(p)
97
# elif !defined(AV_RN64) && defined(AV_RL64)
98
# define AV_RN64(p) AV_RL64(p)
99
# endif
100
101
# if defined(AV_WN64) && !defined(AV_WL64)
102
# define AV_WL64(p, v) AV_WN64(p, v)
103
# elif !defined(AV_WN64) && defined(AV_WL64)
104
# define AV_WN64(p, v) AV_WL64(p, v)
105
# endif
106
107
/*
108
* Define AV_[RW]N helper macros to simplify definitions not provided
109
* by per-arch headers.
110
*/
111
#if AV_HAVE_FAST_UNALIGNED
112
113
# define AV_RN(s, p) (((const av_alias##s*)(p))->u##s)
114
# define AV_WN(s, p, v) (((av_alias##s*)(p))->u##s = (v))
115
116
#else
117
118
#ifndef AV_RB16
119
# define AV_RB16(x) \
120
((((const uint8_t*)(x))[0] << 8) | \
121
((const uint8_t*)(x))[1])
122
#endif
123
#ifndef AV_WB16
124
# define AV_WB16(p, darg) do { \
125
unsigned d = (darg); \
126
((uint8_t*)(p))[1] = (d); \
127
((uint8_t*)(p))[0] = (d)>>8; \
128
} while(0)
129
#endif
130
131
#ifndef AV_RL16
132
# define AV_RL16(x) \
133
((((const uint8_t*)(x))[1] << 8) | \
134
((const uint8_t*)(x))[0])
135
#endif
136
#ifndef AV_WL16
137
# define AV_WL16(p, darg) do { \
138
unsigned d = (darg); \
139
((uint8_t*)(p))[0] = (d); \
140
((uint8_t*)(p))[1] = (d)>>8; \
141
} while(0)
142
#endif
143
144
#ifndef AV_RB32
145
# define AV_RB32(x) \
146
(((uint32_t)((const uint8_t*)(x))[0] << 24) | \
147
(((const uint8_t*)(x))[1] << 16) | \
148
(((const uint8_t*)(x))[2] << 8) | \
149
((const uint8_t*)(x))[3])
150
#endif
151
#ifndef AV_WB32
152
# define AV_WB32(p, darg) do { \
153
unsigned d = (darg); \
154
((uint8_t*)(p))[3] = (d); \
155
((uint8_t*)(p))[2] = (d)>>8; \
156
((uint8_t*)(p))[1] = (d)>>16; \
157
((uint8_t*)(p))[0] = (d)>>24; \
158
} while(0)
159
#endif
160
161
#ifndef AV_RL32
162
# define AV_RL32(x) \
163
(((uint32_t)((const uint8_t*)(x))[3] << 24) | \
164
(((const uint8_t*)(x))[2] << 16) | \
165
(((const uint8_t*)(x))[1] << 8) | \
166
((const uint8_t*)(x))[0])
167
#endif
168
#ifndef AV_WL32
169
# define AV_WL32(p, darg) do { \
170
unsigned d = (darg); \
171
((uint8_t*)(p))[0] = (d); \
172
((uint8_t*)(p))[1] = (d)>>8; \
173
((uint8_t*)(p))[2] = (d)>>16; \
174
((uint8_t*)(p))[3] = (d)>>24; \
175
} while(0)
176
#endif
177
178
#ifndef AV_RB64
179
# define AV_RB64(x) \
180
(((uint64_t)((const uint8_t*)(x))[0] << 56) | \
181
((uint64_t)((const uint8_t*)(x))[1] << 48) | \
182
((uint64_t)((const uint8_t*)(x))[2] << 40) | \
183
((uint64_t)((const uint8_t*)(x))[3] << 32) | \
184
((uint64_t)((const uint8_t*)(x))[4] << 24) | \
185
((uint64_t)((const uint8_t*)(x))[5] << 16) | \
186
((uint64_t)((const uint8_t*)(x))[6] << 8) | \
187
(uint64_t)((const uint8_t*)(x))[7])
188
#endif
189
#ifndef AV_WB64
190
# define AV_WB64(p, darg) do { \
191
uint64_t d = (darg); \
192
((uint8_t*)(p))[7] = (d); \
193
((uint8_t*)(p))[6] = (d)>>8; \
194
((uint8_t*)(p))[5] = (d)>>16; \
195
((uint8_t*)(p))[4] = (d)>>24; \
196
((uint8_t*)(p))[3] = (d)>>32; \
197
((uint8_t*)(p))[2] = (d)>>40; \
198
((uint8_t*)(p))[1] = (d)>>48; \
199
((uint8_t*)(p))[0] = (d)>>56; \
200
} while(0)
201
#endif
202
203
#ifndef AV_RL64
204
# define AV_RL64(x) \
205
(((uint64_t)((const uint8_t*)(x))[7] << 56) | \
206
((uint64_t)((const uint8_t*)(x))[6] << 48) | \
207
((uint64_t)((const uint8_t*)(x))[5] << 40) | \
208
((uint64_t)((const uint8_t*)(x))[4] << 32) | \
209
((uint64_t)((const uint8_t*)(x))[3] << 24) | \
210
((uint64_t)((const uint8_t*)(x))[2] << 16) | \
211
((uint64_t)((const uint8_t*)(x))[1] << 8) | \
212
(uint64_t)((const uint8_t*)(x))[0])
213
#endif
214
#ifndef AV_WL64
215
# define AV_WL64(p, darg) do { \
216
uint64_t d = (darg); \
217
((uint8_t*)(p))[0] = (d); \
218
((uint8_t*)(p))[1] = (d)>>8; \
219
((uint8_t*)(p))[2] = (d)>>16; \
220
((uint8_t*)(p))[3] = (d)>>24; \
221
((uint8_t*)(p))[4] = (d)>>32; \
222
((uint8_t*)(p))[5] = (d)>>40; \
223
((uint8_t*)(p))[6] = (d)>>48; \
224
((uint8_t*)(p))[7] = (d)>>56; \
225
} while(0)
226
#endif
227
228
# define AV_RN(s, p) AV_RL##s(p)
229
# define AV_WN(s, p, v) AV_WL##s(p, v)
230
231
#endif /* HAVE_FAST_UNALIGNED */
232
233
#ifndef AV_RN16
234
# define AV_RN16(p) AV_RN(16, p)
235
#endif
236
237
#ifndef AV_RN32
238
# define AV_RN32(p) AV_RN(32, p)
239
#endif
240
241
#ifndef AV_RN64
242
# define AV_RN64(p) AV_RN(64, p)
243
#endif
244
245
#ifndef AV_WN16
246
# define AV_WN16(p, v) AV_WN(16, p, v)
247
#endif
248
249
#ifndef AV_WN32
250
# define AV_WN32(p, v) AV_WN(32, p, v)
251
#endif
252
253
#ifndef AV_WN64
254
# define AV_WN64(p, v) AV_WN(64, p, v)
255
#endif
256
257
# define AV_RB(s, p) av_bswap##s(AV_RN##s(p))
258
# define AV_WB(s, p, v) AV_WN##s(p, av_bswap##s(v))
259
# define AV_RL(s, p) AV_RN##s(p)
260
# define AV_WL(s, p, v) AV_WN##s(p, v)
261
262
#define AV_RB8(x) (((const uint8_t*)(x))[0])
263
#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0)
264
265
#define AV_RL8(x) AV_RB8(x)
266
#define AV_WL8(p, d) AV_WB8(p, d)
267
268
#ifndef AV_RB16
269
# define AV_RB16(p) AV_RB(16, p)
270
#endif
271
#ifndef AV_WB16
272
# define AV_WB16(p, v) AV_WB(16, p, v)
273
#endif
274
275
#ifndef AV_RL16
276
# define AV_RL16(p) AV_RL(16, p)
277
#endif
278
#ifndef AV_WL16
279
# define AV_WL16(p, v) AV_WL(16, p, v)
280
#endif
281
282
#ifndef AV_RB32
283
# define AV_RB32(p) AV_RB(32, p)
284
#endif
285
#ifndef AV_WB32
286
# define AV_WB32(p, v) AV_WB(32, p, v)
287
#endif
288
289
#ifndef AV_RL32
290
# define AV_RL32(p) AV_RL(32, p)
291
#endif
292
#ifndef AV_WL32
293
# define AV_WL32(p, v) AV_WL(32, p, v)
294
#endif
295
296
#ifndef AV_RB64
297
# define AV_RB64(p) AV_RB(64, p)
298
#endif
299
#ifndef AV_WB64
300
# define AV_WB64(p, v) AV_WB(64, p, v)
301
#endif
302
303
#ifndef AV_RL64
304
# define AV_RL64(p) AV_RL(64, p)
305
#endif
306
#ifndef AV_WL64
307
# define AV_WL64(p, v) AV_WL(64, p, v)
308
#endif
309
310
#ifndef AV_RB24
311
# define AV_RB24(x) \
312
((((const uint8_t*)(x))[0] << 16) | \
313
(((const uint8_t*)(x))[1] << 8) | \
314
((const uint8_t*)(x))[2])
315
#endif
316
#ifndef AV_WB24
317
# define AV_WB24(p, d) do { \
318
((uint8_t*)(p))[2] = (d); \
319
((uint8_t*)(p))[1] = (d)>>8; \
320
((uint8_t*)(p))[0] = (d)>>16; \
321
} while(0)
322
#endif
323
324
#ifndef AV_RL24
325
# define AV_RL24(x) \
326
((((const uint8_t*)(x))[2] << 16) | \
327
(((const uint8_t*)(x))[1] << 8) | \
328
((const uint8_t*)(x))[0])
329
#endif
330
#ifndef AV_WL24
331
# define AV_WL24(p, d) do { \
332
((uint8_t*)(p))[0] = (d); \
333
((uint8_t*)(p))[1] = (d)>>8; \
334
((uint8_t*)(p))[2] = (d)>>16; \
335
} while(0)
336
#endif
337
338