1/*
2 * Copyright 2009 Analog Devices Inc.
3 *
4 * Licensed under the GPL-2 or later.
5 */
6
7#ifndef _UAPI_BLACKFIN_SWAB_H
8#define _UAPI_BLACKFIN_SWAB_H
9
10#include <linux/types.h>
11#include <asm-generic/swab.h>
12
13#ifdef __GNUC__
14
15static __inline__ __attribute_const__ __u32 __arch_swahb32(__u32 xx)
16{
17	__u32 tmp;
18	__asm__("%1 = %0 >> 8 (V);\n\t"
19		"%0 = %0 << 8 (V);\n\t"
20		"%0 = %0 | %1;\n\t"
21		: "+d"(xx), "=&d"(tmp));
22	return xx;
23}
24#define __arch_swahb32 __arch_swahb32
25
26static __inline__ __attribute_const__ __u32 __arch_swahw32(__u32 xx)
27{
28	__u32 rv;
29	__asm__("%0 = PACK(%1.L, %1.H);\n\t": "=d"(rv): "d"(xx));
30	return rv;
31}
32#define __arch_swahw32 __arch_swahw32
33
34static __inline__ __attribute_const__ __u32 __arch_swab32(__u32 xx)
35{
36	return __arch_swahb32(__arch_swahw32(xx));
37}
38#define __arch_swab32 __arch_swab32
39
40static __inline__ __attribute_const__ __u16 __arch_swab16(__u16 xx)
41{
42	__u32 xw = xx;
43	__asm__("%0 <<= 8;\n	%0.L = %0.L + %0.H (NS);\n": "+d"(xw));
44	return (__u16)xw;
45}
46#define __arch_swab16 __arch_swab16
47
48#endif /* __GNUC__ */
49
50#endif /* _UAPI_BLACKFIN_SWAB_H */
51