...
Run Format

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

View as plain text