...

Text file src/runtime/memmove_loong64.s

Documentation: runtime

     1// Copyright 2022 The Go Authors. All rights reserved.
     2// Use of this source code is governed by a BSD-style
     3// license that can be found in the LICENSE file.
     4
     5#include "textflag.h"
     6
     7// See memmove Go doc for important implementation constraints.
     8
     9// func memmove(to, from unsafe.Pointer, n uintptr)
    10TEXT runtime·memmove<ABIInternal>(SB), NOSPLIT|NOFRAME, $0-24
    11#ifndef GOEXPERIMENT_regabiargs
    12	MOVV	to+0(FP), R4
    13	MOVV	from+8(FP), R5
    14	MOVV	n+16(FP), R6
    15#endif
    16	BNE	R6, check
    17	RET
    18
    19check:
    20	SGTU	R4, R5, R7
    21	BNE	R7, backward
    22
    23	ADDV	R4, R6, R9 // end pointer
    24
    25	// if the two pointers are not of same alignments, do byte copying
    26	SUBVU	R5, R4, R7
    27	AND	$7, R7
    28	BNE	R7, out
    29
    30	// if less than 8 bytes, do byte copying
    31	SGTU	$8, R6, R7
    32	BNE	R7, out
    33
    34	// do one byte at a time until 8-aligned
    35	AND	$7, R4, R8
    36	BEQ	R8, words
    37	MOVB	(R5), R7
    38	ADDV	$1, R5
    39	MOVB	R7, (R4)
    40	ADDV	$1, R4
    41	JMP	-6(PC)
    42
    43words:
    44	// do 8 bytes at a time if there is room
    45	ADDV	$-7, R9, R6 // R6 is end pointer-7
    46
    47	PCALIGN	$16
    48	SGTU	R6, R4, R8
    49	BEQ	R8, out
    50	MOVV	(R5), R7
    51	ADDV	$8, R5
    52	MOVV	R7, (R4)
    53	ADDV	$8, R4
    54	JMP	-6(PC)
    55
    56out:
    57	BEQ	R4, R9, done
    58	MOVB	(R5), R7
    59	ADDV	$1, R5
    60	MOVB	R7, (R4)
    61	ADDV	$1, R4
    62	JMP	-5(PC)
    63done:
    64	RET
    65
    66backward:
    67	ADDV	R6, R5 // from-end pointer
    68	ADDV	R4, R6, R9 // to-end pointer
    69
    70	// if the two pointers are not of same alignments, do byte copying
    71	SUBVU	R9, R5, R7
    72	AND	$7, R7
    73	BNE	R7, out1
    74
    75	// if less than 8 bytes, do byte copying
    76	SGTU	$8, R6, R7
    77	BNE	R7, out1
    78
    79	// do one byte at a time until 8-aligned
    80	AND	$7, R9, R8
    81	BEQ	R8, words1
    82	ADDV	$-1, R5
    83	MOVB	(R5), R7
    84	ADDV	$-1, R9
    85	MOVB	R7, (R9)
    86	JMP	-6(PC)
    87
    88words1:
    89	// do 8 bytes at a time if there is room
    90	ADDV	$7, R4, R6 // R6 is start pointer+7
    91
    92	PCALIGN	$16
    93	SGTU	R9, R6, R8
    94	BEQ	R8, out1
    95	ADDV	$-8, R5
    96	MOVV	(R5), R7
    97	ADDV	$-8, R9
    98	MOVV	R7, (R9)
    99	JMP	-6(PC)
   100
   101out1:
   102	BEQ	R4, R9, done1
   103	ADDV	$-1, R5
   104	MOVB	(R5), R7
   105	ADDV	$-1, R9
   106	MOVB	R7, (R9)
   107	JMP	-5(PC)
   108done1:
   109	RET

View as plain text