Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SH_BYTEORDER_H |
| 2 | #define __ASM_SH_BYTEORDER_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1999 Niibe Yutaka |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 6 | * Copyright (C) 2000, 2001 Paolo Alberelli |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/compiler.h> |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 9 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 11 | #ifdef __LITTLE_ENDIAN__ |
| 12 | # define __LITTLE_ENDIAN |
| 13 | #else |
| 14 | # define __BIG_ENDIAN |
| 15 | #endif |
| 16 | |
| 17 | #define __SWAB_64_THRU_32__ |
| 18 | |
| 19 | static inline __attribute_const__ __u32 __arch_swab32(__u32 x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | { |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 21 | __asm__( |
Paul Mundt | 6dba1b6 | 2008-03-14 17:21:09 +0900 | [diff] [blame] | 22 | #ifdef __SH5__ |
| 23 | "byterev %0, %0\n\t" |
| 24 | "shari %0, 32, %0" |
| 25 | #else |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 26 | "swap.b %0, %0\n\t" |
| 27 | "swap.w %0, %0\n\t" |
| 28 | "swap.b %0, %0" |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 29 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | : "=r" (x) |
| 31 | : "0" (x)); |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | return x; |
| 34 | } |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 35 | #define __arch_swab32 __arch_swab32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 37 | static inline __attribute_const__ __u16 __arch_swab16(__u16 x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 39 | __asm__( |
Paul Mundt | 6dba1b6 | 2008-03-14 17:21:09 +0900 | [diff] [blame] | 40 | #ifdef __SH5__ |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 41 | "byterev %0, %0\n\t" |
| 42 | "shari %0, 32, %0" |
Paul Mundt | 6dba1b6 | 2008-03-14 17:21:09 +0900 | [diff] [blame] | 43 | #else |
| 44 | "swap.b %0, %0" |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 45 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | : "=r" (x) |
| 47 | : "0" (x)); |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | return x; |
| 50 | } |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 51 | #define __arch_swab16 __arch_swab16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 53 | static inline __u64 __arch_swab64(__u64 val) |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 54 | { |
| 55 | union { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | struct { __u32 a,b; } s; |
| 57 | __u64 u; |
| 58 | } v, w; |
| 59 | v.u = val; |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 60 | w.s.b = __arch_swab32(v.s.a); |
| 61 | w.s.a = __arch_swab32(v.s.b); |
Paul Mundt | 7a65eaf | 2007-11-09 13:58:44 +0900 | [diff] [blame] | 62 | return w.u; |
| 63 | } |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 64 | #define __arch_swab64 __arch_swab64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Harvey Harrison | 1406266 | 2008-10-31 16:01:22 +0900 | [diff] [blame] | 66 | #include <linux/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | #endif /* __ASM_SH_BYTEORDER_H */ |