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

View as plain text