Statistics
| Branch: | Revision:

ffmpeg / libavutil / bswap.h @ 5ce6934e

History | View | Annotate | Download (2.4 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 bad5537e Diego Biurrun
 * @file libavutil/bswap.h
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 a087028a Diego Biurrun
#include "config.h"
31 99545457 Måns Rullgård
#include "common.h"
32
33 b250f9c6 Aurelien Jacobs
#if   ARCH_ARM
34 3a90480a Måns Rullgård
#   include "arm/bswap.h"
35 e482c2e2 Måns Rullgård
#elif ARCH_AVR32
36
#   include "avr32/bswap.h"
37 b250f9c6 Aurelien Jacobs
#elif ARCH_BFIN
38 3a90480a Måns Rullgård
#   include "bfin/bswap.h"
39 b250f9c6 Aurelien Jacobs
#elif ARCH_SH4
40 3a90480a Måns Rullgård
#   include "sh4/bswap.h"
41 b250f9c6 Aurelien Jacobs
#elif ARCH_X86
42 3a90480a Måns Rullgård
#   include "x86/bswap.h"
43
#endif
44
45
#ifndef bswap_16
46 85074d3c Zuxy Meng
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
47 a9b3f630 Nick Kurshev
{
48 bf5d7db5 Ramiro Polla
    x= (x>>8) | (x<<8);
49 a9b3f630 Nick Kurshev
    return x;
50
}
51 3a90480a Måns Rullgård
#endif
52 a9b3f630 Nick Kurshev
53 3a90480a Måns Rullgård
#ifndef bswap_32
54 85074d3c Zuxy Meng
static av_always_inline av_const uint32_t bswap_32(uint32_t x)
55 a9b3f630 Nick Kurshev
{
56 33f72572 Michael Niedermayer
    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
57 853d15c2 Ramiro Polla
    x= (x>>16) | (x<<16);
58
    return x;
59 24dea064 Michael Niedermayer
}
60 3a90480a Måns Rullgård
#endif
61 a9b3f630 Nick Kurshev
62 3a90480a Måns Rullgård
#ifndef bswap_64
63 85074d3c Zuxy Meng
static inline uint64_t av_const bswap_64(uint64_t x)
64 74fc9989 Fabrice Bellard
{
65 33f72572 Michael Niedermayer
#if 0
66
    x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
67
    x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
68
    return (x>>32) | (x<<32);
69
#else
70 115329f1 Diego Biurrun
    union {
71 74fc9989 Fabrice Bellard
        uint64_t ll;
72 115329f1 Diego Biurrun
        uint32_t l[2];
73 74fc9989 Fabrice Bellard
    } w, r;
74
    w.ll = x;
75
    r.l[0] = bswap_32 (w.l[1]);
76
    r.l[1] = bswap_32 (w.l[0]);
77
    return r.ll;
78 33f72572 Michael Niedermayer
#endif
79 74fc9989 Fabrice Bellard
}
80 3a90480a Måns Rullgård
#endif
81 a9b3f630 Nick Kurshev
82 89c9ff50 Diego Biurrun
// be2me ... big-endian to machine-endian
83
// le2me ... little-endian to machine-endian
84 a9b3f630 Nick Kurshev
85 63613fe6 Måns Rullgård
#if HAVE_BIGENDIAN
86 a9b3f630 Nick Kurshev
#define be2me_16(x) (x)
87
#define be2me_32(x) (x)
88
#define be2me_64(x) (x)
89
#define le2me_16(x) bswap_16(x)
90
#define le2me_32(x) bswap_32(x)
91
#define le2me_64(x) bswap_64(x)
92
#else
93
#define be2me_16(x) bswap_16(x)
94
#define be2me_32(x) bswap_32(x)
95
#define be2me_64(x) bswap_64(x)
96
#define le2me_16(x) (x)
97
#define le2me_32(x) (x)
98
#define le2me_64(x) (x)
99
#endif
100
101 98790382 Stefano Sabatini
#endif /* AVUTIL_BSWAP_H */