11.6Sriastrad/*	$NetBSD: bswap32.S,v 1.6 2014/03/18 18:20:35 riastradh Exp $	*/
21.1Schristos
31.1Schristos/*
41.1Schristos * Copyright (C) 1996 Scott Reynolds.  All rights reserved.
51.1Schristos *
61.1Schristos * Redistribution and use in source and binary forms, with or without
71.1Schristos * modification, are permitted provided that the following conditions
81.1Schristos * are met:
91.1Schristos * 1. Redistributions of source code must retain the above copyright
101.1Schristos *    notice, this list of conditions and the following disclaimer.
111.1Schristos * 2. Redistributions in binary form must reproduce the above copyright
121.1Schristos *    notice, this list of conditions and the following disclaimer in the
131.1Schristos *    documentation and/or other materials provided with the distribution.
141.1Schristos * 3. The name of the author may not be used to endorse or promote products
151.1Schristos *    derived from this software without specific prior written permission
161.1Schristos *
171.1Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
181.1Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
191.1Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
201.1Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
211.1Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
221.1Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231.1Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241.1Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251.1Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
261.1Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271.1Schristos */
281.1Schristos
291.1Schristos#include <machine/asm.h>
301.1Schristos
311.2She#if defined(_KERNEL) || defined(_STANDALONE)
321.4Smatt#define BSWAP32 _C_LABEL(bswap32)
331.2She#else /* defined(_KERNEL) || defined(_STANDALONE) */
341.4Smatt#define BSWAP32 _C_LABEL(__bswap32)
351.2She#endif /* defined(_KERNEL) || defined(_STANDALONE) */
361.4Smatt
371.4Smatt_ENTRY(BSWAP32)
381.3Smatt	movl	4(%sp),%d0
391.5Smatt#ifdef __mcfisac__
401.5Smatt	byterev	%d0
411.5Smatt#elif defined(__mcoldfire__)
421.5Smatt	movl	%d0,%d1
431.5Smatt	lsrl	#8,%d0		| ABCD -> 0ABC
441.5Smatt	andl	#0x00ff00ff,%d0	| 0ABC -> 0A0C
451.5Smatt	andl	#0x00ff00ff,%d1	| ABCD -> 0B0D
461.5Smatt	lsll	#8,%d1		| 0B0D -> B0D0
471.5Smatt	orl	%d1,%d0		| 0A0C | B0D0 -> BADC
481.5Smatt	swap	%d0		| BADC -> DCBA
491.5Smatt#else
501.5Smatt 	rolw	#8,%d0
511.5Smatt 	swap	%d0
521.1Schristos	rolw	#8,%d0
531.5Smatt#endif
541.1Schristos	rts
551.4SmattEND(BSWAP32)
56