github.com/primecitizens/pcz/std@v0.2.1/core/mem/clear_riscv64.s (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright 2023 The Prime Citizens
     3  //
     4  // Copyright 2016 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  // See memclrNoHeapPointers Go doc for important implementation constraints.
    13  
    14  // void runtime·Clear(void*, uintptr)
    15  TEXT ·Clear<ABIInternal>(SB),NOSPLIT,$0-16
    16  	// X10 = ptr
    17  	// X11 = n
    18  
    19  	// If less than 8 bytes, do single byte zeroing.
    20  	MOV $8, X9
    21  	BLT X11, X9, check4
    22  
    23  	// Check alignment
    24  	AND $3, X10, X5
    25  	BEQZ X5, aligned
    26  
    27  	// Zero one byte at a time until we reach 8 byte alignment.
    28  	SUB X5, X11, X11
    29  align:
    30  	ADD $-1, X5
    31  	MOVB ZERO, 0(X10)
    32  	ADD $1, X10
    33  	BNEZ X5, align
    34  
    35  aligned:
    36  	MOV $8, X9
    37  	BLT X11, X9, check4
    38  	MOV $16, X9
    39  	BLT X11, X9, zero8
    40  	MOV $32, X9
    41  	BLT X11, X9, zero16
    42  	MOV $64, X9
    43  	BLT X11, X9, zero32
    44  loop64:
    45  	MOV ZERO, 0(X10)
    46  	MOV ZERO, 8(X10)
    47  	MOV ZERO, 16(X10)
    48  	MOV ZERO, 24(X10)
    49  	MOV ZERO, 32(X10)
    50  	MOV ZERO, 40(X10)
    51  	MOV ZERO, 48(X10)
    52  	MOV ZERO, 56(X10)
    53  	ADD $64, X10
    54  	ADD $-64, X11
    55  	BGE X11, X9, loop64
    56  	BEQZ X11, done
    57  
    58  check32:
    59  	MOV $32, X9
    60  	BLT X11, X9, check16
    61  zero32:
    62  	MOV ZERO, 0(X10)
    63  	MOV ZERO, 8(X10)
    64  	MOV ZERO, 16(X10)
    65  	MOV ZERO, 24(X10)
    66  	ADD $32, X10
    67  	ADD $-32, X11
    68  	BEQZ X11, done
    69  
    70  check16:
    71  	MOV $16, X9
    72  	BLT X11, X9, check8
    73  zero16:
    74  	MOV ZERO, 0(X10)
    75  	MOV ZERO, 8(X10)
    76  	ADD $16, X10
    77  	ADD $-16, X11
    78  	BEQZ X11, done
    79  
    80  check8:
    81  	MOV $8, X9
    82  	BLT X11, X9, check4
    83  zero8:
    84  	MOV ZERO, 0(X10)
    85  	ADD $8, X10
    86  	ADD $-8, X11
    87  	BEQZ X11, done
    88  
    89  check4:
    90  	MOV $4, X9
    91  	BLT X11, X9, loop1
    92  zero4:
    93  	MOVB ZERO, 0(X10)
    94  	MOVB ZERO, 1(X10)
    95  	MOVB ZERO, 2(X10)
    96  	MOVB ZERO, 3(X10)
    97  	ADD $4, X10
    98  	ADD $-4, X11
    99  
   100  loop1:
   101  	BEQZ X11, done
   102  	MOVB ZERO, 0(X10)
   103  	ADD $1, X10
   104  	ADD $-1, X11
   105  	JMP loop1
   106  
   107  done:
   108  	RET