blob: 4c13e61175632c3dc8f5a60712dda405eb177b66 [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__(
Paul Mundt6dba1b62008-03-14 17:21:09 +090014#ifdef __SH5__
15 "byterev %0, %0\n\t"
16 "shari %0, 32, %0"
17#else
Paul Mundt7a65eaf2007-11-09 13:58:44 +090018 "swap.b %0, %0\n\t"
19 "swap.w %0, %0\n\t"
20 "swap.b %0, %0"
Paul Mundt7a65eaf2007-11-09 13:58:44 +090021#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__(
Paul Mundt6dba1b62008-03-14 17:21:09 +090031#ifdef __SH5__
Paul Mundt7a65eaf2007-11-09 13:58:44 +090032 "byterev %0, %0\n\t"
33 "shari %0, 32, %0"
Paul Mundt6dba1b62008-03-14 17:21:09 +090034#else
35 "swap.b %0, %0"
Paul Mundt7a65eaf2007-11-09 13:58:44 +090036#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 : "=r" (x)
38 : "0" (x));
Paul Mundt7a65eaf2007-11-09 13:58:44 +090039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 return x;
41}
42
Paul Mundt7a65eaf2007-11-09 13:58:44 +090043static inline __u64 ___arch__swab64(__u64 val)
44{
45 union {
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct { __u32 a,b; } s;
47 __u64 u;
48 } v, w;
49 v.u = val;
Paul Mundt7a65eaf2007-11-09 13:58:44 +090050 w.s.b = ___arch__swab32(v.s.a);
51 w.s.a = ___arch__swab32(v.s.b);
52 return w.u;
53}
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#define __arch__swab64(x) ___arch__swab64(x)
56#define __arch__swab32(x) ___arch__swab32(x)
57#define __arch__swab16(x) ___arch__swab16(x)
58
59#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
60# define __BYTEORDER_HAS_U64__
61# define __SWAB_64_THRU_32__
62#endif
63
64#ifdef __LITTLE_ENDIAN__
65#include <linux/byteorder/little_endian.h>
66#else
67#include <linux/byteorder/big_endian.h>
68#endif
69
70#endif /* __ASM_SH_BYTEORDER_H */