2005-04-17 06:20:36 +08:00
|
|
|
#ifndef __ASM_SH_BYTEORDER_H
|
|
|
|
#define __ASM_SH_BYTEORDER_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 Niibe Yutaka
|
2007-11-09 12:58:44 +08:00
|
|
|
* Copyright (C) 2000, 2001 Paolo Alberelli
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
#include <linux/compiler.h>
|
2007-11-09 12:58:44 +08:00
|
|
|
#include <linux/types.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-11-09 12:58:44 +08:00
|
|
|
static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-11-09 12:58:44 +08:00
|
|
|
__asm__(
|
2008-03-14 16:21:09 +08:00
|
|
|
#ifdef __SH5__
|
|
|
|
"byterev %0, %0\n\t"
|
|
|
|
"shari %0, 32, %0"
|
|
|
|
#else
|
2007-11-09 12:58:44 +08:00
|
|
|
"swap.b %0, %0\n\t"
|
|
|
|
"swap.w %0, %0\n\t"
|
|
|
|
"swap.b %0, %0"
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
: "=r" (x)
|
|
|
|
: "0" (x));
|
2007-11-09 12:58:44 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-11-09 12:58:44 +08:00
|
|
|
static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-11-09 12:58:44 +08:00
|
|
|
__asm__(
|
2008-03-14 16:21:09 +08:00
|
|
|
#ifdef __SH5__
|
2007-11-09 12:58:44 +08:00
|
|
|
"byterev %0, %0\n\t"
|
|
|
|
"shari %0, 32, %0"
|
2008-03-14 16:21:09 +08:00
|
|
|
#else
|
|
|
|
"swap.b %0, %0"
|
2007-11-09 12:58:44 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
: "=r" (x)
|
|
|
|
: "0" (x));
|
2007-11-09 12:58:44 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-11-09 12:58:44 +08:00
|
|
|
static inline __u64 ___arch__swab64(__u64 val)
|
|
|
|
{
|
|
|
|
union {
|
2005-04-17 06:20:36 +08:00
|
|
|
struct { __u32 a,b; } s;
|
|
|
|
__u64 u;
|
|
|
|
} v, w;
|
|
|
|
v.u = val;
|
2007-11-09 12:58:44 +08:00
|
|
|
w.s.b = ___arch__swab32(v.s.a);
|
|
|
|
w.s.a = ___arch__swab32(v.s.b);
|
|
|
|
return w.u;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define __arch__swab64(x) ___arch__swab64(x)
|
|
|
|
#define __arch__swab32(x) ___arch__swab32(x)
|
|
|
|
#define __arch__swab16(x) ___arch__swab16(x)
|
|
|
|
|
|
|
|
#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
|
|
|
|
# define __BYTEORDER_HAS_U64__
|
|
|
|
# define __SWAB_64_THRU_32__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __LITTLE_ENDIAN__
|
|
|
|
#include <linux/byteorder/little_endian.h>
|
|
|
|
#else
|
|
|
|
#include <linux/byteorder/big_endian.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __ASM_SH_BYTEORDER_H */
|