more changes on original files
[linux-2.4.git] / include / asm-parisc / byteorder.h
1 #ifndef _PARISC_BYTEORDER_H
2 #define _PARISC_BYTEORDER_H
3
4 #include <asm/types.h>
5
6 #ifdef __GNUC__
7
8 static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
9 {
10         unsigned int temp;
11         __asm__("shd %0, %0, 16, %1\n\t"        /* shift abcdabcd -> cdab */
12                 "dep %1, 15, 8, %1\n\t"         /* deposit cdab -> cbab */
13                 "shd %0, %1, 8, %0"             /* shift abcdcbab -> dcba */
14                 : "=r" (x), "=&r" (temp)
15                 : "0" (x));
16         return x;
17 }
18
19
20 #if BITS_PER_LONG > 32
21 /*
22 ** From "PA-RISC 2.0 Architecture", HP Professional Books.
23 ** See Appendix I page 8 , "Endian Byte Swapping".
24 **
25 ** Pretty cool algorithm: (* == zero'd bits)
26 **      PERMH   01234567 -> 67452301 into %0
27 **      HSHL    67452301 -> 7*5*3*1* into %1
28 **      HSHR    67452301 -> *6*4*2*0 into %0
29 **      OR      %0 | %1  -> 76543210 into %0 (all done!)
30 */
31 static __inline__ __const__ __u64 ___arch__swab64(__u64 x) {
32         __u64 temp;
33         __asm__("permh 3210, %0, %0\n\t"
34                 "hshl %0, 8, %1\n\t"
35                 "hshr u, %0, 8, %0\n\t"
36                 "or %1, %0, %0"
37                 : "=r" (x), "=&r" (temp)
38                 : "0" (x));
39         return x;
40 }
41 #define __arch__swab64(x) ___arch__swab64(x)
42 #else
43 static __inline__ __const__ __u64 ___arch__swab64(__u64 x)
44 {
45         __u32 t1 = (__u32) x;
46         __u32 t2 = (__u32) ((x) >> 32);
47         ___arch__swab32(t1);
48         ___arch__swab32(t2);
49         return (((__u64) t1 << 32) + ((__u64) t2));
50 }
51 #endif
52
53
54 static __inline__ __const__ __u16 ___arch__swab16(__u16 x)
55 {
56         __asm__("dep %0, 15, 8, %0\n\t"         /* deposit 00ab -> 0bab */
57                 "shd %r0, %0, 8, %0"            /* shift 000000ab -> 00ba */
58                 : "=r" (x)
59                 : "0" (x));
60         return x;
61 }
62
63 #define __arch__swab32(x) ___arch__swab32(x)
64 #define __arch__swab16(x) ___arch__swab16(x)
65
66 #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
67 #  define __BYTEORDER_HAS_U64__
68 #  define __SWAB_64_THRU_32__
69 #endif
70
71 #endif /* __GNUC__ */
72
73 #include <linux/byteorder/big_endian.h>
74
75 #endif /* _PARISC_BYTEORDER_H */