Home | History | Annotate | Line # | Download | only in string
      1  1.5  uebayasi /*	$NetBSD: memset.S,v 1.5 2014/05/23 03:17:31 uebayasi Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  christos  * by David Laight.
      9  1.1  christos  *
     10  1.1  christos  * Redistribution and use in source and binary forms, with or without
     11  1.1  christos  * modification, are permitted provided that the following conditions
     12  1.1  christos  * are met:
     13  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  christos  *    documentation and/or other materials provided with the distribution.
     18  1.1  christos  *
     19  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  christos  */
     31  1.1  christos 
     32  1.1  christos #include <machine/asm.h>
     33  1.1  christos 
     34  1.1  christos #if defined(LIBC_SCCS)
     35  1.5  uebayasi 	RCSID("$NetBSD: memset.S,v 1.5 2014/05/23 03:17:31 uebayasi Exp $")
     36  1.1  christos #endif
     37  1.1  christos 
     38  1.1  christos #ifdef BZERO
     39  1.1  christos ENTRY(bzero)
     40  1.1  christos #else
     41  1.1  christos ENTRY(memset)
     42  1.1  christos #endif
     43  1.1  christos #ifdef BZERO
     44  1.1  christos 	movl	8(%esp),%ecx
     45  1.1  christos 	xor	%eax,%eax
     46  1.1  christos #else
     47  1.1  christos 	movl	12(%esp),%ecx
     48  1.1  christos 	movzbl	8(%esp),%eax		/* unsigned char, zero extend */
     49  1.1  christos #endif
     50  1.1  christos 	cmpl	$0x0f,%ecx		/* avoid mispredicted branch... */
     51  1.1  christos 
     52  1.1  christos 	pushl	%edi
     53  1.1  christos 	movl	8(%esp),%edi
     54  1.1  christos 
     55  1.1  christos 	/*
     56  1.1  christos 	 * if the string is too short, it's really not worth the overhead
     57  1.1  christos 	 * of aligning to word boundries, etc.  So we jump to a plain
     58  1.1  christos 	 * unaligned set.
     59  1.1  christos 	 *
     60  1.1  christos 	 * NB aligning the transfer is actually pointless on my athlon 700,
     61  1.1  christos 	 * It does make a difference to a PII though.
     62  1.1  christos 	 *
     63  1.1  christos 	 * The PII, PIII and PIV all seem to have a massive performance
     64  1.1  christos 	 * drop when the initial target address is an odd multiple of 4.
     65  1.1  christos 	 */
     66  1.2      yamt 	jbe	.Lby_bytes
     67  1.1  christos 
     68  1.1  christos #ifndef BZERO
     69  1.1  christos 	movb	%al,%ah			/* copy char to all bytes in word */
     70  1.1  christos 	movl	%eax,%edx
     71  1.1  christos 	sall	$16,%eax
     72  1.1  christos 	orl	%edx,%eax
     73  1.1  christos #endif
     74  1.1  christos 
     75  1.1  christos 	movl	%edi,%edx		/* detect misalignment */
     76  1.1  christos 	neg	%edx
     77  1.1  christos 	andl	$7,%edx
     78  1.2      yamt 	jnz	.Lalign
     79  1.2      yamt .Laligned:
     80  1.1  christos 	movl	%eax,-4(%edi,%ecx)	/* zap last 4 bytes */
     81  1.1  christos 	shrl	$2,%ecx			/* zero by words */
     82  1.1  christos 	rep
     83  1.1  christos 	stosl
     84  1.2      yamt .Ldone:
     85  1.1  christos #ifndef BZERO
     86  1.1  christos 	movl	8(%esp),%eax		/* return address of buffer */
     87  1.1  christos #endif
     88  1.1  christos 	pop	%edi
     89  1.1  christos 	ret
     90  1.1  christos 
     91  1.2      yamt .Lalign:
     92  1.1  christos 	movl	%eax,(%edi)		/* zap first 8 bytes */
     93  1.1  christos 	movl	%eax,4(%edi)
     94  1.1  christos 	subl	%edx,%ecx		/* remove from main count */
     95  1.1  christos 	add	%edx,%edi
     96  1.2      yamt 	jmp	.Laligned
     97  1.1  christos 
     98  1.2      yamt .Lby_bytes:
     99  1.1  christos 	rep
    100  1.1  christos 	stosb
    101  1.1  christos 
    102  1.1  christos #ifndef BZERO
    103  1.1  christos 	movl	8(%esp),%eax		/* return address of buffer */
    104  1.1  christos #endif
    105  1.1  christos 	popl	%edi
    106  1.1  christos 	ret
    107  1.5  uebayasi #ifdef BZERO
    108  1.5  uebayasi END(bzero)
    109  1.5  uebayasi #else
    110  1.5  uebayasi END(memset)
    111  1.5  uebayasi #endif
    112