1*267197ecSapb/* $NetBSD: byte_swap_4.S,v 1.3 2008/02/16 17:37:13 apb Exp $ */ 237c9f0a6Schristos 337c9f0a6Schristos/* 437c9f0a6Schristos * Copyright (c) 1996 Carnegie-Mellon University. 537c9f0a6Schristos * All rights reserved. 637c9f0a6Schristos * 737c9f0a6Schristos * Author: Chris G. Demetriou 837c9f0a6Schristos * 937c9f0a6Schristos * Permission to use, copy, modify and distribute this software and 1037c9f0a6Schristos * its documentation is hereby granted, provided that both the copyright 1137c9f0a6Schristos * notice and this permission notice appear in all copies of the 1237c9f0a6Schristos * software, derivative works or modified versions, and any portions 1337c9f0a6Schristos * thereof, and that both notices appear in supporting documentation. 1437c9f0a6Schristos * 1537c9f0a6Schristos * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 1637c9f0a6Schristos * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 1737c9f0a6Schristos * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 1837c9f0a6Schristos * 1937c9f0a6Schristos * Carnegie Mellon requests users of this software to return to 2037c9f0a6Schristos * 2137c9f0a6Schristos * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 2237c9f0a6Schristos * School of Computer Science 2337c9f0a6Schristos * Carnegie Mellon University 2437c9f0a6Schristos * Pittsburgh PA 15213-3890 2537c9f0a6Schristos * 2637c9f0a6Schristos * any improvements or extensions that they make and grant Carnegie the 2737c9f0a6Schristos * rights to redistribute these changes. 2837c9f0a6Schristos */ 2937c9f0a6Schristos 3037c9f0a6Schristos#include <machine/asm.h> 3137c9f0a6Schristos 3237c9f0a6Schristos/* 3337c9f0a6Schristos * Byte-swap a 4-byte quantity. (Convert 0x01234567 to 0x67452301.) 3437c9f0a6Schristos * 35*267197ecSapb * Argument is an unsigned 4-byte integer (uint32_t). 3637c9f0a6Schristos */ 37987ddf0aSyamt#if defined(_KERNEL) || defined(_STANDALONE) 38987ddf0aSyamt#define BSWAP32 bswap32 39987ddf0aSyamt#else /* defined(_KERNEL) || defined(_STANDALONE) */ 40987ddf0aSyamt#define BSWAP32 __bswap32 41987ddf0aSyamt#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 42987ddf0aSyamtLEAF(BSWAP32, 1) /* a0 contains 0x01234567 */ 4337c9f0a6SchristosXLEAF(htonl, 1) 4437c9f0a6SchristosXLEAF(ntohl, 1) 4537c9f0a6Schristos insbl a0, 3, t0 /* t0 = 0x67 */ 4637c9f0a6Schristos extbl a0, 1, t1 /* t1 = 0x 45 */ 4737c9f0a6Schristos extbl a0, 2, t2 /* t2 = 0x 23 */ 4837c9f0a6Schristos extbl a0, 3, t3 /* t3 = 0x 01 */ 4937c9f0a6Schristos sll t1, 16, t1 /* t1 = 0x 45 */ 5037c9f0a6Schristos sll t2, 8, t2 /* t2 = 0x 23 */ 5137c9f0a6Schristos or t3, t0, v0 /* v0 = 0x67 01 */ 5237c9f0a6Schristos or t1, t2, t1 /* t1 = 0x 4523 */ 5337c9f0a6Schristos or t1, v0, v0 /* v0 = 0x67452301 */ 5437c9f0a6Schristos RET 55987ddf0aSyamtEND(BSWAP32) 56