Statistics
| Branch: | Revision:

ffmpeg / libavutil / bswap.h @ 08675bb3

History | View | Annotate | Download (3.14 KB)

1 04d7f601 Diego Biurrun
/*
2
 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 04d7f601 Diego Biurrun
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 04d7f601 Diego Biurrun
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 04d7f601 Diego Biurrun
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 04d7f601 Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21 983e3246 Michael Niedermayer
/**
22 ba87f080 Diego Biurrun
 * @file
23 7ce68923 Diego Biurrun
 * byte swapping routines
24 983e3246 Michael Niedermayer
 */
25
26 98790382 Stefano Sabatini
#ifndef AVUTIL_BSWAP_H
27
#define AVUTIL_BSWAP_H
28 a9b3f630 Nick Kurshev
29 99545457 Måns Rullgård
#include <stdint.h>
30 1fc81e73 Måns Rullgård
#include "libavutil/avconfig.h"
31 2ed6f399 Måns Rullgård
#include "attributes.h"
32 99545457 Måns Rullgård
33 1fc81e73 Måns Rullgård
#ifdef HAVE_AV_CONFIG_H
34
35
#include "config.h"
36
37 b250f9c6 Aurelien Jacobs
#if   ARCH_ARM
38 3a90480a Måns Rullgård
#   include "arm/bswap.h"
39 e482c2e2 Måns Rullgård
#elif ARCH_AVR32
40
#   include "avr32/bswap.h"
41 b250f9c6 Aurelien Jacobs
#elif ARCH_BFIN
42 3a90480a Måns Rullgård
#   include "bfin/bswap.h"
43 b250f9c6 Aurelien Jacobs
#elif ARCH_SH4
44 3a90480a Måns Rullgård
#   include "sh4/bswap.h"
45 b250f9c6 Aurelien Jacobs
#elif ARCH_X86
46 3a90480a Måns Rullgård
#   include "x86/bswap.h"
47
#endif
48
49 1fc81e73 Måns Rullgård
#endif /* HAVE_AV_CONFIG_H */
50
51 547b7bcb Måns Rullgård
#define AV_BSWAP16C(x) (((x) << 8 & 0xff00)  | ((x) >> 8 & 0x00ff))
52 cc6849ae Måns Rullgård
#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
53
#define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
54 547b7bcb Måns Rullgård
55
#define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
56
57 8fc0162a Måns Rullgård
#ifndef av_bswap16
58
static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
59 a9b3f630 Nick Kurshev
{
60 bf5d7db5 Ramiro Polla
    x= (x>>8) | (x<<8);
61 a9b3f630 Nick Kurshev
    return x;
62
}
63 3a90480a Måns Rullgård
#endif
64 a9b3f630 Nick Kurshev
65 8fc0162a Måns Rullgård
#ifndef av_bswap32
66
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
67 a9b3f630 Nick Kurshev
{
68 33f72572 Michael Niedermayer
    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
69 853d15c2 Ramiro Polla
    x= (x>>16) | (x<<16);
70
    return x;
71 24dea064 Michael Niedermayer
}
72 3a90480a Måns Rullgård
#endif
73 a9b3f630 Nick Kurshev
74 8fc0162a Måns Rullgård
#ifndef av_bswap64
75
static inline uint64_t av_const av_bswap64(uint64_t x)
76 74fc9989 Fabrice Bellard
{
77 33f72572 Michael Niedermayer
#if 0
78
    x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
79
    x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
80
    return (x>>32) | (x<<32);
81
#else
82 115329f1 Diego Biurrun
    union {
83 74fc9989 Fabrice Bellard
        uint64_t ll;
84 115329f1 Diego Biurrun
        uint32_t l[2];
85 74fc9989 Fabrice Bellard
    } w, r;
86
    w.ll = x;
87 8fc0162a Måns Rullgård
    r.l[0] = av_bswap32 (w.l[1]);
88
    r.l[1] = av_bswap32 (w.l[0]);
89 74fc9989 Fabrice Bellard
    return r.ll;
90 33f72572 Michael Niedermayer
#endif
91 74fc9989 Fabrice Bellard
}
92 3a90480a Måns Rullgård
#endif
93 a9b3f630 Nick Kurshev
94 e6b22522 Måns Rullgård
// be2ne ... big-endian to native-endian
95
// le2ne ... little-endian to native-endian
96 a9b3f630 Nick Kurshev
97 1fc81e73 Måns Rullgård
#if AV_HAVE_BIGENDIAN
98 8fc0162a Måns Rullgård
#define av_be2ne16(x) (x)
99
#define av_be2ne32(x) (x)
100
#define av_be2ne64(x) (x)
101
#define av_le2ne16(x) av_bswap16(x)
102
#define av_le2ne32(x) av_bswap32(x)
103
#define av_le2ne64(x) av_bswap64(x)
104 e6b22522 Måns Rullgård
#define AV_BE2NEC(s, x) (x)
105
#define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
106 a9b3f630 Nick Kurshev
#else
107 8fc0162a Måns Rullgård
#define av_be2ne16(x) av_bswap16(x)
108
#define av_be2ne32(x) av_bswap32(x)
109
#define av_be2ne64(x) av_bswap64(x)
110
#define av_le2ne16(x) (x)
111
#define av_le2ne32(x) (x)
112
#define av_le2ne64(x) (x)
113 e6b22522 Måns Rullgård
#define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
114
#define AV_LE2NEC(s, x) (x)
115 a9b3f630 Nick Kurshev
#endif
116
117 e6b22522 Måns Rullgård
#define AV_BE2NE16C(x) AV_BE2NEC(16, x)
118
#define AV_BE2NE32C(x) AV_BE2NEC(32, x)
119
#define AV_BE2NE64C(x) AV_BE2NEC(64, x)
120
#define AV_LE2NE16C(x) AV_LE2NEC(16, x)
121
#define AV_LE2NE32C(x) AV_LE2NEC(32, x)
122
#define AV_LE2NE64C(x) AV_LE2NEC(64, x)
123 547b7bcb Måns Rullgård
124 98790382 Stefano Sabatini
#endif /* AVUTIL_BSWAP_H */