Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 1 | #ifndef __ASM_SH_SWAB_H |
| 2 | #define __ASM_SH_SWAB_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1999 Niibe Yutaka |
| 6 | * Copyright (C) 2000, 2001 Paolo Alberelli |
| 7 | */ |
| 8 | #include <linux/compiler.h> |
| 9 | #include <linux/types.h> |
Paul Mundt | f8f06bc | 2009-06-14 23:21:54 +0900 | [diff] [blame] | 10 | #include <asm-generic/swab.h> |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 11 | |
| 12 | static inline __attribute_const__ __u32 __arch_swab32(__u32 x) |
| 13 | { |
| 14 | __asm__( |
| 15 | #ifdef __SH5__ |
Paul Mundt | 567bb8f | 2009-05-10 14:25:39 +0900 | [diff] [blame] | 16 | "byterev %1, %0\n\t" |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 17 | "shari %0, 32, %0" |
| 18 | #else |
Paul Mundt | 567bb8f | 2009-05-10 14:25:39 +0900 | [diff] [blame] | 19 | "swap.b %1, %0\n\t" |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 20 | "swap.w %0, %0\n\t" |
| 21 | "swap.b %0, %0" |
| 22 | #endif |
| 23 | : "=r" (x) |
Paul Mundt | 567bb8f | 2009-05-10 14:25:39 +0900 | [diff] [blame] | 24 | : "r" (x)); |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 25 | |
| 26 | return x; |
| 27 | } |
| 28 | #define __arch_swab32 __arch_swab32 |
| 29 | |
| 30 | static inline __attribute_const__ __u16 __arch_swab16(__u16 x) |
| 31 | { |
| 32 | __asm__( |
| 33 | #ifdef __SH5__ |
Paul Mundt | 567bb8f | 2009-05-10 14:25:39 +0900 | [diff] [blame] | 34 | "byterev %1, %0\n\t" |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 35 | "shari %0, 32, %0" |
| 36 | #else |
Paul Mundt | 567bb8f | 2009-05-10 14:25:39 +0900 | [diff] [blame] | 37 | "swap.b %1, %0" |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 38 | #endif |
| 39 | : "=r" (x) |
Paul Mundt | 567bb8f | 2009-05-10 14:25:39 +0900 | [diff] [blame] | 40 | : "r" (x)); |
Harvey Harrison | 1af84a6 | 2009-01-06 14:56:25 -0800 | [diff] [blame] | 41 | |
| 42 | return x; |
| 43 | } |
| 44 | #define __arch_swab16 __arch_swab16 |
| 45 | |
| 46 | static inline __u64 __arch_swab64(__u64 val) |
| 47 | { |
| 48 | union { |
| 49 | struct { __u32 a,b; } s; |
| 50 | __u64 u; |
| 51 | } v, w; |
| 52 | v.u = val; |
| 53 | w.s.b = __arch_swab32(v.s.a); |
| 54 | w.s.a = __arch_swab32(v.s.b); |
| 55 | return w.u; |
| 56 | } |
| 57 | #define __arch_swab64 __arch_swab64 |
| 58 | |
| 59 | #endif /* __ASM_SH_SWAB_H */ |