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