github.com/primecitizens/pcz/std@v0.2.1/core/gc/wb_wasm.s (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 // 4 // Copyright 2018 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 wasm 9 10 #include "textflag.h" 11 12 // gcWriteBarrier informs the GC about heap pointer writes. 13 // 14 // gcWriteBarrier does NOT follow the Go ABI. It accepts the 15 // number of bytes of buffer needed as a wasm argument 16 // (put on the TOS by the caller, lives in local R0 in this body) 17 // and returns a pointer to the buffer space as a wasm result 18 // (left on the TOS in this body, appears on the wasm stack 19 // in the caller). 20 TEXT gcWriteBarrier<>(SB), NOSPLIT, $0 21 Loop 22 // R3 = g.m 23 MOVD g_m(g), R3 24 // R4 = p 25 MOVD m_p(R3), R4 26 // R5 = wbBuf.next 27 MOVD p_wbBuf+wbBuf_next(R4), R5 28 29 // Increment wbBuf.next 30 Get R5 31 Get R0 32 I64Add 33 Set R5 34 35 // Is the buffer full? 36 Get R5 37 I64Load (p_wbBuf+wbBuf_end)(R4) 38 I64LeU 39 If 40 // Commit to the larger buffer. 41 MOVD R5, p_wbBuf+wbBuf_next(R4) 42 43 // Make return value (the original next position) 44 Get R5 45 Get R0 46 I64Sub 47 48 Return 49 End 50 51 // Flush 52 CALLNORESUME runtime·wbBufFlush(SB) 53 54 // Retry 55 Br $0 56 End 57 58 TEXT runtime·gcWriteBarrier1<ABIInternal>(SB),NOSPLIT,$0 59 I64Const $8 60 Call gcWriteBarrier<>(SB) 61 Return 62 TEXT runtime·gcWriteBarrier2<ABIInternal>(SB),NOSPLIT,$0 63 I64Const $16 64 Call gcWriteBarrier<>(SB) 65 Return 66 TEXT runtime·gcWriteBarrier3<ABIInternal>(SB),NOSPLIT,$0 67 I64Const $24 68 Call gcWriteBarrier<>(SB) 69 Return 70 TEXT runtime·gcWriteBarrier4<ABIInternal>(SB),NOSPLIT,$0 71 I64Const $32 72 Call gcWriteBarrier<>(SB) 73 Return 74 TEXT runtime·gcWriteBarrier5<ABIInternal>(SB),NOSPLIT,$0 75 I64Const $40 76 Call gcWriteBarrier<>(SB) 77 Return 78 TEXT runtime·gcWriteBarrier6<ABIInternal>(SB),NOSPLIT,$0 79 I64Const $48 80 Call gcWriteBarrier<>(SB) 81 Return 82 TEXT runtime·gcWriteBarrier7<ABIInternal>(SB),NOSPLIT,$0 83 I64Const $56 84 Call gcWriteBarrier<>(SB) 85 Return 86 TEXT runtime·gcWriteBarrier8<ABIInternal>(SB),NOSPLIT,$0 87 I64Const $64 88 Call gcWriteBarrier<>(SB) 89 Return