~ubuntu-branches/ubuntu/precise/krusader/precise

« back to all changes in this revision

Viewing changes to iso/libisofs/bswap.h

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-05-05 22:26:37 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505222637-ydv3cwjwy365on2r
Tags: 1:2.1.0~beta1-1ubuntu1
* Merge from Debian Unstable.  Remaining changes:
  - Retain Kubuntu doc path

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* From the mplayer project (www.mplayerhq.hu) */
2
 
 
3
 
#ifndef __BSWAP_H__
4
 
#define __BSWAP_H__
5
 
 
 
1
/*****************************************************************************
 
2
 * Copyright (C) 2002 Shie Erlich <erlich@users.sourceforge.net>             *
 
3
 * Copyright (C) 2002 Rafi Yanai <yanai@users.sourceforge.net>               *
 
4
 * From the mplayer project (www.mplayerhq.hu)                               *
 
5
 *                                                                           *
 
6
 * This program is free software; you can redistribute it and/or modify      *
 
7
 * it under the terms of the GNU General Public License as published by      *
 
8
 * the Free Software Foundation; either version 2 of the License, or         *
 
9
 * (at your option) any later version.                                       *
 
10
 *                                                                           *
 
11
 * This package 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             *
 
14
 * GNU General Public License for more details.                              *
 
15
 *                                                                           *
 
16
 * You should have received a copy of the GNU General Public License         *
 
17
 * along with this package; if not, write to the Free Software               *
 
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA *
 
19
 *****************************************************************************/
 
20
 
 
21
#ifndef BSWAP_H
 
22
#define BSWAP_H
 
23
 
 
24
/* this file doesn't exist
6
25
#ifdef HAVE_CONFIG_H
7
26
#include "config.h"
8
27
#endif
 
28
*/
9
29
 
10
30
#ifdef HAVE_BYTESWAP_H
11
31
#include <byteswap.h>
14
34
#ifdef ARCH_X86
15
35
inline static unsigned short ByteSwap16(unsigned short x)
16
36
{
17
 
  __asm("xchgb %b0,%h0" :
18
 
        "=q" (x)        :
19
 
        "0" (x));
 
37
__asm("xchgb %b0,%h0" :
 
38
          "=q"(x) :
 
39
                  "0"(x));
20
40
    return x;
21
41
}
22
42
#define bswap_16(x) ByteSwap16(x)
24
44
inline static unsigned int ByteSwap32(unsigned int x)
25
45
{
26
46
#if __CPU__ > 386
27
 
 __asm("bswap   %0":
28
 
      "=r" (x)     :
 
47
__asm("bswap %0":
 
48
          "=r"(x)     :
29
49
#else
30
 
 __asm("xchgb   %b0,%h0\n"
31
 
      " rorl    $16,%0\n"
32
 
      " xchgb   %b0,%h0":
33
 
      "=q" (x)          :
 
50
                  __asm("xchgb %b0,%h0\n"
 
51
                        " rorl $16,%0\n"
 
52
                        " xchgb %b0,%h0":
 
53
                        "=q"(x)  :
34
54
#endif
35
 
      "0" (x));
36
 
  return x;
37
 
}
 
55
                        "0"(x));
 
56
                  return x;
 
57
              }
38
58
#define bswap_32(x) ByteSwap32(x)
39
59
 
40
 
inline static unsigned long long int ByteSwap64(unsigned long long int x)
 
60
      inline static unsigned long long int ByteSwap64(unsigned long long int x)
41
61
{
42
 
  register union { __extension__ unsigned long long int __ll;
43
 
          unsigned int __l[2]; } __x;
44
 
  asm("xchgl    %0,%1":
45
 
      "=r"(__x.__l[0]),"=r"(__x.__l[1]):
46
 
      "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
47
 
  return __x.__ll;
 
62
    register union { __extension__ unsigned long long int __ll;
 
63
        unsigned int __l[2];
 
64
    } __x;
 
65
asm("xchgl %0,%1":
 
66
        "=r"(__x.__l[0]), "=r"(__x.__l[1]):
 
67
                "0"(bswap_32((unsigned long)x)), "1"(bswap_32((unsigned long)(x >> 32))));
 
68
    return __x.__ll;
48
69
}
49
70
#define bswap_64(x) ByteSwap64(x)
50
71
 
51
72
#else
52
73
 
53
74
#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
54
 
                        
 
75
 
55
76
 
56
77
/* code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. */
57
78
#define bswap_32(x) \
58
 
     ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
59
 
      (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
 
79
    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | \
 
80
     (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
60
81
 
61
82
#define bswap_64(x) \
62
 
     (__extension__                                             \
63
 
      ({ union { __extension__ unsigned long long int __ll;     \
64
 
                 unsigned int __l[2]; } __w, __r;               \
65
 
         __w.__ll = (x);                                        \
66
 
         __r.__l[0] = bswap_32 (__w.__l[1]);                    \
67
 
         __r.__l[1] = bswap_32 (__w.__l[0]);                    \
68
 
         __r.__ll; }))
69
 
#endif  /* !ARCH_X86 */
 
83
    (__extension__      \
 
84
    ({ union { __extension__ unsigned long long int __ll; \
 
85
            unsigned int __l[2]; } __w, __r;  \
 
86
        __w.__ll = (x);     \
 
87
        __r.__l[0] = bswap_32 (__w.__l[1]);   \
 
88
        __r.__l[1] = bswap_32 (__w.__l[0]);   \
 
89
        __r.__ll; }))
 
90
#endif /* !ARCH_X86 */
70
91
 
71
 
#endif  /* !HAVE_BYTESWAP_H */
 
92
#endif /* !HAVE_BYTESWAP_H */
72
93
 
73
94
/*
74
95
 be2me ... BigEndian to MachineEndian