github.com/primecitizens/pcz/std@v0.2.1/core/bytealg/count_riscv64.s (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  // 
     4  // Copyright 2020 The Go Authors. All rights reserved.
     5  // Use of this source code is governed by a BSD-style
     6  // license that can be found in the LICENSE file.
     7  
     8  //go:build pcz && riscv64
     9  
    10  #include "textflag.h"
    11  
    12  TEXT ·CountSlice<ABIInternal>(SB),NOSPLIT,$0-40
    13  	// X10 = b_base
    14  	// X11 = b_len
    15  	// X12 = b_cap (unused)
    16  	// X13 = byte to count (want in X12)
    17  	AND $0xff, X13, X12
    18  	MOV ZERO, X14 // count
    19  	ADD X10, X11 // end
    20  
    21  loop:
    22  	BEQ X10, X11, done
    23  	MOVBU (X10), X15
    24  	ADD $1, X10
    25  	BNE X12, X15, loop
    26  	ADD $1, X14
    27  	JMP loop
    28  
    29  done:
    30  	MOV X14, X10
    31  	RET
    32  
    33  TEXT ·Count<ABIInternal>(SB),NOSPLIT,$0-32
    34  	// X10 = s_base
    35  	// X11 = s_len
    36  	// X12 = byte to count
    37  	AND $0xff, X12
    38  	MOV ZERO, X14 // count
    39  	ADD X10, X11 // end
    40  
    41  loop:
    42  	BEQ X10, X11, done
    43  	MOVBU (X10), X15
    44  	ADD $1, X10
    45  	BNE X12, X15, loop
    46  	ADD $1, X14
    47  	JMP loop
    48  
    49  done:
    50  	MOV X14, X10
    51  	RET