github.com/primecitizens/pcz/std@v0.2.1/core/mem/clear_mipsx.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 && (mips || mipsle)
     9  
    10  #include "textflag.h"
    11  
    12  #ifdef GOARCH_mips
    13  #define MOVWHI  MOVWL
    14  #define MOVWLO  MOVWR
    15  #else
    16  #define MOVWHI  MOVWR
    17  #define MOVWLO  MOVWL
    18  #endif
    19  
    20  // See memclrNoHeapPointers Go doc for important implementation constraints.
    21  
    22  // func Clear(ptr unsafe.Pointer, n uintptr)
    23  TEXT ·Clear(SB),NOSPLIT,$0-8
    24  	MOVW n+4(FP), R2
    25  	MOVW ptr+0(FP), R1
    26  
    27  	SGTU $4, R2, R3
    28  	ADDU R2, R1, R4
    29  	BNE R3, small_zero
    30  
    31  ptr_align:
    32  	AND $3, R1, R3
    33  	BEQ R3, setup
    34  	SUBU R1, R0, R3
    35  	AND $3, R3 // R3 contains number of bytes needed to align ptr
    36  	MOVWHI R0, 0(R1)	// MOVWHI will write zeros up to next word boundary
    37  	SUBU R3, R2
    38  	ADDU R3, R1
    39  
    40  setup:
    41  	AND $31, R2, R6
    42  	AND $3, R2, R5
    43  	SUBU R6, R4, R6 // end pointer for 32-byte chunks
    44  	SUBU R5, R4, R5 // end pointer for 4-byte chunks
    45  
    46  large:
    47  	BEQ R1, R6, words
    48  	MOVW R0, 0(R1)
    49  	MOVW R0, 4(R1)
    50  	MOVW R0, 8(R1)
    51  	MOVW R0, 12(R1)
    52  	MOVW R0, 16(R1)
    53  	MOVW R0, 20(R1)
    54  	MOVW R0, 24(R1)
    55  	MOVW R0, 28(R1)
    56  	ADDU $32, R1
    57  	JMP large
    58  
    59  words:
    60  	BEQ R1, R5, tail
    61  	MOVW R0, 0(R1)
    62  	ADDU $4, R1
    63  	JMP words
    64  
    65  tail:
    66  	BEQ R1, R4, ret
    67  	MOVWLO R0, -1(R4)
    68  
    69  ret:
    70  	RET
    71  
    72  small_zero:
    73  	BEQ R1, R4, ret
    74  	MOVB R0, 0(R1)
    75  	ADDU $1, R1
    76  	JMP small_zero