swab.c revision 138659
190792Sgshapiro/* 2261363Sgshapiro * Copyright (c) 1988, 1993 390792Sgshapiro * The Regents of the University of California. All rights reserved. 490792Sgshapiro * 590792Sgshapiro * This code is derived from software contributed to Berkeley by 690792Sgshapiro * Jeffrey Mogul. 790792Sgshapiro * 890792Sgshapiro * Redistribution and use in source and binary forms, with or without 990792Sgshapiro * modification, are permitted provided that the following conditions 1090792Sgshapiro * are met: 1190792Sgshapiro * 1. Redistributions of source code must retain the above copyright 1290792Sgshapiro * notice, this list of conditions and the following disclaimer. 1390792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright 1490792Sgshapiro * notice, this list of conditions and the following disclaimer in the 1590792Sgshapiro * documentation and/or other materials provided with the distribution. 16266692Sgshapiro * 3. All advertising materials mentioning features or use of this software 1790792Sgshapiro * must display the following acknowledgement: 1890792Sgshapiro * This product includes software developed by the University of 1990792Sgshapiro * California, Berkeley and its contributors. 2090792Sgshapiro * 4. Neither the name of the University nor the names of its contributors 2190792Sgshapiro * may be used to endorse or promote products derived from this software 2290792Sgshapiro * without specific prior written permission. 2390792Sgshapiro * 2490792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2590792Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2690792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2790792Sgshapiro * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2890792Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2990792Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3090792Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3190792Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3290792Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3390792Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3490792Sgshapiro * SUCH DAMAGE. 3590792Sgshapiro */ 3690792Sgshapiro 3790792Sgshapiro#if defined(LIBC_SCCS) && !defined(lint) 3890792Sgshapirostatic char sccsid[] = "@(#)swab.c 8.1 (Berkeley) 6/4/93"; 3990792Sgshapiro#endif /* LIBC_SCCS and not lint */ 4090792Sgshapiro#include <sys/cdefs.h> 4190792Sgshapiro__FBSDID("$FreeBSD: head/lib/libc/string/swab.c 138659 2004-12-10 15:24:40Z trhodes $"); 4290792Sgshapiro 4390792Sgshapiro#include <unistd.h> 4490792Sgshapiro 4590792Sgshapirovoid 4690792Sgshapiroswab(const void * __restrict from, void * __restrict to, ssize_t len) 4790792Sgshapiro{ 4890792Sgshapiro unsigned long temp; 4990792Sgshapiro int n; 5090792Sgshapiro char *fp, *tp; 5190792Sgshapiro 5290792Sgshapiro n = len >> 1; 5390792Sgshapiro fp = (char *)from; 5490792Sgshapiro tp = (char *)to; 5590792Sgshapiro#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp 5690792Sgshapiro /* round to multiple of 8 */ 5790792Sgshapiro for (; n & 0x7; --n) 5890792Sgshapiro STEP; 5990792Sgshapiro for (n >>= 3; n > 0; --n) { 6090792Sgshapiro STEP; STEP; STEP; STEP; 6190792Sgshapiro STEP; STEP; STEP; STEP; 6290792Sgshapiro } 6390792Sgshapiro} 6490792Sgshapiro