/*1* Copyright (c) 1993,94 Winning Strategies, Inc.2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. All advertising materials mentioning features or use of this software13* must display the following acknowledgement:14* This product includes software developed by Winning Strategies, Inc.15* 4. The name of the author may not be used to endorse or promote products16* derived from this software without specific prior written permission17*18* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR19* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES20* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.21* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,22* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT23* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF27* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28*/2930#include <machine/asm.h>31/*32* void33* swab (const void *src, void *dst, size_t len)34* copy len bytes from src to dst, swapping adjacent bytes35*36* On the i486, this code is negligibly faster than the code generated37* by gcc at about half the size. If my i386 databook is correct, it38* should be considerably faster than the gcc code on an i386.39*40* Written by:41* J.T. Conklin ([email protected]), Winning Strategies, Inc.42*/4344ENTRY(swab)45pushl %esi46pushl %edi47movl 12(%esp),%esi48movl 16(%esp),%edi49movl 20(%esp),%ecx5051cld # set direction forward5253shrl $1,%ecx54testl $7,%ecx # copy first group of 1 to 7 words55jz L2 # while swaping alternate bytes.56.align 2,0x9057L1: lodsw58rorw $8,%ax59stosw60decl %ecx61testl $7,%ecx62jnz L16364L2: shrl $3,%ecx # copy remainder 8 words at a time65jz L4 # while swapping alternate bytes.66.align 2,0x9067L3: lodsw68rorw $8,%ax69stosw70lodsw71rorw $8,%ax72stosw73lodsw74rorw $8,%ax75stosw76lodsw77rorw $8,%ax78stosw79lodsw80rorw $8,%ax81stosw82lodsw83rorw $8,%ax84stosw85lodsw86rorw $8,%ax87stosw88lodsw89rorw $8,%ax90stosw91decl %ecx92jnz L39394L4: popl %edi95popl %esi96ret97END(swab)9899.section .note.GNU-stack,"",%progbits100101102