Subversion Repositories shark

Rev

Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
#ifndef _I386_BYTEORDER_H
2
#define _I386_BYTEORDER_H
3
 
4
#include <asm/types.h>
5
 
6
#ifdef __GNUC__
7
 
8
/* For avoiding bswap on i386 */
9
#ifdef __KERNEL__
10
#include <linux/config.h>
11
#endif
12
 
1056 tullio 13
static __inline__ __attribute__((const)) __u32 ___arch__swab32(__u32 x)
422 giacomo 14
{
15
#ifdef CONFIG_X86_BSWAP
16
        __asm__("bswap %0" : "=r" (x) : "0" (x));
17
#else
18
        __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
19
                "rorl $16,%0\n\t"       /* swap words           */
20
                "xchgb %b0,%h0"         /* swap higher bytes    */
21
                :"=q" (x)
22
                : "0" (x));
23
#endif
24
        return x;
25
}
26
 
27
/* gcc should generate this for open coded C now too. May be worth switching to
28
   it because inline assembly cannot be scheduled. -AK */
1056 tullio 29
static __inline__ __attribute__((const)) __u16 ___arch__swab16(__u16 x)
422 giacomo 30
{
31
        __asm__("xchgb %b0,%h0"         /* swap bytes           */
32
                : "=q" (x)
33
                :  "0" (x));
34
                return x;
35
}
36
 
37
 
38
static inline __u64 ___arch__swab64(__u64 val)
39
{
40
        union {
41
                struct { __u32 a,b; } s;
42
                __u64 u;
43
        } v;
44
        v.u = val;
45
#ifdef CONFIG_X86_BSWAP
46
        asm("bswapl %0 ; bswapl %1 ; xchgl %0,%1"
47
            : "=r" (v.s.a), "=r" (v.s.b)
48
            : "0" (v.s.a), "1" (v.s.b));
49
#else
50
   v.s.a = ___arch__swab32(v.s.a);
51
        v.s.b = ___arch__swab32(v.s.b);
52
        asm("xchgl %0,%1" : "=r" (v.s.a), "=r" (v.s.b) : "0" (v.s.a), "1" (v.s.b));
53
#endif
54
        return v.u;    
55
}
56
 
57
#define __arch__swab64(x) ___arch__swab64(x)
58
#define __arch__swab32(x) ___arch__swab32(x)
59
#define __arch__swab16(x) ___arch__swab16(x)
60
 
61
#define __BYTEORDER_HAS_U64__
62
 
63
#endif /* __GNUC__ */
64
 
65
#include <linux/byteorder/little_endian.h>
66
 
67
#endif /* _I386_BYTEORDER_H */