Home | History | Annotate | Download | only in runtime
      1 // Copyright 2015 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 mips64 mips64le
      6 
      7 #include "textflag.h"
      8 
      9 // void runtimememmove(void*, void*, uintptr)
     10 TEXT runtimememmove(SB), NOSPLIT, $-8-24
     11 	MOVV	to+0(FP), R1
     12 	MOVV	from+8(FP), R2
     13 	MOVV	n+16(FP), R3
     14 	BNE	R3, check
     15 	RET
     16 
     17 check:
     18 	SGTU	R1, R2, R4
     19 	BNE	R4, backward
     20 
     21 	ADDV	R1, R3, R6 // end pointer
     22 
     23 	// if the two pointers are not of same alignments, do byte copying
     24 	SUBVU	R2, R1, R4
     25 	AND	$7, R4
     26 	BNE	R4, out
     27 
     28 	// if less than 8 bytes, do byte copying
     29 	SGTU	$8, R3, R4
     30 	BNE	R4, out
     31 
     32 	// do one byte at a time until 8-aligned
     33 	AND	$7, R1, R5
     34 	BEQ	R5, words
     35 	MOVB	(R2), R4
     36 	ADDV	$1, R2
     37 	MOVB	R4, (R1)
     38 	ADDV	$1, R1
     39 	JMP	-6(PC)
     40 
     41 words:
     42 	// do 8 bytes at a time if there is room
     43 	ADDV	$-7, R6, R3 // R3 is end pointer-7
     44 
     45 	SGTU	R3, R1, R5
     46 	BEQ	R5, out
     47 	MOVV	(R2), R4
     48 	ADDV	$8, R2
     49 	MOVV	R4, (R1)
     50 	ADDV	$8, R1
     51 	JMP	-6(PC)
     52 
     53 out:
     54 	BEQ	R1, R6, done
     55 	MOVB	(R2), R4
     56 	ADDV	$1, R2
     57 	MOVB	R4, (R1)
     58 	ADDV	$1, R1
     59 	JMP	-5(PC)
     60 done:
     61 	RET
     62 
     63 backward:
     64 	ADDV	R3, R2 // from-end pointer
     65 	ADDV	R1, R3, R6 // to-end pointer
     66 
     67 	// if the two pointers are not of same alignments, do byte copying
     68 	SUBVU	R6, R2, R4
     69 	AND	$7, R4
     70 	BNE	R4, out1
     71 
     72 	// if less than 8 bytes, do byte copying
     73 	SGTU	$8, R3, R4
     74 	BNE	R4, out1
     75 
     76 	// do one byte at a time until 8-aligned
     77 	AND	$7, R6, R5
     78 	BEQ	R5, words1
     79 	ADDV	$-1, R2
     80 	MOVB	(R2), R4
     81 	ADDV	$-1, R6
     82 	MOVB	R4, (R6)
     83 	JMP	-6(PC)
     84 
     85 words1:
     86 	// do 8 bytes at a time if there is room
     87 	ADDV	$7, R1, R3 // R3 is start pointer+7
     88 
     89 	SGTU	R6, R3, R5
     90 	BEQ	R5, out1
     91 	ADDV	$-8, R2
     92 	MOVV	(R2), R4
     93 	ADDV	$-8, R6
     94 	MOVV	R4, (R6)
     95 	JMP	-6(PC)
     96 
     97 out1:
     98 	BEQ	R1, R6, done1
     99 	ADDV	$-1, R2
    100 	MOVB	(R2), R4
    101 	ADDV	$-1, R6
    102 	MOVB	R4, (R6)
    103 	JMP	-5(PC)
    104 done1:
    105 	RET
    106