diff libavutil/bswap.h @ 2:897f711a7157

rearrange to work with autoconf
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Tue, 25 Sep 2012 15:55:33 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libavutil/bswap.h	Tue Sep 25 15:55:33 2012 +0200
     1.3 @@ -0,0 +1,95 @@
     1.4 +/*
     1.5 + * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
     1.6 + *
     1.7 + * This file is part of FFmpeg.
     1.8 + *
     1.9 + * FFmpeg is free software; you can redistribute it and/or
    1.10 + * modify it under the terms of the GNU Lesser General Public
    1.11 + * License as published by the Free Software Foundation; either
    1.12 + * version 2.1 of the License, or (at your option) any later version.
    1.13 + *
    1.14 + * FFmpeg is distributed in the hope that it will be useful,
    1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 + * Lesser General Public License for more details.
    1.18 + *
    1.19 + * You should have received a copy of the GNU Lesser General Public
    1.20 + * License along with FFmpeg; if not, write to the Free Software
    1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
    1.22 + */
    1.23 +
    1.24 +/**
    1.25 + * @file
    1.26 + * byte swapping routines
    1.27 + */
    1.28 +
    1.29 +#ifndef AVUTIL_BSWAP_H
    1.30 +#define AVUTIL_BSWAP_H
    1.31 +
    1.32 +#include <stdint.h>
    1.33 +#include "config.h"
    1.34 +#include "attributes.h"
    1.35 +
    1.36 +#if   ARCH_ARM
    1.37 +#   include "arm/bswap.h"
    1.38 +#elif ARCH_X86
    1.39 +#   include "x86/bswap.h"
    1.40 +#endif
    1.41 +
    1.42 +#ifndef bswap_16
    1.43 +static av_always_inline av_const uint16_t bswap_16(uint16_t x)
    1.44 +{
    1.45 +    x= (x>>8) | (x<<8);
    1.46 +    return x;
    1.47 +}
    1.48 +#endif
    1.49 +
    1.50 +#ifndef bswap_32
    1.51 +static av_always_inline av_const uint32_t bswap_32(uint32_t x)
    1.52 +{
    1.53 +    x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
    1.54 +    x= (x>>16) | (x<<16);
    1.55 +    return x;
    1.56 +}
    1.57 +#endif
    1.58 +
    1.59 +#ifndef bswap_64
    1.60 +static inline uint64_t av_const bswap_64(uint64_t x)
    1.61 +{
    1.62 +#if 0
    1.63 +    x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
    1.64 +    x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
    1.65 +    return (x>>32) | (x<<32);
    1.66 +#else
    1.67 +    union {
    1.68 +        uint64_t ll;
    1.69 +        uint32_t l[2];
    1.70 +    } w, r;
    1.71 +    w.ll = x;
    1.72 +    r.l[0] = bswap_32 (w.l[1]);
    1.73 +    r.l[1] = bswap_32 (w.l[0]);
    1.74 +    return r.ll;
    1.75 +#endif
    1.76 +}
    1.77 +#endif
    1.78 +
    1.79 +// be2me ... big-endian to machine-endian
    1.80 +// le2me ... little-endian to machine-endian
    1.81 +
    1.82 +#if HAVE_BIGENDIAN
    1.83 +#define be2me_16(x) (x)
    1.84 +#define be2me_32(x) (x)
    1.85 +#define be2me_64(x) (x)
    1.86 +#define le2me_16(x) bswap_16(x)
    1.87 +#define le2me_32(x) bswap_32(x)
    1.88 +#define le2me_64(x) bswap_64(x)
    1.89 +#else
    1.90 +#define be2me_16(x) bswap_16(x)
    1.91 +#define be2me_32(x) bswap_32(x)
    1.92 +#define be2me_64(x) bswap_64(x)
    1.93 +#define le2me_16(x) (x)
    1.94 +#define le2me_32(x) (x)
    1.95 +#define le2me_64(x) (x)
    1.96 +#endif
    1.97 +
    1.98 +#endif /* AVUTIL_BSWAP_H */