github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/bytealg/equal_s390x.s (about)

     1  // Copyright 2018 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  TEXT ·Equal(SB),NOSPLIT|NOFRAME,$0-49
     9  	MOVD	a_len+8(FP), R2
    10  	MOVD	b_len+32(FP), R6
    11  	MOVD	a_base+0(FP), R3
    12  	MOVD	b_base+24(FP), R5
    13  	LA	ret+48(FP), R7
    14  	CMPBNE	R2, R6, notequal
    15  	BR	memeqbody<>(SB)
    16  notequal:
    17  	MOVB	$0, ret+48(FP)
    18  	RET
    19  
    20  // memequal(a, b unsafe.Pointer, size uintptr) bool
    21  TEXT runtime·memequal(SB),NOSPLIT|NOFRAME,$0-25
    22  	MOVD	a+0(FP), R3
    23  	MOVD	b+8(FP), R5
    24  	MOVD	size+16(FP), R6
    25  	LA	ret+24(FP), R7
    26  	BR	memeqbody<>(SB)
    27  
    28  // memequal_varlen(a, b unsafe.Pointer) bool
    29  TEXT runtime·memequal_varlen(SB),NOSPLIT|NOFRAME,$0-17
    30  	MOVD	a+0(FP), R3
    31  	MOVD	b+8(FP), R5
    32  	MOVD	8(R12), R6    // compiler stores size at offset 8 in the closure
    33  	LA	ret+16(FP), R7
    34  	BR	memeqbody<>(SB)
    35  
    36  // input:
    37  //   R3 = a
    38  //   R5 = b
    39  //   R6 = len
    40  //   R7 = address of output byte (stores 0 or 1 here)
    41  //   a and b have the same length
    42  TEXT memeqbody<>(SB),NOSPLIT|NOFRAME,$0-0
    43  	CMPBEQ	R3, R5, equal
    44  loop:
    45  	CMPBEQ	R6, $0, equal
    46  	CMPBLT	R6, $32, tiny
    47  	CMP	R6, $256
    48  	BLT	tail
    49  	CLC	$256, 0(R3), 0(R5)
    50  	BNE	notequal
    51  	SUB	$256, R6
    52  	LA	256(R3), R3
    53  	LA	256(R5), R5
    54  	BR	loop
    55  tail:
    56  	SUB	$1, R6, R8
    57  	EXRL	$memeqbodyclc<>(SB), R8
    58  	BEQ	equal
    59  notequal:
    60  	MOVB	$0, 0(R7)
    61  	RET
    62  equal:
    63  	MOVB	$1, 0(R7)
    64  	RET
    65  tiny:
    66  	MOVD	$0, R2
    67  	CMPBLT	R6, $16, lt16
    68  	MOVD	0(R3), R8
    69  	MOVD	0(R5), R9
    70  	CMPBNE	R8, R9, notequal
    71  	MOVD	8(R3), R8
    72  	MOVD	8(R5), R9
    73  	CMPBNE	R8, R9, notequal
    74  	LA	16(R2), R2
    75  	SUB	$16, R6
    76  lt16:
    77  	CMPBLT	R6, $8, lt8
    78  	MOVD	0(R3)(R2*1), R8
    79  	MOVD	0(R5)(R2*1), R9
    80  	CMPBNE	R8, R9, notequal
    81  	LA	8(R2), R2
    82  	SUB	$8, R6
    83  lt8:
    84  	CMPBLT	R6, $4, lt4
    85  	MOVWZ	0(R3)(R2*1), R8
    86  	MOVWZ	0(R5)(R2*1), R9
    87  	CMPBNE	R8, R9, notequal
    88  	LA	4(R2), R2
    89  	SUB	$4, R6
    90  lt4:
    91  #define CHECK(n) \
    92  	CMPBEQ	R6, $n, equal \
    93  	MOVB	n(R3)(R2*1), R8 \
    94  	MOVB	n(R5)(R2*1), R9 \
    95  	CMPBNE	R8, R9, notequal
    96  	CHECK(0)
    97  	CHECK(1)
    98  	CHECK(2)
    99  	CHECK(3)
   100  	BR	equal
   101  
   102  TEXT memeqbodyclc<>(SB),NOSPLIT|NOFRAME,$0-0
   103  	CLC	$1, 0(R3), 0(R5)
   104  	RET