2005-04-17 00:20:36 +02:00
|
|
|
#ifndef __ASM_SH_BYTEORDER_H
|
|
|
|
#define __ASM_SH_BYTEORDER_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 Niibe Yutaka
|
2007-11-09 05:58:44 +01:00
|
|
|
* Copyright (C) 2000, 2001 Paolo Alberelli
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
#include <linux/compiler.h>
|
2007-11-09 05:58:44 +01:00
|
|
|
#include <linux/types.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-11-09 05:58:44 +01:00
|
|
|
static inline __attribute_const__ __u32 ___arch__swab32(__u32 x)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-11-09 05:58:44 +01:00
|
|
|
__asm__(
|
|
|
|
#ifdef CONFIG_SUPERH32
|
|
|
|
"swap.b %0, %0\n\t"
|
|
|
|
"swap.w %0, %0\n\t"
|
|
|
|
"swap.b %0, %0"
|
|
|
|
#else
|
|
|
|
"byterev %0, %0\n\t"
|
|
|
|
"shari %0, 32, %0"
|
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r" (x)
|
|
|
|
: "0" (x));
|
2007-11-09 05:58:44 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-11-09 05:58:44 +01:00
|
|
|
static inline __attribute_const__ __u16 ___arch__swab16(__u16 x)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-11-09 05:58:44 +01:00
|
|
|
__asm__(
|
|
|
|
#ifdef CONFIG_SUPERH32
|
|
|
|
"swap.b %0, %0"
|
|
|
|
#else
|
|
|
|
"byterev %0, %0\n\t"
|
|
|
|
"shari %0, 32, %0"
|
|
|
|
|
|
|
|
#endif
|
2005-04-17 00:20:36 +02:00
|
|
|
: "=r" (x)
|
|
|
|
: "0" (x));
|
2007-11-09 05:58:44 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-11-09 05:58:44 +01:00
|
|
|
static inline __u64 ___arch__swab64(__u64 val)
|
|
|
|
{
|
|
|
|
union {
|
2005-04-17 00:20:36 +02:00
|
|
|
struct { __u32 a,b; } s;
|
|
|
|
__u64 u;
|
|
|
|
} v, w;
|
|
|
|
v.u = val;
|
2007-11-09 05:58:44 +01:00
|
|
|
w.s.b = ___arch__swab32(v.s.a);
|
|
|
|
w.s.a = ___arch__swab32(v.s.b);
|
|
|
|
return w.u;
|
|
|
|
}
|
2005-04-17 00:20:36 +02: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 */
|