blob: 0eb9904b6545be3be0b7a99c6b258c25828fc2fa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH_BYTEORDER_H
2#define __ASM_SH_BYTEORDER_H
3
4/*
5 * Copyright (C) 1999 Niibe Yutaka
Paul Mundt7a65eaf2007-11-09 13:58:44 +09006 * Copyright (C) 2000, 2001 Paolo Alberelli
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/compiler.h>
Paul Mundt7a65eaf2007-11-09 13:58:44 +09009#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Paul Mundt7a65eaf2007-11-09 13:58:44 +090011static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012{
Paul Mundt7a65eaf2007-11-09 13:58:44 +090013 __asm__(
14#ifdef CONFIG_SUPERH32
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 : "=r" (x)
23 : "0" (x));
Paul Mundt7a65eaf2007-11-09 13:58:44 +090024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 return x;
26}
27
Paul Mundt7a65eaf2007-11-09 13:58:44 +090028static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Paul Mundt7a65eaf2007-11-09 13:58:44 +090030 __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
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 : "=r" (x)
39 : "0" (x));
Paul Mundt7a65eaf2007-11-09 13:58:44 +090040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 return x;
42}
43
Paul Mundt7a65eaf2007-11-09 13:58:44 +090044static inline __u64 ___arch__swab64(__u64 val)
45{
46 union {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 struct { __u32 a,b; } s;
48 __u64 u;
49 } v, w;
50 v.u = val;
Paul Mundt7a65eaf2007-11-09 13:58:44 +090051 w.s.b = ___arch__swab32(v.s.a);
52 w.s.a = ___arch__swab32(v.s.b);
53 return w.u;
54}
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define __arch__swab64(x) ___arch__swab64(x)
57#define __arch__swab32(x) ___arch__swab32(x)
58#define __arch__swab16(x) ___arch__swab16(x)
59
60#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
61# define __BYTEORDER_HAS_U64__
62# define __SWAB_64_THRU_32__
63#endif
64
65#ifdef __LITTLE_ENDIAN__
66#include <linux/byteorder/little_endian.h>
67#else
68#include <linux/byteorder/big_endian.h>
69#endif
70
71#endif /* __ASM_SH_BYTEORDER_H */