blob: 0e08fe54ad71fcdb30b2a46756736e88bcdd3d34 [file] [log] [blame]
Harvey Harrison1af84a62009-01-06 14:56:25 -08001#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>
10
11#define __SWAB_64_THRU_32__
12
13static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
14{
15 __asm__(
16#ifdef __SH5__
Paul Mundt567bb8f2009-05-10 14:25:39 +090017 "byterev %1, %0\n\t"
Harvey Harrison1af84a62009-01-06 14:56:25 -080018 "shari %0, 32, %0"
19#else
Paul Mundt567bb8f2009-05-10 14:25:39 +090020 "swap.b %1, %0\n\t"
Harvey Harrison1af84a62009-01-06 14:56:25 -080021 "swap.w %0, %0\n\t"
22 "swap.b %0, %0"
23#endif
24 : "=r" (x)
Paul Mundt567bb8f2009-05-10 14:25:39 +090025 : "r" (x));
Harvey Harrison1af84a62009-01-06 14:56:25 -080026
27 return x;
28}
29#define __arch_swab32 __arch_swab32
30
31static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
32{
33 __asm__(
34#ifdef __SH5__
Paul Mundt567bb8f2009-05-10 14:25:39 +090035 "byterev %1, %0\n\t"
Harvey Harrison1af84a62009-01-06 14:56:25 -080036 "shari %0, 32, %0"
37#else
Paul Mundt567bb8f2009-05-10 14:25:39 +090038 "swap.b %1, %0"
Harvey Harrison1af84a62009-01-06 14:56:25 -080039#endif
40 : "=r" (x)
Paul Mundt567bb8f2009-05-10 14:25:39 +090041 : "r" (x));
Harvey Harrison1af84a62009-01-06 14:56:25 -080042
43 return x;
44}
45#define __arch_swab16 __arch_swab16
46
47static inline __u64 __arch_swab64(__u64 val)
48{
49 union {
50 struct { __u32 a,b; } s;
51 __u64 u;
52 } v, w;
53 v.u = val;
54 w.s.b = __arch_swab32(v.s.a);
55 w.s.a = __arch_swab32(v.s.b);
56 return w.u;
57}
58#define __arch_swab64 __arch_swab64
59
60#endif /* __ASM_SH_SWAB_H */