summaryrefslogtreecommitdiff
path: root/sys/arch/sh/include/endian.h
blob: 32cb0513aed63e22bb86f744b1d076a8f8d4d414 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*	$OpenBSD: endian.h,v 1.8 2019/02/17 15:44:26 deraadt Exp $	*/
/*	$NetBSD: endian.h,v 1.4 2000/03/17 00:09:25 mycroft Exp $	*/

/* Written by Manuel Bouyer. Public domain */

#ifndef _SH_ENDIAN_H_
#define	_SH_ENDIAN_H_

#ifndef __FROM_SYS__ENDIAN
#include <sys/_types.h>
#endif

static __inline __uint16_t
__swap16md(__uint16_t _x)
{
	__uint16_t _rv;

	__asm volatile ("swap.b %1,%0" : "=r"(_rv) : "r"(_x));

	 return (_rv);
}

static __inline __uint32_t
__swap32md(__uint32_t _x)
{
	__uint32_t _rv;

	__asm volatile ("swap.b %1,%0; swap.w %0,%0; swap.b %0,%0"
			  : "=r"(_rv) : "r"(_x));

	return (_rv);
}

static __inline __uint64_t
__swap64md(__uint64_t _x)
{
	__uint64_t _rv;

	_rv = (__uint64_t)__swap32md((__uint32_t)(_x >> 32)) |
	    (__uint64_t)__swap32md((__uint32_t)_x) << 32;

	return (_rv);
}

/* Tell sys/endian.h we have MD variants of the swap macros.  */
#define __HAVE_MD_SWAP

#ifdef __LITTLE_ENDIAN__
#define	_BYTE_ORDER _LITTLE_ENDIAN
#else
#define	_BYTE_ORDER _BIG_ENDIAN
#endif
#define	__STRICT_ALIGNMENT

#ifndef __FROM_SYS__ENDIAN
#include <sys/endian.h>
#endif

#endif /* !_SH_ENDIAN_H_ */