...
Run Format

Text file src/runtime/memmove_plan9_386.s

Documentation: runtime

     1	// Inferno's libkern/memmove-386.s
     2	// https://bitbucket.org/inferno-os/inferno-os/src/default/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	#include "textflag.h"
    27	
    28	// func memmove(to, from unsafe.Pointer, n uintptr)
    29	TEXT runtime·memmove(SB), NOSPLIT, $0-12
    30		MOVL	to+0(FP), DI
    31		MOVL	from+4(FP), SI
    32		MOVL	n+8(FP), BX
    33	
    34		// REP instructions have a high startup cost, so we handle small sizes
    35		// with some straightline code. The REP MOVSL instruction is really fast
    36		// for large sizes. The cutover is approximately 1K.
    37	tail:
    38		TESTL	BX, BX
    39		JEQ	move_0
    40		CMPL	BX, $2
    41		JBE	move_1or2
    42		CMPL	BX, $4
    43		JB	move_3
    44		JE	move_4
    45		CMPL	BX, $8
    46		JBE	move_5through8
    47		CMPL	BX, $16
    48		JBE	move_9through16
    49	
    50	/*
    51	 * check and set for backwards
    52	 */
    53		CMPL	SI, DI
    54		JLS	back
    55	
    56	/*
    57	 * forward copy loop
    58	 */
    59	forward:	
    60		MOVL	BX, CX
    61		SHRL	$2, CX
    62		ANDL	$3, BX
    63	
    64		REP;	MOVSL
    65		JMP	tail
    66	/*
    67	 * check overlap
    68	 */
    69	back:
    70		MOVL	SI, CX
    71		ADDL	BX, CX
    72		CMPL	CX, DI
    73		JLS	forward
    74	/*
    75	 * whole thing backwards has
    76	 * adjusted addresses
    77	 */
    78	
    79		ADDL	BX, DI
    80		ADDL	BX, SI
    81		STD
    82	
    83	/*
    84	 * copy
    85	 */
    86		MOVL	BX, CX
    87		SHRL	$2, CX
    88		ANDL	$3, BX
    89	
    90		SUBL	$4, DI
    91		SUBL	$4, SI
    92		REP;	MOVSL
    93	
    94		CLD
    95		ADDL	$4, DI
    96		ADDL	$4, SI
    97		SUBL	BX, DI
    98		SUBL	BX, SI
    99		JMP	tail
   100	
   101	move_1or2:
   102		MOVB	(SI), AX
   103		MOVB	-1(SI)(BX*1), CX
   104		MOVB	AX, (DI)
   105		MOVB	CX, -1(DI)(BX*1)
   106		RET
   107	move_0:
   108		RET
   109	move_3:
   110		MOVW	(SI), AX
   111		MOVB	2(SI), CX
   112		MOVW	AX, (DI)
   113		MOVB	CX, 2(DI)
   114		RET
   115	move_4:
   116		// We need a separate case for 4 to make sure we write pointers atomically.
   117		MOVL	(SI), AX
   118		MOVL	AX, (DI)
   119		RET
   120	move_5through8:
   121		MOVL	(SI), AX
   122		MOVL	-4(SI)(BX*1), CX
   123		MOVL	AX, (DI)
   124		MOVL	CX, -4(DI)(BX*1)
   125		RET
   126	move_9through16:
   127		MOVL	(SI), AX
   128		MOVL	4(SI), CX
   129		MOVL	-8(SI)(BX*1), DX
   130		MOVL	-4(SI)(BX*1), BP
   131		MOVL	AX, (DI)
   132		MOVL	CX, 4(DI)
   133		MOVL	DX, -8(DI)(BX*1)
   134		MOVL	BP, -4(DI)(BX*1)
   135		RET

View as plain text