github.com/primecitizens/pcz/std@v0.2.1/core/mem/move_mips64x.s (about)

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