xref: /openbsd-src/sys/arch/hppa/include/endian.h (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: endian.h,v 1.7 2001/06/29 20:28:54 mickey Exp $	*/
2 
3 /*
4  * Copyright (c) 1998-2001 Michael Shalayeff
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Michael Shalayeff.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _MACHINE_ENDIAN_H_
34 #define	_MACHINE_ENDIAN_H_
35 
36 #ifdef __GNUC__
37 
38 #define __swap64md(x) ({					\
39 	u_int64_t __swap64md_x = (x);				\
40 								\
41 	(u_int64_t)__swap32md(__swap64md_x >> 32) |		\
42 	(u_int64_t)__swap32md(__swap64md_x & 0xffffffff) << 32;	\
43 })
44 
45 #define	__swap32md(x) ({			\
46 	register u_int32_t __swap32md_x;	\
47 						\
48 	__asm  ("extru	%1, 7,8,%%r19\n\t"	\
49 		"shd	%1,%1,8,%0\n\t"		\
50 		"dep	%0,15,8,%0\n\t"		\
51 		"dep	%%r19,31,8,%0"		\
52 		: "=&r" (__swap32md_x)		\
53 		: "r" (x) : "r19");		\
54 	__swap32md_x;				\
55 })
56 
57 #if 1
58 /*
59  * Use generic C version because w/ asm inline below
60  * gcc inserts extra "extru r,31,16,r" to convert
61  * to 16 bit entity, which produces overhead we don't need.
62  * Besides, gcc does swap16 same way by itself.
63  */
64 #define	__swap16md(x)	__swap16gen(x)
65 #else
66 #define	__swap16md(x) ({						\
67 	register u_int16_t __swap16md_x;				\
68 									\
69 	__asm  ("extru	%1,23,8,%0\n\t"					\
70 		"dep	%1,23,8,%0"					\
71 	       : "=&r" (__swap16md_x) : "r" (x));			\
72 	__swap16md_x;							\
73 })
74 #endif
75 
76 #define __swap64md(x) ({						\
77 	u_int64_t __swap64md_x = (x);					\
78 									\
79 	(u_int64_t)__swap32md(__swap64md_x >> 32) |			\
80 	    (u_int64_t)__swap32md(__swap64md_x & 0xffffffff) << 32;	\
81 })
82 
83 /* Tell sys/endian.h we have MD variants of the swap macros.  */
84 #define MD_SWAP
85 
86 #endif /* __GNUC__ */
87 
88 
89 #define	BYTE_ORDER	BIG_ENDIAN
90 #include <sys/endian.h>
91 
92 #define	__STRICT_ALIGNMENT
93 
94 #endif /* !_MACHINE_ENDIAN_H_ */
95