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