Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[deliverable/linux.git] / include / asm-sh / byteorder.h
CommitLineData
1da177e4
LT
1#ifndef __ASM_SH_BYTEORDER_H
2#define __ASM_SH_BYTEORDER_H
3
4/*
5 * Copyright (C) 1999 Niibe Yutaka
7a65eaf4 6 * Copyright (C) 2000, 2001 Paolo Alberelli
1da177e4 7 */
1da177e4 8#include <linux/compiler.h>
7a65eaf4 9#include <linux/types.h>
1da177e4 10
7a65eaf4 11static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
1da177e4 12{
7a65eaf4 13 __asm__(
6dba1b67
PM
14#ifdef __SH5__
15 "byterev %0, %0\n\t"
16 "shari %0, 32, %0"
17#else
7a65eaf4
PM
18 "swap.b %0, %0\n\t"
19 "swap.w %0, %0\n\t"
20 "swap.b %0, %0"
7a65eaf4 21#endif
1da177e4
LT
22 : "=r" (x)
23 : "0" (x));
7a65eaf4 24
1da177e4
LT
25 return x;
26}
27
7a65eaf4 28static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
1da177e4 29{
7a65eaf4 30 __asm__(
6dba1b67 31#ifdef __SH5__
7a65eaf4
PM
32 "byterev %0, %0\n\t"
33 "shari %0, 32, %0"
6dba1b67
PM
34#else
35 "swap.b %0, %0"
7a65eaf4 36#endif
1da177e4
LT
37 : "=r" (x)
38 : "0" (x));
7a65eaf4 39
1da177e4
LT
40 return x;
41}
42
7a65eaf4
PM
43static inline __u64 ___arch__swab64(__u64 val)
44{
45 union {
1da177e4
LT
46 struct { __u32 a,b; } s;
47 __u64 u;
48 } v, w;
49 v.u = val;
7a65eaf4
PM
50 w.s.b = ___arch__swab32(v.s.a);
51 w.s.a = ___arch__swab32(v.s.b);
52 return w.u;
53}
1da177e4
LT
54
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 */
This page took 0.529673 seconds and 5 git commands to generate.