No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hppa / include / byte_swap.h
blob31084d8db66ddc363bdd44f69a76b2bb847bff72
1 /* $NetBSD: byte_swap.h,v 1.7.82.1 2008/10/27 08:02:41 skrll Exp $ */
3 /* $OpenBSD: endian.h,v 1.8 2004/04/07 18:24:19 mickey Exp $ */
5 /*
6 * Copyright (c) 1998-2004 Michael Shalayeff
7 * All rights reserved.
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.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _HPPA_BYTE_SWAP_H_
32 #define _HPPA_BYTE_SWAP_H_
34 #ifdef __GNUC__
35 #include <sys/types.h>
36 __BEGIN_DECLS
39 #define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
40 static __inline uint32_t __byte_swap_u32_variable(uint32_t);
41 static __inline uint32_t
42 __byte_swap_u32_variable(uint32_t x)
44 register uint32_t __swap32md_x; \
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);
55 #if 0
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.
62 #define __swap16md(x) __swap16gen(x)
63 #else
64 #define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
65 static __inline uint16_t __byte_swap_u16_variable(uint16_t);
66 static __inline uint16_t
67 __byte_swap_u16_variable(uint16_t x)
69 register uint16_t __swap16md_x; \
71 __asm ("extru %1,23,8,%0\n\t" \
72 "dep %1,23,8,%0" \
73 : "=&r" (__swap16md_x) : "r" (x)); \
74 return(__swap16md_x);
76 #endif
78 __END_DECLS
79 #endif
81 #endif /* !_HPPA_BYTE_SWAP_H_ */