annotate bswap.h @ 21291:efec4a336747

Synced with r21168
author torinthiel
date Mon, 27 Nov 2006 08:56:42 +0000
parents 8a7bcdba8e19
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21226
8a7bcdba8e19 Reuse bswap.h from libavutil. Will only work when libavutil subdir is available.
reimar
parents: 18388
diff changeset
1 #ifndef __MP_BSWAP_H__
8a7bcdba8e19 Reuse bswap.h from libavutil. Will only work when libavutil subdir is available.
reimar
parents: 18388
diff changeset
2 #define __MP_BSWAP_H__
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
3
21226
8a7bcdba8e19 Reuse bswap.h from libavutil. Will only work when libavutil subdir is available.
reimar
parents: 18388
diff changeset
4 #include "libavutil/common.h"
8a7bcdba8e19 Reuse bswap.h from libavutil. Will only work when libavutil subdir is available.
reimar
parents: 18388
diff changeset
5 #include "libavutil/bswap.h"
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
6
18388
afcecc96ed2d fix the warning generated (in gcc4) by the 'inline' keyword position.
iive
parents: 17664
diff changeset
7 static inline float bswap_flt(float x) {
15976
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
8 union {uint32_t i; float f;} u;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
9 u.f = x;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
10 u.i = bswap_32(u.i);
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
11 return u.f;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
12 }
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
13
18388
afcecc96ed2d fix the warning generated (in gcc4) by the 'inline' keyword position.
iive
parents: 17664
diff changeset
14 static inline double bswap_dbl(double x) {
15976
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
15 union {uint64_t i; double d;} u;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
16 u.d = x;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
17 u.i = bswap_64(u.i);
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
18 return u.d;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
19 }
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
20
18388
afcecc96ed2d fix the warning generated (in gcc4) by the 'inline' keyword position.
iive
parents: 17664
diff changeset
21 static inline long double bswap_ldbl(long double x) {
15976
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
22 union {char d[10]; long double ld;} uin;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
23 union {char d[10]; long double ld;} uout;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
24 uin.ld = x;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
25 uout.d[0] = uin.d[9];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
26 uout.d[1] = uin.d[8];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
27 uout.d[2] = uin.d[7];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
28 uout.d[3] = uin.d[6];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
29 uout.d[4] = uin.d[5];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
30 uout.d[5] = uin.d[4];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
31 uout.d[6] = uin.d[3];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
32 uout.d[7] = uin.d[2];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
33 uout.d[8] = uin.d[1];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
34 uout.d[9] = uin.d[0];
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
35 return uout.ld;
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
36 }
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
37
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
38 // be2me ... BigEndian to MachineEndian
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
39 // le2me ... LittleEndian to MachineEndian
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
40
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
41 #ifdef WORDS_BIGENDIAN
15976
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
42 #define be2me_flt(x) (x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
43 #define be2me_dbl(x) (x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
44 #define be2me_ldbl(x) (x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
45 #define le2me_flt(x) bswap_flt(x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
46 #define le2me_dbl(x) bswap_dbl(x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
47 #define le2me_ldbl(x) bswap_ldbl(x)
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
48 #else
15976
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
49 #define be2me_flt(x) bswap_flt(x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
50 #define be2me_dbl(x) bswap_dbl(x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
51 #define be2me_ldbl(x) bswap_ldbl(x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
52 #define le2me_flt(x) (x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
53 #define le2me_dbl(x) (x)
28b8fc8278e0 (hopefully) fixing remaining float endianness problems
reimar
parents: 13720
diff changeset
54 #define le2me_ldbl(x) (x)
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
55 #endif
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
56
21226
8a7bcdba8e19 Reuse bswap.h from libavutil. Will only work when libavutil subdir is available.
reimar
parents: 18388
diff changeset
57 #endif /* __MP_BSWAP_H__ */