[BACK]Return to byte_swap_8.S CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / common / lib / libc / arch / mips / gen

File: [cvs.NetBSD.org] / src / common / lib / libc / arch / mips / gen / byte_swap_8.S (download)

Revision 1.2, Mon Dec 14 00:39:00 2009 UTC (12 years, 6 months ago) by matt
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, yamt-nfs-mp-base9, yamt-nfs-mp-base11, yamt-nfs-mp-base10, tls-maxphys-base, tls-maxphys-20171202, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, rmind-uvmplock-base, rmind-smpnet-nbase, rmind-smpnet-base, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, localcount-20160914, khorben-n900, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, cherry-xenmp-base, cherry-xenmp, bouyer-xenpvh-base2, bouyer-xenpvh-base1, bouyer-xenpvh-base, bouyer-xenpvh, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, ad-namecache-base3, ad-namecache-base, ad-namecache, HEAD
Branch point for: phil-wifi
Changes since 1.1: +118 -0 lines

Merge from matt-nb5-mips64

/*	$NetBSD: byte_swap_8.S,v 1.2 2009/12/14 00:39:00 matt Exp $	*/

/*-
 * Copyright (c) 1991, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * Ralph Campbell.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <mips/asm.h>

#if defined(LIBC_SCCS) && !defined(lint)
	RCSID("$NetBSD: byte_swap_8.S,v 1.2 2009/12/14 00:39:00 matt Exp $")
#endif /* LIBC_SCCS and not lint */

#undef _LOCORE
#define _LOCORE		/* XXX not really, just assembly-code source */
#include <machine/endian.h>

NLEAF(bswap64)	# a0 = 0xffeeddccbbaa9988 return 0x8899aabbccddeeff
#if (__mips == 32 || __mips == 64) && __mips_isa_rev == 2
#if !defined(__mips_o32)
	/*
	 * If we are on MIPS32r2 or MIPS64r2 use the new instructions.
	 */
	dsbh	v0, a0			# dwords swap bytes within halfwords
	dshd	v0, v0			# dwords swap halwords within dwords
	j	ra
#else /* defined(__mips_o32) */
	/*
	 * If we are on MIPS32r2 or MIPS64r2 use the new instructions.
	 * (except we must use the 32bit versions) 
	 */
	wsbh	v1, a0			# word swap bytes within halfwords
	wsbh	v0, a1			# word swap bytes within halfwords
	rotr	v1, v1, 16		# rotate word 16bits and swap word
	rotr	v0, v0, 16		# rotate word 16bits and swap word
	j	ra
#endif /* defined(__mips_o32) */
#elif !defined(__mips_o32)
					# a0  = 0xffeeddccbbaa9988
	li	t0, 0xffff		# t0  = 0x000000000000ffff
	dsll	t1, t0, 32		# t1  = 0x0000ffff00000000
	or	t0, t1			# t0  = 0x0000ffff0000ffff
	dsll	t2, t0, 8		# t2  = 0x00ffff0000ffff00
	xor	t2, t0			# t2  = 0x00ff00ff00ff00ff
	/*
	 * We could swap by halfword, but that would be one instruction longer.
	 */
	dsrl	ta0, a0, 32		# ta0 = 0x00000000ffeeddcc
	dsll	ta1, a0, 32		# ta1 = 0xbbaa998800000000
	or	a1, ta0, ta1		# a1  = 0xbbaa9988ffeeddcc
					# words swapped
	and	ta0, a1, t0		# ta0 = 0x000099880000ddcc
	dsrl	ta1, a1, 16		# ta1 = 0x0000bbaa9988ffee
	and	ta1, t0			# ta1 = 0x0000bbaa0000ffee
	dsll	a2, ta0, 16		# a2  = 0x99880000ddcc0000
	or	a2, ta1			# a2  = 0x9988bbaaddccffee
					# halfwords swapped
	and	ta0, a2, t2		# ta0 = 0x008800aa00cc00ee
	dsrl	ta1, a2, 8		# ta1 = 0x009988bbaaddccff
	and	ta1, t2			# ta1 = 0x009900bb00dd00ff
	dsll	v0, ta0, 8		# v0  = 0x8800aa00cc00ee00
	or	v0, ta1			# v0  = 0x8899aabbccddeeff
					# bytes swapped
	j	ra
#else /* defined(__mips_o32) */
	/*
	 * 32bit ABI.
	 */
					# a0  = 0xccddeeff
					# a1  = 0x8899aabb
	srl	t0, a0, 24		# t0  = 0x000000cc
	srl	t1, a1, 24		# t1  = 0x00000088
	sll	ta0, a0, 24		# ta0 = 0xff000000
	sll	ta1, a1, 24		# ta1 = 0xbb000000
	or	ta0, ta0, t0		# ta0 = 0xff0000cc
	or	ta1, ta1, t1		# ta1 = 0xbb000088
	and	t0, a0, 0xff00		# t0  = 0x0000ee00
	and	t1, a1, 0xff00		# t1  = 0x0000aa00
	sll	t0, t0, 8		# t0  = 0x00ee0000
	sll	t1, t1, 8		# t1  = 0x00aa0000
	or	ta0, ta0, t0		# ta0 = 0xffee00cc
	or	ta1, ta1, t1		# ta1 = 0xbbaa0088
	srl	t0, a0, 8		# t0  = 0x00ccddee
	srl	t1, a1, 8		# t1  = 0x008899aa
	and	t0, t0, 0xff00		# t0  = 0x0000dd00
	and	t1, t1, 0xff00		# t1  = 0x00009900
	or	v1, ta0, t0		# v1  = 0xffeeddcc
	or	v0, ta1, t1		# v0  = 0xbbaa9988
	j	ra
#endif /* defined(__mips_o32) */
END(bswap64)