15780Sdg/*
25780Sdg * Copyright (c) 1993,94 Winning Strategies, Inc.
35780Sdg * All rights reserved.
45780Sdg *
55780Sdg * Redistribution and use in source and binary forms, with or without
65780Sdg * modification, are permitted provided that the following conditions
75780Sdg * are met:
85780Sdg * 1. Redistributions of source code must retain the above copyright
95780Sdg *    notice, this list of conditions and the following disclaimer.
105780Sdg * 2. Redistributions in binary form must reproduce the above copyright
115780Sdg *    notice, this list of conditions and the following disclaimer in the
125780Sdg *    documentation and/or other materials provided with the distribution.
135780Sdg * 3. All advertising materials mentioning features or use of this software
145780Sdg *    must display the following acknowledgement:
155780Sdg *      This product includes software developed by Winning Strategies, Inc.
165780Sdg * 4. The name of the author may not be used to endorse or promote products
175780Sdg *    derived from this software without specific prior written permission
185780Sdg *
195780Sdg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
205780Sdg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
215780Sdg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
225780Sdg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
235780Sdg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
245780Sdg * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255780Sdg * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265780Sdg * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275780Sdg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
285780Sdg * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295780Sdg */
305780Sdg
3185437Speter#include <machine/asm.h>
3293000Sobrien__FBSDID("$FreeBSD: releng/10.2/lib/libc/i386/string/swab.S 217106 2011-01-07 16:08:40Z kib $");
335780Sdg
345780Sdg/*
355780Sdg * void
365780Sdg * swab (const void *src, void *dst, size_t len)
375780Sdg *	copy len bytes from src to dst, swapping adjacent bytes
385780Sdg *
395780Sdg * On the i486, this code is negligibly faster than the code generated
405780Sdg * by gcc at about half the size.  If my i386 databook is correct, it
41108533Sschweikh * should be considerably faster than the gcc code on an i386.
425780Sdg *
435780Sdg * Written by:
445780Sdg *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
455780Sdg */
465780Sdg
475780SdgENTRY(swab)
485780Sdg	pushl	%esi
495780Sdg	pushl	%edi
505780Sdg	movl	12(%esp),%esi
515780Sdg	movl	16(%esp),%edi
525780Sdg	movl	20(%esp),%ecx
535780Sdg
545780Sdg	cld				# set direction forward
555780Sdg
565780Sdg	shrl	$1,%ecx
575780Sdg	testl	$7,%ecx			# copy first group of 1 to 7 words
585780Sdg	jz	L2			# while swaping alternate bytes.
595780Sdg	.align	2,0x90
605780SdgL1:	lodsw
615780Sdg	rorw	$8,%ax
625780Sdg	stosw
635780Sdg	decl	%ecx
645780Sdg	testl	$7,%ecx
655780Sdg	jnz	L1
665780Sdg
675780SdgL2:	shrl	$3,%ecx			# copy remainder 8 words at a time
685780Sdg	jz	L4			# while swapping alternate bytes.
695780Sdg	.align	2,0x90
705780SdgL3:	lodsw
715780Sdg	rorw	$8,%ax
725780Sdg	stosw
735780Sdg	lodsw
745780Sdg	rorw	$8,%ax
755780Sdg	stosw
765780Sdg	lodsw
775780Sdg	rorw	$8,%ax
785780Sdg	stosw
795780Sdg	lodsw
805780Sdg	rorw	$8,%ax
815780Sdg	stosw
825780Sdg	lodsw
835780Sdg	rorw	$8,%ax
845780Sdg	stosw
855780Sdg	lodsw
865780Sdg	rorw	$8,%ax
875780Sdg	stosw
885780Sdg	lodsw
895780Sdg	rorw	$8,%ax
905780Sdg	stosw
915780Sdg	lodsw
925780Sdg	rorw	$8,%ax
935780Sdg	stosw
945780Sdg	decl	%ecx
955780Sdg	jnz	L3
965780Sdg
975780SdgL4:	popl	%edi
985780Sdg	popl	%esi
995780Sdg	ret
100184548SpeterEND(swab)
101217106Skib
102217106Skib	.section .note.GNU-stack,"",%progbits
103