aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sh/byteorder.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-sh/byteorder.h')
-rw-r--r--include/asm-sh/byteorder.h45
1 files changed, 30 insertions, 15 deletions
diff --git a/include/asm-sh/byteorder.h b/include/asm-sh/byteorder.h
index bff2b1382e01..0eb9904b6545 100644
--- a/include/asm-sh/byteorder.h
+++ b/include/asm-sh/byteorder.h
@@ -3,40 +3,55 @@
3 3
4/* 4/*
5 * Copyright (C) 1999 Niibe Yutaka 5 * Copyright (C) 1999 Niibe Yutaka
6 * Copyright (C) 2000, 2001 Paolo Alberelli
6 */ 7 */
7
8#include <asm/types.h>
9#include <linux/compiler.h> 8#include <linux/compiler.h>
9#include <linux/types.h>
10 10
11static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x) 11static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
12{ 12{
13 __asm__("swap.b %0, %0\n\t" 13 __asm__(
14 "swap.w %0, %0\n\t" 14#ifdef CONFIG_SUPERH32
15 "swap.b %0, %0" 15 "swap.b %0, %0\n\t"
16 "swap.w %0, %0\n\t"
17 "swap.b %0, %0"
18#else
19 "byterev %0, %0\n\t"
20 "shari %0, 32, %0"
21#endif
16 : "=r" (x) 22 : "=r" (x)
17 : "0" (x)); 23 : "0" (x));
24
18 return x; 25 return x;
19} 26}
20 27
21static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x) 28static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
22{ 29{
23 __asm__("swap.b %0, %0" 30 __asm__(
31#ifdef CONFIG_SUPERH32
32 "swap.b %0, %0"
33#else
34 "byterev %0, %0\n\t"
35 "shari %0, 32, %0"
36
37#endif
24 : "=r" (x) 38 : "=r" (x)
25 : "0" (x)); 39 : "0" (x));
40
26 return x; 41 return x;
27} 42}
28 43
29static inline __u64 ___arch__swab64(__u64 val) 44static inline __u64 ___arch__swab64(__u64 val)
30{ 45{
31 union { 46 union {
32 struct { __u32 a,b; } s; 47 struct { __u32 a,b; } s;
33 __u64 u; 48 __u64 u;
34 } v, w; 49 } v, w;
35 v.u = val; 50 v.u = val;
36 w.s.b = ___arch__swab32(v.s.a); 51 w.s.b = ___arch__swab32(v.s.a);
37 w.s.a = ___arch__swab32(v.s.b); 52 w.s.a = ___arch__swab32(v.s.b);
38 return w.u; 53 return w.u;
39} 54}
40 55
41#define __arch__swab64(x) ___arch__swab64(x) 56#define __arch__swab64(x) ___arch__swab64(x)
42#define __arch__swab32(x) ___arch__swab32(x) 57#define __arch__swab32(x) ___arch__swab32(x)