11.3Sapb/* $NetBSD: byte_swap_2.S,v 1.3 2008/02/16 17:37:13 apb Exp $ */
21.1Schristos
31.1Schristos/*
41.1Schristos * Copyright (c) 1996 Carnegie-Mellon University.
51.1Schristos * All rights reserved.
61.1Schristos *
71.1Schristos * Author: Chris G. Demetriou
81.1Schristos *
91.1Schristos * Permission to use, copy, modify and distribute this software and
101.1Schristos * its documentation is hereby granted, provided that both the copyright
111.1Schristos * notice and this permission notice appear in all copies of the
121.1Schristos * software, derivative works or modified versions, and any portions
131.1Schristos * thereof, and that both notices appear in supporting documentation.
141.1Schristos *
151.1Schristos * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
161.1Schristos * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
171.1Schristos * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
181.1Schristos *
191.1Schristos * Carnegie Mellon requests users of this software to return to
201.1Schristos *
211.1Schristos *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
221.1Schristos *  School of Computer Science
231.1Schristos *  Carnegie Mellon University
241.1Schristos *  Pittsburgh PA 15213-3890
251.1Schristos *
261.1Schristos * any improvements or extensions that they make and grant Carnegie the
271.1Schristos * rights to redistribute these changes.
281.1Schristos */
291.1Schristos
301.1Schristos#include <machine/asm.h>
311.1Schristos
321.1Schristos/*
331.1Schristos * Byte-swap a 2-byte quantity.  (Convert 0x0123 to 0x2301.)
341.1Schristos *
351.3Sapb * Argument is an unsigned 2-byte integer (uint16_t).
361.1Schristos */
371.2Syamt#if defined(_KERNEL) || defined(_STANDALONE)
381.2Syamt#define	BSWAP16	bswap16
391.2Syamt#else /* defined(_KERNEL) || defined(_STANDALONE) */
401.2Syamt#define	BSWAP16	__bswap16
411.2Syamt#endif /* defined(_KERNEL) || defined(_STANDALONE) */
421.2SyamtLEAF(BSWAP16, 1)		/* a0 contains 0x0123 */
431.1SchristosXLEAF(htons, 1)
441.1SchristosXLEAF(ntohs, 1)
451.1Schristos	insbl	a0, 1, t0	/* t0 = 0x23   */
461.1Schristos	extbl	a0, 1, t1	/* t1 = 0x  01 */
471.1Schristos	or	t0, t1, v0	/* v0 = 0x2301 */
481.1Schristos	RET
491.2SyamtEND(BSWAP16)
50