byte_swap.h revision 1.6
11.6Sperry/*	$NetBSD: byte_swap.h,v 1.6 2005/12/24 23:24:00 perry Exp $	*/
21.1Sleo
31.1Sleo/*-
41.1Sleo * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Sleo * All rights reserved.
61.1Sleo *
71.1Sleo * This code is derived from software contributed to The NetBSD Foundation
81.1Sleo * by Leo Weppelman.
91.1Sleo *
101.1Sleo * Redistribution and use in source and binary forms, with or without
111.1Sleo * modification, are permitted provided that the following conditions
121.1Sleo * are met:
131.1Sleo * 1. Redistributions of source code must retain the above copyright
141.1Sleo *    notice, this list of conditions and the following disclaimer.
151.1Sleo * 2. Redistributions in binary form must reproduce the above copyright
161.1Sleo *    notice, this list of conditions and the following disclaimer in the
171.1Sleo *    documentation and/or other materials provided with the distribution.
181.1Sleo * 3. All advertising materials mentioning features or use of this software
191.1Sleo *    must display the following acknowledgement:
201.1Sleo *        This product includes software developed by the NetBSD
211.1Sleo *        Foundation, Inc. and its contributors.
221.1Sleo * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sleo *    contributors may be used to endorse or promote products derived
241.1Sleo *    from this software without specific prior written permission.
251.1Sleo *
261.1Sleo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sleo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sleo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sleo * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sleo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sleo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sleo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sleo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sleo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sleo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sleo * POSSIBILITY OF SUCH DAMAGE.
371.1Sleo */
381.1Sleo
391.1Sleo#ifndef	M68K_BYTE_SWAP_H_
401.1Sleo#define	M68K_BYTE_SWAP_H_
411.1Sleo
421.5Sperrystatic inline u_int16_t __byte_swap_word(u_int16_t);
431.5Sperrystatic inline u_int32_t __byte_swap_long(u_int32_t);
441.1Sleo
451.5Sperrystatic inline u_int16_t
461.4Slukem__byte_swap_word(u_int16_t var)
471.4Slukem{
481.6Sperry	__asm volatile ("rorw #8, %0" : "=d" (var) : "0" (var));
491.4Slukem	return (var);
501.4Slukem}
511.4Slukem
521.5Sperrystatic inline u_int32_t
531.4Slukem__byte_swap_long(u_int32_t var)
541.4Slukem{
551.6Sperry	__asm volatile (
561.4Slukem		"rorw #8, %0; swap %0; rorw #8, %0" : "=d" (var) : "0" (var));
571.4Slukem	return (var);
581.4Slukem}
591.1Sleo
601.1Sleo#endif /* !M68K_BYTE_SWAP_H_ */
61