1*b6cbf720SGianluca Guida/* $NetBSD: byte_swap_4.S,v 1.3 2008/02/16 17:37:13 apb Exp $ */ 2*b6cbf720SGianluca Guida 3*b6cbf720SGianluca Guida/* 4*b6cbf720SGianluca Guida * Copyright (c) 1996 Carnegie-Mellon University. 5*b6cbf720SGianluca Guida * All rights reserved. 6*b6cbf720SGianluca Guida * 7*b6cbf720SGianluca Guida * Author: Chris G. Demetriou 8*b6cbf720SGianluca Guida * 9*b6cbf720SGianluca Guida * Permission to use, copy, modify and distribute this software and 10*b6cbf720SGianluca Guida * its documentation is hereby granted, provided that both the copyright 11*b6cbf720SGianluca Guida * notice and this permission notice appear in all copies of the 12*b6cbf720SGianluca Guida * software, derivative works or modified versions, and any portions 13*b6cbf720SGianluca Guida * thereof, and that both notices appear in supporting documentation. 14*b6cbf720SGianluca Guida * 15*b6cbf720SGianluca Guida * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16*b6cbf720SGianluca Guida * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17*b6cbf720SGianluca Guida * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18*b6cbf720SGianluca Guida * 19*b6cbf720SGianluca Guida * Carnegie Mellon requests users of this software to return to 20*b6cbf720SGianluca Guida * 21*b6cbf720SGianluca Guida * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22*b6cbf720SGianluca Guida * School of Computer Science 23*b6cbf720SGianluca Guida * Carnegie Mellon University 24*b6cbf720SGianluca Guida * Pittsburgh PA 15213-3890 25*b6cbf720SGianluca Guida * 26*b6cbf720SGianluca Guida * any improvements or extensions that they make and grant Carnegie the 27*b6cbf720SGianluca Guida * rights to redistribute these changes. 28*b6cbf720SGianluca Guida */ 29*b6cbf720SGianluca Guida 30*b6cbf720SGianluca Guida#include <machine/asm.h> 31*b6cbf720SGianluca Guida 32*b6cbf720SGianluca Guida/* 33*b6cbf720SGianluca Guida * Byte-swap a 4-byte quantity. (Convert 0x01234567 to 0x67452301.) 34*b6cbf720SGianluca Guida * 35*b6cbf720SGianluca Guida * Argument is an unsigned 4-byte integer (uint32_t). 36*b6cbf720SGianluca Guida */ 37*b6cbf720SGianluca Guida#if defined(_KERNEL) || defined(_STANDALONE) 38*b6cbf720SGianluca Guida#define BSWAP32 bswap32 39*b6cbf720SGianluca Guida#else /* defined(_KERNEL) || defined(_STANDALONE) */ 40*b6cbf720SGianluca Guida#define BSWAP32 __bswap32 41*b6cbf720SGianluca Guida#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 42*b6cbf720SGianluca GuidaLEAF(BSWAP32, 1) /* a0 contains 0x01234567 */ 43*b6cbf720SGianluca GuidaXLEAF(htonl, 1) 44*b6cbf720SGianluca GuidaXLEAF(ntohl, 1) 45*b6cbf720SGianluca Guida insbl a0, 3, t0 /* t0 = 0x67 */ 46*b6cbf720SGianluca Guida extbl a0, 1, t1 /* t1 = 0x 45 */ 47*b6cbf720SGianluca Guida extbl a0, 2, t2 /* t2 = 0x 23 */ 48*b6cbf720SGianluca Guida extbl a0, 3, t3 /* t3 = 0x 01 */ 49*b6cbf720SGianluca Guida sll t1, 16, t1 /* t1 = 0x 45 */ 50*b6cbf720SGianluca Guida sll t2, 8, t2 /* t2 = 0x 23 */ 51*b6cbf720SGianluca Guida or t3, t0, v0 /* v0 = 0x67 01 */ 52*b6cbf720SGianluca Guida or t1, t2, t1 /* t1 = 0x 4523 */ 53*b6cbf720SGianluca Guida or t1, v0, v0 /* v0 = 0x67452301 */ 54*b6cbf720SGianluca Guida RET 55*b6cbf720SGianluca GuidaEND(BSWAP32) 56