00001 /*- 00002 * Copyright (c) 1998 The NetBSD Foundation, Inc. 00003 * All rights reserved. 00004 * 00005 * This code is derived from software contributed to The NetBSD Foundation 00006 * by Charles M. Hannum. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 3. All advertising materials mentioning features or use of this software 00017 * must display the following acknowledgement: 00018 * This product includes software developed by the NetBSD 00019 * Foundation, Inc. and its contributors. 00020 * 4. Neither the name of The NetBSD Foundation nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 00025 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00027 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 00028 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 */ 00036 #ifndef __MACHDEP_BYTE_SWAP_H__ 00037 #define __MACHDEP_BYTE_SWAP_H__ 00038 00039 #if 0 00040 #define __byte_swap_long_variable(x) __extension__ \ 00041 ({ register in_addr_t __x = (x); \ 00042 __asm ("bswap %1" \ 00043 : "=r" (__x) \ 00044 : "0" (__x)); \ 00045 __x; }) 00046 #else 00047 #define __byte_swap_long_variable(x) __extension__ \ 00048 ({ register in_addr_t __x = (x); \ 00049 __asm ("rorw $8, %w1\n\trorl $16, %1\n\trorw $8, %w1" \ 00050 : "=r" (__x) \ 00051 : "0" (__x)); \ 00052 __x; }) 00053 #endif 00054 00055 #define __byte_swap_word_variable(x) __extension__ \ 00056 ({ register in_port_t __x = (x); \ 00057 __asm ("rorw $8, %w1" \ 00058 : "=r" (__x) \ 00059 : "0" (__x)); \ 00060 __x; }) 00061 00062 #define __byte_swap_long_constant(x) \ 00063 ((((x) & 0xff000000) >> 24) | \ 00064 (((x) & 0x00ff0000) >> 8) | \ 00065 (((x) & 0x0000ff00) << 8) | \ 00066 (((x) & 0x000000ff) << 24)) 00067 #define __byte_swap_word_constant(x) \ 00068 ((((x) & 0xff00) >> 8) | \ 00069 (((x) & 0x00ff) << 8)) 00070 #define __byte_swap_long(x) \ 00071 (__builtin_constant_p((x)) ? \ 00072 __byte_swap_long_constant(x) : __byte_swap_long_variable(x)) 00073 #define __byte_swap_word(x) \ 00074 (__builtin_constant_p((x)) ? \ 00075 __byte_swap_word_constant(x) : __byte_swap_word_variable(x)) 00076 00077 #endif