1*53166c52Sdholland/* $NetBSD: byte_swap_4.S,v 1.9 2020/12/11 09:02:33 dholland Exp $ */ 237c9f0a6Schristos 337c9f0a6Schristos/*- 437c9f0a6Schristos * Copyright (c) 1997 The NetBSD Foundation, Inc. 537c9f0a6Schristos * All rights reserved. 637c9f0a6Schristos * 737c9f0a6Schristos * This code is derived from software contributed to The NetBSD Foundation 837c9f0a6Schristos * by Neil A. Carson 937c9f0a6Schristos * 1037c9f0a6Schristos * Redistribution and use in source and binary forms, with or without 1137c9f0a6Schristos * modification, are permitted provided that the following conditions 1237c9f0a6Schristos * are met: 1337c9f0a6Schristos * 1. Redistributions of source code must retain the above copyright 1437c9f0a6Schristos * notice, this list of conditions and the following disclaimer. 1537c9f0a6Schristos * 2. Redistributions in binary form must reproduce the above copyright 1637c9f0a6Schristos * notice, this list of conditions and the following disclaimer in the 1737c9f0a6Schristos * documentation and/or other materials provided with the distribution. 1837c9f0a6Schristos * 1937c9f0a6Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2037c9f0a6Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2137c9f0a6Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2237c9f0a6Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2337c9f0a6Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2437c9f0a6Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2537c9f0a6Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2637c9f0a6Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2737c9f0a6Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2837c9f0a6Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2937c9f0a6Schristos * POSSIBILITY OF SUCH DAMAGE. 3037c9f0a6Schristos */ 3137c9f0a6Schristos 3237c9f0a6Schristos#include <machine/asm.h> 3337c9f0a6Schristos 34c61d2c64Suwe#if defined(_KERNEL) || defined(_STANDALONE) 3514ba29f9Smatt#define FUNC _C_LABEL(bswap32) 36c61d2c64Suwe#else 3714ba29f9Smatt#define FUNC _C_LABEL(__bswap32) 38c61d2c64Suwe#endif 3914ba29f9SmattENTRY(FUNC) 40a96852fcSmatt#ifdef _ARM_ARCH_6 41a96852fcSmatt rev r0, r0 4214ba29f9Smatt#elif !defined(__thumb__) 433818c9a2Sdholland eor r1, r0, r0, ror #16 /* d.c.b.a -> db.ca.db.ca */ 443818c9a2Sdholland bic r1, r1, #0x00FF0000 /* db.ca.db.ca -> db.0.db.ca */ 453818c9a2Sdholland mov r0, r0, ror #8 /* d.c.b.a -> a.d.c.b */ 463818c9a2Sdholland eor r0, r0, r1, lsr #8 /* a.d.c.b ^ 0.db.0.db -> a.b.c.d */ 4714ba29f9Smatt#else 4814ba29f9Smatt movs r3, #16 49*53166c52Sdholland lsls r1, r0, #8 /* d.c.b.a -> c.b.a.0 */ 503818c9a2Sdholland lsrs r0, r0, #8 /* d.c.b.a -> 0.d.c.b */ 513818c9a2Sdholland rors r1, r3 /* c.b.a.0 -> a.0.c.b */ 523818c9a2Sdholland rors r0, r3 /* 0.d.c.b -> c.b.0.d */ 533818c9a2Sdholland lsrs r1, r1, #8 /* a.0.c.b -> 0.a.0.c */ 543818c9a2Sdholland lsls r1, r1, #8 /* 0.a.0.c -> a.0.c.0 */ 553818c9a2Sdholland lsls r0, r0, #8 /* c.b.0.d -> b.0.d.0 */ 563818c9a2Sdholland lsrs r0, r0, #8 /* b.0.d.0 -> 0.b.0.d */ 573818c9a2Sdholland orrs r0, r0, r1 /* a.0.c.0 | 0.b.0.d -> a.b.c.d */ 58a96852fcSmatt#endif 5937c9f0a6Schristos RET 6014ba29f9SmattEND(FUNC) 6114ba29f9Smatt 6214ba29f9Smatt#if BYTE_ORDER == LITTLE_ENDIAN 6314ba29f9SmattSTRONG_ALIAS(_C_LABEL(ntohl), FUNC) 6414ba29f9SmattSTRONG_ALIAS(_C_LABEL(htonl), FUNC) 6514ba29f9Smatt#endif 66