1 // Copyright 2011 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 #include "textflag.h" 6 7 TEXT SwapInt32(SB),NOSPLIT,$0-12 8 JMP SwapUint32(SB) 9 10 TEXT SwapUint32(SB),NOSPLIT,$0-12 11 MOVL addr+0(FP), BX 12 MOVL new+4(FP), AX 13 XCHGL AX, 0(BX) 14 MOVL AX, old+8(FP) 15 RET 16 17 TEXT SwapInt64(SB),NOSPLIT,$0-24 18 JMP SwapUint64(SB) 19 20 TEXT SwapUint64(SB),NOSPLIT,$0-24 21 MOVL addr+0(FP), BX 22 TESTL $7, BX 23 JZ 2(PC) 24 MOVL 0, BX // crash with nil ptr deref 25 MOVQ new+8(FP), AX 26 XCHGQ AX, 0(BX) 27 MOVQ AX, old+16(FP) 28 RET 29 30 TEXT SwapUintptr(SB),NOSPLIT,$0-12 31 JMP SwapUint32(SB) 32 33 TEXT CompareAndSwapInt32(SB),NOSPLIT,$0-17 34 JMP CompareAndSwapUint32(SB) 35 36 TEXT CompareAndSwapUint32(SB),NOSPLIT,$0-17 37 MOVL addr+0(FP), BX 38 MOVL old+4(FP), AX 39 MOVL new+8(FP), CX 40 LOCK 41 CMPXCHGL CX, 0(BX) 42 SETEQ swapped+16(FP) 43 RET 44 45 TEXT CompareAndSwapUintptr(SB),NOSPLIT,$0-17 46 JMP CompareAndSwapUint32(SB) 47 48 TEXT CompareAndSwapInt64(SB),NOSPLIT,$0-25 49 JMP CompareAndSwapUint64(SB) 50 51 TEXT CompareAndSwapUint64(SB),NOSPLIT,$0-25 52 MOVL addr+0(FP), BX 53 TESTL $7, BX 54 JZ 2(PC) 55 MOVL 0, BX // crash with nil ptr deref 56 MOVQ old+8(FP), AX 57 MOVQ new+16(FP), CX 58 LOCK 59 CMPXCHGQ CX, 0(BX) 60 SETEQ swapped+24(FP) 61 RET 62 63 TEXT AddInt32(SB),NOSPLIT,$0-12 64 JMP AddUint32(SB) 65 66 TEXT AddUint32(SB),NOSPLIT,$0-12 67 MOVL addr+0(FP), BX 68 MOVL delta+4(FP), AX 69 MOVL AX, CX 70 LOCK 71 XADDL AX, 0(BX) 72 ADDL AX, CX 73 MOVL CX, new+8(FP) 74 RET 75 76 TEXT AddUintptr(SB),NOSPLIT,$0-12 77 JMP AddUint32(SB) 78 79 TEXT AddInt64(SB),NOSPLIT,$0-24 80 JMP AddUint64(SB) 81 82 TEXT AddUint64(SB),NOSPLIT,$0-24 83 MOVL addr+0(FP), BX 84 TESTL $7, BX 85 JZ 2(PC) 86 MOVL 0, BX // crash with nil ptr deref 87 MOVQ delta+8(FP), AX 88 MOVQ AX, CX 89 LOCK 90 XADDQ AX, 0(BX) 91 ADDQ AX, CX 92 MOVQ CX, new+16(FP) 93 RET 94 95 TEXT LoadInt32(SB),NOSPLIT,$0-12 96 JMP LoadUint32(SB) 97 98 TEXT LoadUint32(SB),NOSPLIT,$0-12 99 MOVL addr+0(FP), AX 100 MOVL 0(AX), AX 101 MOVL AX, val+8(FP) 102 RET 103 104 TEXT LoadInt64(SB),NOSPLIT,$0-16 105 JMP LoadUint64(SB) 106 107 TEXT LoadUint64(SB),NOSPLIT,$0-16 108 MOVL addr+0(FP), AX 109 TESTL $7, AX 110 JZ 2(PC) 111 MOVL 0, AX // crash with nil ptr deref 112 MOVQ 0(AX), AX 113 MOVQ AX, val+8(FP) 114 RET 115 116 TEXT LoadUintptr(SB),NOSPLIT,$0-12 117 JMP LoadPointer(SB) 118 119 TEXT LoadPointer(SB),NOSPLIT,$0-12 120 MOVL addr+0(FP), AX 121 MOVL 0(AX), AX 122 MOVL AX, val+8(FP) 123 RET 124 125 TEXT StoreInt32(SB),NOSPLIT,$0-8 126 JMP StoreUint32(SB) 127 128 TEXT StoreUint32(SB),NOSPLIT,$0-8 129 MOVL addr+0(FP), BX 130 MOVL val+4(FP), AX 131 XCHGL AX, 0(BX) 132 RET 133 134 TEXT StoreInt64(SB),NOSPLIT,$0-16 135 JMP StoreUint64(SB) 136 137 TEXT StoreUint64(SB),NOSPLIT,$0-16 138 MOVL addr+0(FP), BX 139 TESTL $7, BX 140 JZ 2(PC) 141 MOVL 0, BX // crash with nil ptr deref 142 MOVQ val+8(FP), AX 143 XCHGQ AX, 0(BX) 144 RET 145 146 TEXT StoreUintptr(SB),NOSPLIT,$0-8 147 JMP StoreUint32(SB) 148