Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/memmove_riscv64.s

Documentation: runtime

     1  // Copyright 2016 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  // void runtime¬∑memmove(void*, void*, uintptr)
    10  TEXT runtime¬∑memmove(SB),NOSPLIT,$-0-24
    11  	MOV	to+0(FP), T0
    12  	MOV	from+8(FP), T1
    13  	MOV	n+16(FP), T2
    14  	ADD	T1, T2, T5
    15  
    16  	// If the destination is ahead of the source, start at the end of the
    17  	// buffer and go backward.
    18  	BLTU	T1, T0, b
    19  
    20  	// If less than eight bytes, do one byte at a time.
    21  	SLTU	$8, T2, T3
    22  	BNE	T3, ZERO, f_outcheck
    23  
    24  	// Do one byte at a time until from is eight-aligned.
    25  	JMP	f_aligncheck
    26  f_align:
    27  	MOVB	(T1), T3
    28  	MOVB	T3, (T0)
    29  	ADD	$1, T0
    30  	ADD	$1, T1
    31  f_aligncheck:
    32  	AND	$7, T1, T3
    33  	BNE	T3, ZERO, f_align
    34  
    35  	// Do eight bytes at a time as long as there is room.
    36  	ADD	$-7, T5, T6
    37  	JMP	f_wordscheck
    38  f_words:
    39  	MOV	(T1), T3
    40  	MOV	T3, (T0)
    41  	ADD	$8, T0
    42  	ADD	$8, T1
    43  f_wordscheck:
    44  	SLTU	T6, T1, T3
    45  	BNE	T3, ZERO, f_words
    46  
    47  	// Finish off the remaining partial word.
    48  	JMP 	f_outcheck
    49  f_out:
    50  	MOVB	(T1), T3
    51  	MOVB	T3, (T0)
    52  	ADD	$1, T0
    53  	ADD	$1, T1
    54  f_outcheck:
    55  	BNE	T1, T5, f_out
    56  
    57  	RET
    58  
    59  b:
    60  	ADD	T0, T2, T4
    61  	// If less than eight bytes, do one byte at a time.
    62  	SLTU	$8, T2, T3
    63  	BNE	T3, ZERO, b_outcheck
    64  
    65  	// Do one byte at a time until from+n is eight-aligned.
    66  	JMP	b_aligncheck
    67  b_align:
    68  	ADD	$-1, T4
    69  	ADD	$-1, T5
    70  	MOVB	(T5), T3
    71  	MOVB	T3, (T4)
    72  b_aligncheck:
    73  	AND	$7, T5, T3
    74  	BNE	T3, ZERO, b_align
    75  
    76  	// Do eight bytes at a time as long as there is room.
    77  	ADD	$7, T1, T6
    78  	JMP	b_wordscheck
    79  b_words:
    80  	ADD	$-8, T4
    81  	ADD	$-8, T5
    82  	MOV	(T5), T3
    83  	MOV	T3, (T4)
    84  b_wordscheck:
    85  	SLTU	T5, T6, T3
    86  	BNE	T3, ZERO, b_words
    87  
    88  	// Finish off the remaining partial word.
    89  	JMP	b_outcheck
    90  b_out:
    91  	ADD	$-1, T4
    92  	ADD	$-1, T5
    93  	MOVB	(T5), T3
    94  	MOVB	T3, (T4)
    95  b_outcheck:
    96  	BNE	T5, T1, b_out
    97  
    98  	RET
    99  

View as plain text