Black Lives Matter. Support the Equal Justice Initiative.

Text file src/runtime/memmove_mipsx.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  //go:build mips || mipsle
     6  // +build mips mipsle
     7  
     8  #include "textflag.h"
     9  
    10  #ifdef GOARCH_mips
    11  #define MOVWHI  MOVWL
    12  #define MOVWLO  MOVWR
    13  #else
    14  #define MOVWHI  MOVWR
    15  #define MOVWLO  MOVWL
    16  #endif
    17  
    18  // See memmove Go doc for important implementation constraints.
    19  
    20  // func memmove(to, from unsafe.Pointer, n uintptr)
    21  TEXT runtime¬∑memmove(SB),NOSPLIT,$-0-12
    22  	MOVW	n+8(FP), R3
    23  	MOVW	from+4(FP), R2
    24  	MOVW	to+0(FP), R1
    25  
    26  	ADDU	R3, R2, R4	// end pointer for source
    27  	ADDU	R3, R1, R5	// end pointer for destination
    28  
    29  	// if destination is ahead of source, start at the end of the buffer and go backward.
    30  	SGTU	R1, R2, R6
    31  	BNE	R6, backward
    32  
    33  	// if less than 4 bytes, use byte by byte copying
    34  	SGTU	$4, R3, R6
    35  	BNE	R6, f_small_copy
    36  
    37  	// align destination to 4 bytes
    38  	AND	$3, R1, R6
    39  	BEQ	R6, f_dest_aligned
    40  	SUBU	R1, R0, R6
    41  	AND	$3, R6
    42  	MOVWHI	0(R2), R7
    43  	SUBU	R6, R3
    44  	MOVWLO	3(R2), R7
    45  	ADDU	R6, R2
    46  	MOVWHI	R7, 0(R1)
    47  	ADDU	R6, R1
    48  
    49  f_dest_aligned:
    50  	AND	$31, R3, R7
    51  	AND	$3, R3, R6
    52  	SUBU	R7, R5, R7	// end pointer for 32-byte chunks
    53  	SUBU	R6, R5, R6	// end pointer for 4-byte chunks
    54  
    55  	// if source is not aligned, use unaligned reads
    56  	AND	$3, R2, R8
    57  	BNE	R8, f_large_ua
    58  
    59  f_large:
    60  	BEQ	R1, R7, f_words
    61  	ADDU	$32, R1
    62  	MOVW	0(R2), R8
    63  	MOVW	4(R2), R9
    64  	MOVW	8(R2), R10
    65  	MOVW	12(R2), R11
    66  	MOVW	16(R2), R12
    67  	MOVW	20(R2), R13
    68  	MOVW	24(R2), R14
    69  	MOVW	28(R2), R15
    70  	ADDU	$32, R2
    71  	MOVW	R8, -32(R1)
    72  	MOVW	R9, -28(R1)
    73  	MOVW	R10, -24(R1)
    74  	MOVW	R11, -20(R1)
    75  	MOVW	R12, -16(R1)
    76  	MOVW	R13, -12(R1)
    77  	MOVW	R14, -8(R1)
    78  	MOVW	R15, -4(R1)
    79  	JMP	f_large
    80  
    81  f_words:
    82  	BEQ	R1, R6, f_tail
    83  	ADDU	$4, R1
    84  	MOVW	0(R2), R8
    85  	ADDU	$4, R2
    86  	MOVW	R8, -4(R1)
    87  	JMP	f_words
    88  
    89  f_tail:
    90  	BEQ	R1, R5, ret
    91  	MOVWLO	-1(R4), R8
    92  	MOVWLO	R8, -1(R5)
    93  
    94  ret:
    95  	RET
    96  
    97  f_large_ua:
    98  	BEQ	R1, R7, f_words_ua
    99  	ADDU	$32, R1
   100  	MOVWHI	0(R2), R8
   101  	MOVWHI	4(R2), R9
   102  	MOVWHI	8(R2), R10
   103  	MOVWHI	12(R2), R11
   104  	MOVWHI	16(R2), R12
   105  	MOVWHI	20(R2), R13
   106  	MOVWHI	24(R2), R14
   107  	MOVWHI	28(R2), R15
   108  	MOVWLO	3(R2), R8
   109  	MOVWLO	7(R2), R9
   110  	MOVWLO	11(R2), R10
   111  	MOVWLO	15(R2), R11
   112  	MOVWLO	19(R2), R12
   113  	MOVWLO	23(R2), R13
   114  	MOVWLO	27(R2), R14
   115  	MOVWLO	31(R2), R15
   116  	ADDU	$32, R2
   117  	MOVW	R8, -32(R1)
   118  	MOVW	R9, -28(R1)
   119  	MOVW	R10, -24(R1)
   120  	MOVW	R11, -20(R1)
   121  	MOVW	R12, -16(R1)
   122  	MOVW	R13, -12(R1)
   123  	MOVW	R14, -8(R1)
   124  	MOVW	R15, -4(R1)
   125  	JMP	f_large_ua
   126  
   127  f_words_ua:
   128  	BEQ	R1, R6, f_tail_ua
   129  	MOVWHI	0(R2), R8
   130  	ADDU	$4, R1
   131  	MOVWLO	3(R2), R8
   132  	ADDU	$4, R2
   133  	MOVW	R8, -4(R1)
   134  	JMP	f_words_ua
   135  
   136  f_tail_ua:
   137  	BEQ	R1, R5, ret
   138  	MOVWHI	-4(R4), R8
   139  	MOVWLO	-1(R4), R8
   140  	MOVWLO	R8, -1(R5)
   141  	JMP	ret
   142  
   143  f_small_copy:
   144  	BEQ	R1, R5, ret
   145  	ADDU	$1, R1
   146  	MOVB	0(R2), R6
   147  	ADDU	$1, R2
   148  	MOVB	R6, -1(R1)
   149  	JMP	f_small_copy
   150  
   151  backward:
   152  	SGTU	$4, R3, R6
   153  	BNE	R6, b_small_copy
   154  
   155  	AND	$3, R5, R6
   156  	BEQ	R6, b_dest_aligned
   157  	MOVWHI	-4(R4), R7
   158  	SUBU	R6, R3
   159  	MOVWLO	-1(R4), R7
   160  	SUBU	R6, R4
   161  	MOVWLO	R7, -1(R5)
   162  	SUBU	R6, R5
   163  
   164  b_dest_aligned:
   165  	AND	$31, R3, R7
   166  	AND	$3, R3, R6
   167  	ADDU	R7, R1, R7
   168  	ADDU	R6, R1, R6
   169  
   170  	AND	$3, R4, R8
   171  	BNE	R8, b_large_ua
   172  
   173  b_large:
   174  	BEQ	R5, R7, b_words
   175  	ADDU	$-32, R5
   176  	MOVW	-4(R4), R8
   177  	MOVW	-8(R4), R9
   178  	MOVW	-12(R4), R10
   179  	MOVW	-16(R4), R11
   180  	MOVW	-20(R4), R12
   181  	MOVW	-24(R4), R13
   182  	MOVW	-28(R4), R14
   183  	MOVW	-32(R4), R15
   184  	ADDU	$-32, R4
   185  	MOVW	R8, 28(R5)
   186  	MOVW	R9, 24(R5)
   187  	MOVW	R10, 20(R5)
   188  	MOVW	R11, 16(R5)
   189  	MOVW	R12, 12(R5)
   190  	MOVW	R13, 8(R5)
   191  	MOVW	R14, 4(R5)
   192  	MOVW	R15, 0(R5)
   193  	JMP	b_large
   194  
   195  b_words:
   196  	BEQ	R5, R6, b_tail
   197  	ADDU	$-4, R5
   198  	MOVW	-4(R4), R8
   199  	ADDU	$-4, R4
   200  	MOVW	R8, 0(R5)
   201  	JMP	b_words
   202  
   203  b_tail:
   204  	BEQ	R5, R1, ret
   205  	MOVWHI	0(R2), R8	// R2 and R1 have the same alignment so we don't need to load a whole word
   206  	MOVWHI	R8, 0(R1)
   207  	JMP	ret
   208  
   209  b_large_ua:
   210  	BEQ	R5, R7, b_words_ua
   211  	ADDU	$-32, R5
   212  	MOVWHI	-4(R4), R8
   213  	MOVWHI	-8(R4), R9
   214  	MOVWHI	-12(R4), R10
   215  	MOVWHI	-16(R4), R11
   216  	MOVWHI	-20(R4), R12
   217  	MOVWHI	-24(R4), R13
   218  	MOVWHI	-28(R4), R14
   219  	MOVWHI	-32(R4), R15
   220  	MOVWLO	-1(R4), R8
   221  	MOVWLO	-5(R4), R9
   222  	MOVWLO	-9(R4), R10
   223  	MOVWLO	-13(R4), R11
   224  	MOVWLO	-17(R4), R12
   225  	MOVWLO	-21(R4), R13
   226  	MOVWLO	-25(R4), R14
   227  	MOVWLO	-29(R4), R15
   228  	ADDU	$-32, R4
   229  	MOVW	R8, 28(R5)
   230  	MOVW	R9, 24(R5)
   231  	MOVW	R10, 20(R5)
   232  	MOVW	R11, 16(R5)
   233  	MOVW	R12, 12(R5)
   234  	MOVW	R13, 8(R5)
   235  	MOVW	R14, 4(R5)
   236  	MOVW	R15, 0(R5)
   237  	JMP	b_large_ua
   238  
   239  b_words_ua:
   240  	BEQ	R5, R6, b_tail_ua
   241  	MOVWHI	-4(R4), R8
   242  	ADDU	$-4, R5
   243  	MOVWLO	-1(R4), R8
   244  	ADDU	$-4, R4
   245  	MOVW	R8, 0(R5)
   246  	JMP	b_words_ua
   247  
   248  b_tail_ua:
   249  	BEQ	R5, R1, ret
   250  	MOVWHI	(R2), R8
   251  	MOVWLO	3(R2), R8
   252  	MOVWHI	R8, 0(R1)
   253  	JMP ret
   254  
   255  b_small_copy:
   256  	BEQ	R5, R1, ret
   257  	ADDU	$-1, R5
   258  	MOVB	-1(R4), R6
   259  	ADDU	$-1, R4
   260  	MOVB	R6, 0(R5)
   261  	JMP	b_small_copy
   262  

View as plain text