summaryrefslogtreecommitdiff
path: root/apps/codecs/libcook/bswap.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libcook/bswap.h')
-rw-r--r--apps/codecs/libcook/bswap.h173
1 files changed, 112 insertions, 61 deletions
diff --git a/apps/codecs/libcook/bswap.h b/apps/codecs/libcook/bswap.h
index 443cd1c3f9..b083d10ed0 100644
--- a/apps/codecs/libcook/bswap.h
+++ b/apps/codecs/libcook/bswap.h
@@ -1,86 +1,137 @@
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * 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 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/** 1/**
22 * @file libavutil/bswap.h 2 * @file bswap.h
23 * byte swapping routines 3 * byte swap.
24 */ 4 */
25 5
26#ifndef AVUTIL_BSWAP_H 6#ifndef __BSWAP_H__
27#define AVUTIL_BSWAP_H 7#define __BSWAP_H__
28 8
29#include <stdint.h> 9#ifdef HAVE_BYTESWAP_H
30//#include "ffmpeg_config.h" 10#include <byteswap.h>
31//#include "common.h" 11#else
32
33#if ARCH_ARM
34# include "arm/bswap.h"
35#elif ARCH_BFIN
36# include "bfin/bswap.h"
37#elif ARCH_SH4
38# include "sh4/bswap.h"
39#elif ARCH_X86
40# include "x86/bswap.h"
41#endif
42 12
43#ifndef bswap_16 13#ifdef ROCKBOX
44static inline uint16_t bswap_16(uint16_t x) 14#include "codecs.h"
15
16/* rockbox' optimised inline functions */
17#define bswap_16(x) swap16(x)
18#define bswap_32(x) swap32(x)
19
20static inline uint64_t ByteSwap64(uint64_t x)
45{ 21{
46 x= (x>>8) | (x<<8); 22 union {
47 return x; 23 uint64_t ll;
24 struct {
25 uint32_t l,h;
26 } l;
27 } r;
28 r.l.l = bswap_32 (x);
29 r.l.h = bswap_32 (x>>32);
30 return r.ll;
48} 31}
49#endif 32#define bswap_64(x) ByteSwap64(x)
50 33
51#ifndef bswap_32 34#elif defined(ARCH_X86)
52static inline uint32_t bswap_32(uint32_t x) 35static inline unsigned short ByteSwap16(unsigned short x)
53{ 36{
54 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); 37 __asm("xchgb %b0,%h0" :
55 x= (x>>16) | (x<<16); 38 "=q" (x) :
39 "0" (x));
56 return x; 40 return x;
57} 41}
42#define bswap_16(x) ByteSwap16(x)
43
44static inline unsigned int ByteSwap32(unsigned int x)
45{
46#if __CPU__ > 386
47 __asm("bswap %0":
48 "=r" (x) :
49#else
50 __asm("xchgb %b0,%h0\n"
51 " rorl $16,%0\n"
52 " xchgb %b0,%h0":
53 "=q" (x) :
58#endif 54#endif
55 "0" (x));
56 return x;
57}
58#define bswap_32(x) ByteSwap32(x)
59 59
60#ifndef bswap_64 60static inline unsigned long long int ByteSwap64(unsigned long long int x)
61static inline uint64_t bswap_64(uint64_t x)
62{ 61{
63#if 0 62 register union { __extension__ uint64_t __ll;
64 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); 63 uint32_t __l[2]; } __x;
65 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); 64 asm("xchgl %0,%1":
66 return (x>>32) | (x<<32); 65 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
66 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
67 return __x.__ll;
68}
69#define bswap_64(x) ByteSwap64(x)
70
71#elif defined(ARCH_SH4)
72
73static inline uint16_t ByteSwap16(uint16_t x) {
74 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
75 return x;
76}
77
78static inline uint32_t ByteSwap32(uint32_t x) {
79 __asm__(
80 "swap.b %0,%0\n"
81 "swap.w %0,%0\n"
82 "swap.b %0,%0\n"
83 :"=r"(x):"0"(x));
84 return x;
85}
86
87#define bswap_16(x) ByteSwap16(x)
88#define bswap_32(x) ByteSwap32(x)
89
90static inline uint64_t ByteSwap64(uint64_t x)
91{
92 union {
93 uint64_t ll;
94 struct {
95 uint32_t l,h;
96 } l;
97 } r;
98 r.l.l = bswap_32 (x);
99 r.l.h = bswap_32 (x>>32);
100 return r.ll;
101}
102#define bswap_64(x) ByteSwap64(x)
103
67#else 104#else
68 union { 105
106#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
107
108
109// code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
110#define bswap_32(x) \
111 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
112 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
113
114static inline uint64_t ByteSwap64(uint64_t x)
115{
116 union {
69 uint64_t ll; 117 uint64_t ll;
70 uint32_t l[2]; 118 uint32_t l[2];
71 } w, r; 119 } w, r;
72 w.ll = x; 120 w.ll = x;
73 r.l[0] = bswap_32 (w.l[1]); 121 r.l[0] = bswap_32 (w.l[1]);
74 r.l[1] = bswap_32 (w.l[0]); 122 r.l[1] = bswap_32 (w.l[0]);
75 return r.ll; 123 return r.ll;
76#endif
77} 124}
78#endif 125#define bswap_64(x) ByteSwap64(x)
126
127#endif /* !ARCH_X86 */
128
129#endif /* !HAVE_BYTESWAP_H */
79 130
80// be2me ... big-endian to machine-endian 131// be2me ... BigEndian to MachineEndian
81// le2me ... little-endian to machine-endian 132// le2me ... LittleEndian to MachineEndian
82 133
83#ifdef WORDS_BIGENDIAN 134#ifdef ROCKBOX_BIG_ENDIAN
84#define be2me_16(x) (x) 135#define be2me_16(x) (x)
85#define be2me_32(x) (x) 136#define be2me_32(x) (x)
86#define be2me_64(x) (x) 137#define be2me_64(x) (x)
@@ -96,4 +147,4 @@ static inline uint64_t bswap_64(uint64_t x)
96#define le2me_64(x) (x) 147#define le2me_64(x) (x)
97#endif 148#endif
98 149
99#endif /* AVUTIL_BSWAP_H */ 150#endif /* __BSWAP_H__ */