github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/runtime/memmove_386.s (about)

     1  // Inferno's libkern/memmove-386.s
     2  // http://code.google.com/p/inferno-os/source/browse/libkern/memmove-386.s
     3  //
     4  //         Copyright © 1994-1999 Lucent Technologies Inc.  All rights reserved.
     5  //         Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com).  All rights reserved.
     6  //         Portions Copyright 2009 The Go Authors. All rights reserved.
     7  //
     8  // Permission is hereby granted, free of charge, to any person obtaining a copy
     9  // of this software and associated documentation files (the "Software"), to deal
    10  // in the Software without restriction, including without limitation the rights
    11  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    12  // copies of the Software, and to permit persons to whom the Software is
    13  // furnished to do so, subject to the following conditions:
    14  //
    15  // The above copyright notice and this permission notice shall be included in
    16  // all copies or substantial portions of the Software.
    17  //
    18  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    19  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    20  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    21  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    22  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    23  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    24  // THE SOFTWARE.
    25  
    26  TEXT runtime·memmove(SB), 7, $0
    27  	MOVL	to+0(FP), DI
    28  	MOVL	fr+4(FP), SI
    29  	MOVL	n+8(FP), BX
    30  /*
    31   * check and set for backwards
    32   */
    33  	CMPL	SI, DI
    34  	JLS	back
    35  
    36  /*
    37   * forward copy loop
    38   */
    39  forward:	
    40  	MOVL	BX, CX
    41  	SHRL	$2, CX
    42  	ANDL	$3, BX
    43  
    44  	REP;	MOVSL
    45  	MOVL	BX, CX
    46  	REP;	MOVSB
    47  
    48  	MOVL	to+0(FP),AX
    49  	RET
    50  /*
    51   * check overlap
    52   */
    53  back:
    54  	MOVL	SI, CX
    55  	ADDL	BX, CX
    56  	CMPL	CX, DI
    57  	JLS	forward
    58  /*
    59   * whole thing backwards has
    60   * adjusted addresses
    61   */
    62  
    63  	ADDL	BX, DI
    64  	ADDL	BX, SI
    65  	STD
    66  
    67  /*
    68   * copy
    69   */
    70  	MOVL	BX, CX
    71  	SHRL	$2, CX
    72  	ANDL	$3, BX
    73  
    74  	SUBL	$4, DI
    75  	SUBL	$4, SI
    76  	REP;	MOVSL
    77  
    78  	ADDL	$3, DI
    79  	ADDL	$3, SI
    80  	MOVL	BX, CX
    81  	REP;	MOVSB
    82  
    83  	CLD
    84  	MOVL	to+0(FP),AX
    85  	RET
    86