blob: 83095c5bb379b7e685454e09ea30b926a82c60db [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _PARISC_BYTEORDER_H
2#define _PARISC_BYTEORDER_H
3
4#include <asm/types.h>
5#include <linux/compiler.h>
6
Harvey Harrisond2e66752008-12-02 03:28:17 +00007#define __BIG_ENDIAN
8#define __SWAB_64_THRU_32__
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Harvey Harrisond2e66752008-12-02 03:28:17 +000010static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070011{
12 __asm__("dep %0, 15, 8, %0\n\t" /* deposit 00ab -> 0bab */
13 "shd %%r0, %0, 8, %0" /* shift 000000ab -> 00ba */
14 : "=r" (x)
15 : "0" (x));
16 return x;
17}
Harvey Harrisond2e66752008-12-02 03:28:17 +000018#define __arch_swab16 __arch_swab16
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Harvey Harrisond2e66752008-12-02 03:28:17 +000020static inline __attribute_const__ __u32 __arch_swab24(__u32 x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
22 __asm__("shd %0, %0, 8, %0\n\t" /* shift xabcxabc -> cxab */
23 "dep %0, 15, 8, %0\n\t" /* deposit cxab -> cbab */
24 "shd %%r0, %0, 8, %0" /* shift 0000cbab -> 0cba */
25 : "=r" (x)
26 : "0" (x));
27 return x;
28}
29
Harvey Harrisond2e66752008-12-02 03:28:17 +000030static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 unsigned int temp;
33 __asm__("shd %0, %0, 16, %1\n\t" /* shift abcdabcd -> cdab */
34 "dep %1, 15, 8, %1\n\t" /* deposit cdab -> cbab */
35 "shd %0, %1, 8, %0" /* shift abcdcbab -> dcba */
36 : "=r" (x), "=&r" (temp)
37 : "0" (x));
38 return x;
39}
Harvey Harrisond2e66752008-12-02 03:28:17 +000040#define __arch_swab32 __arch_swab32
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#if BITS_PER_LONG > 32
43/*
44** From "PA-RISC 2.0 Architecture", HP Professional Books.
45** See Appendix I page 8 , "Endian Byte Swapping".
46**
47** Pretty cool algorithm: (* == zero'd bits)
48** PERMH 01234567 -> 67452301 into %0
49** HSHL 67452301 -> 7*5*3*1* into %1
50** HSHR 67452301 -> *6*4*2*0 into %0
51** OR %0 | %1 -> 76543210 into %0 (all done!)
52*/
Harvey Harrisond2e66752008-12-02 03:28:17 +000053static inline __attribute_const__ __u64 __arch_swab64(__u64 x)
54{
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 __u64 temp;
56 __asm__("permh,3210 %0, %0\n\t"
57 "hshl %0, 8, %1\n\t"
58 "hshr,u %0, 8, %0\n\t"
59 "or %1, %0, %0"
60 : "=r" (x), "=&r" (temp)
61 : "0" (x));
62 return x;
63}
Harvey Harrisond2e66752008-12-02 03:28:17 +000064#define __arch_swab64 __arch_swab64
65#endif /* BITS_PER_LONG > 32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Harvey Harrisond2e66752008-12-02 03:28:17 +000067#include <linux/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#endif /* _PARISC_BYTEORDER_H */