github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/src/runtime/internal/atomic/asm_riscv.s (about) 1 // Copyright 2016 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 // +build riscv 6 7 #include "textflag.h" 8 9 TEXT ·Cas(SB), NOSPLIT, $0-17 10 MOV ptr+0(FP), A0 11 MOVW old+8(FP), A1 12 MOVW new+12(FP), A2 13 cas: 14 WORD $0x140522af // lr.w.aq t0,(a0) 15 BNE T0, A1, fail 16 WORD $0x1cc5252f // sc.w.aq a0,a2,(a0) 17 // a0 = 0 iff the sc succeeded. Convert that to a boolean. 18 SLTIU $1, A0, A0 19 MOV A0, ret+16(FP) 20 RET 21 fail: 22 MOV $0, A0 23 MOV A0, ret+16(FP) 24 RET 25 26 TEXT ·Casp1(SB), NOSPLIT, $0-25 27 MOV ptr+0(FP), A0 28 MOV old+8(FP), A1 29 MOV new+16(FP), A2 30 cas: 31 WORD $0x140532af // lr.d.aq t0,(a0) 32 BNE T0, A1, fail 33 WORD $0x1cc5352f // sc.d.aq a0,a2,(a0) 34 // a0 = 0 iff the sc succeeded. Convert that to a boolean. 35 SLTIU $1, A0, A0 36 MOV A0, ret+24(FP) 37 RET 38 fail: 39 MOV $0, A0 40 MOV A0, ret+24(FP) 41 RET 42 43 TEXT ·Casuintptr(SB),NOSPLIT,$0-25 44 JMP ·Casp1(SB) 45 46 TEXT ·Storeuintptr(SB),NOSPLIT,$0-16 47 MOV ptr+0(FP), A0 48 MOV new+8(FP), A1 49 // Since ptr is aligned, this store is atomic automatically. 50 MOV A1, (A0) 51 RET 52 53 TEXT ·Loaduintptr(SB),NOSPLIT,$0-16 54 MOV ptr+0(FP), A0 55 // Since ptr is aligned, this load is atomic automatically. 56 MOV (A0), A0 57 MOV A0, ret+8(FP) 58 RET 59 60 TEXT ·Loaduint(SB),NOSPLIT,$0-16 61 JMP ·Loaduintptr(SB) 62 63 TEXT ·Loadint64(SB),NOSPLIT,$0-16 64 JMP ·Loaduintptr(SB) 65 66 TEXT ·Xaddint64(SB),NOSPLIT,$0-24 67 MOV ptr+0(FP), A0 68 MOV delta+8(FP), A1 69 WORD $0x04b5352f // amoadd.d.aq a0,a1,(a0) 70 ADD A0, A1, A0 71 MOVW A0, ret+16(FP) 72 RET