Text file src/internal/bytealg/equal_riscv64.s

     1  // Copyright 2019 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 "go_asm.h"
     6  #include "textflag.h"
     7  
     8  #define	CTXT	S10
     9  
    10  // func memequal(a, b unsafe.Pointer, size uintptr) bool
    11  TEXT runtime·memequal<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-25
    12  #ifndef GOEXPERIMENT_regabiargs
    13  	MOV	a+0(FP), X10
    14  	MOV	b+8(FP), X11
    15  	MOV	size+16(FP), X12
    16  	MOV	$ret+24(FP), X13
    17  #endif
    18  	// X10 = a_base
    19  	// X11 = b_base
    20  	// X12 = size
    21  	JMP	memequal<>(SB)
    22  
    23  // func memequal_varlen(a, b unsafe.Pointer) bool
    24  TEXT runtime·memequal_varlen<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-17
    25  	MOV	8(CTXT), X12    // compiler stores size at offset 8 in the closure
    26  #ifndef GOEXPERIMENT_regabiargs
    27  	MOV	a+0(FP), X10
    28  	MOV	b+8(FP), X11
    29  	MOV	$ret+16(FP), X13
    30  #endif
    31  	// X10 = a_base
    32  	// X11 = b_base
    33  	JMP	memequal<>(SB)
    34  
    35  // On entry X10 and X11 contain pointers, X12 contains length.
    36  // For non-regabi X13 contains address for return value.
    37  // For regabi return value in X10.
    38  TEXT memequal<>(SB),NOSPLIT|NOFRAME,$0
    39  	BEQ	X10, X11, eq
    40  
    41  	MOV	$32, X23
    42  	BLT	X12, X23, loop4_check
    43  
    44  	// Check alignment - if alignment differs we have to do one byte at a time.
    45  	AND	$3, X10, X9
    46  	AND	$3, X11, X19
    47  	BNE	X9, X19, loop4_check
    48  	BEQZ	X9, loop32_check
    49  
    50  	// Check one byte at a time until we reach 8 byte alignment.
    51  	SUB	X9, X12, X12
    52  align:
    53  	ADD	$-1, X9
    54  	MOVBU	0(X10), X19
    55  	MOVBU	0(X11), X20
    56  	BNE	X19, X20, not_eq
    57  	ADD	$1, X10
    58  	ADD	$1, X11
    59  	BNEZ	X9, align
    60  
    61  loop32_check:
    62  	MOV	$32, X9
    63  	BLT	X12, X9, loop16_check
    64  loop32:
    65  	MOV	0(X10), X19
    66  	MOV	0(X11), X20
    67  	MOV	8(X10), X21
    68  	MOV	8(X11), X22
    69  	BNE	X19, X20, not_eq
    70  	BNE	X21, X22, not_eq
    71  	MOV	16(X10), X14
    72  	MOV	16(X11), X15
    73  	MOV	24(X10), X16
    74  	MOV	24(X11), X17
    75  	BNE	X14, X15, not_eq
    76  	BNE	X16, X17, not_eq
    77  	ADD	$32, X10
    78  	ADD	$32, X11
    79  	ADD	$-32, X12
    80  	BGE	X12, X9, loop32
    81  	BEQZ	X12, eq
    82  
    83  loop16_check:
    84  	MOV	$16, X23
    85  	BLT	X12, X23, loop4_check
    86  loop16:
    87  	MOV	0(X10), X19
    88  	MOV	0(X11), X20
    89  	MOV	8(X10), X21
    90  	MOV	8(X11), X22
    91  	BNE	X19, X20, not_eq
    92  	BNE	X21, X22, not_eq
    93  	ADD	$16, X10
    94  	ADD	$16, X11
    95  	ADD	$-16, X12
    96  	BGE	X12, X23, loop16
    97  	BEQZ	X12, eq
    98  
    99  loop4_check:
   100  	MOV	$4, X23
   101  	BLT	X12, X23, loop1
   102  loop4:
   103  	MOVBU	0(X10), X19
   104  	MOVBU	0(X11), X20
   105  	MOVBU	1(X10), X21
   106  	MOVBU	1(X11), X22
   107  	BNE	X19, X20, not_eq
   108  	BNE	X21, X22, not_eq
   109  	MOVBU	2(X10), X14
   110  	MOVBU	2(X11), X15
   111  	MOVBU	3(X10), X16
   112  	MOVBU	3(X11), X17
   113  	BNE	X14, X15, not_eq
   114  	BNE	X16, X17, not_eq
   115  	ADD	$4, X10
   116  	ADD	$4, X11
   117  	ADD	$-4, X12
   118  	BGE	X12, X23, loop4
   119  
   120  loop1:
   121  	BEQZ	X12, eq
   122  	MOVBU	0(X10), X19
   123  	MOVBU	0(X11), X20
   124  	BNE	X19, X20, not_eq
   125  	ADD	$1, X10
   126  	ADD	$1, X11
   127  	ADD	$-1, X12
   128  	JMP	loop1
   129  
   130  not_eq:
   131  #ifndef GOEXPERIMENT_regabiargs
   132  	MOVB	ZERO, (X13)
   133  #else
   134  	MOVB	ZERO, X10
   135  #endif
   136  	RET
   137  eq:
   138  #ifndef GOEXPERIMENT_regabiargs
   139  	MOV	$1, X10
   140  	MOVB	X10, (X13)
   141  #else
   142  	MOV	$1, X10
   143  #endif
   144  	RET
   145  

View as plain text