Home | History | Annotate | Download | only in atomic
      1 // Copyright 2015 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 mips64 mips64le
      6 
      7 #include "textflag.h"
      8 
      9 #define LL(base, rt)	WORD	$((060<<26)|((base)<<21)|((rt)<<16))
     10 #define LLV(base, rt)	WORD	$((064<<26)|((base)<<21)|((rt)<<16))
     11 #define SC(base, rt)	WORD	$((070<<26)|((base)<<21)|((rt)<<16))
     12 #define SCV(base, rt)	WORD	$((074<<26)|((base)<<21)|((rt)<<16))
     13 #define SYNC	WORD $0xf
     14 
     15 TEXT SwapInt32(SB),NOSPLIT,$0-20
     16 	JMP	SwapUint32(SB)
     17 
     18 TEXT SwapUint32(SB),NOSPLIT,$0-20
     19 	MOVV	addr+0(FP), R2
     20 	MOVW	new+8(FP), R5
     21 	SYNC
     22 	MOVV	R5, R3
     23 	LL(2, 1)	// R1 = *R2
     24 	SC(2, 3)	// *R2 = R3
     25 	BEQ	R3, -3(PC)
     26 	MOVW	R1, old+16(FP)
     27 	SYNC
     28 	RET
     29 
     30 TEXT SwapInt64(SB),NOSPLIT,$0-24
     31 	JMP	SwapUint64(SB)
     32 
     33 TEXT SwapUint64(SB),NOSPLIT,$0-24
     34 	MOVV	addr+0(FP), R2
     35 	MOVV	new+8(FP), R5
     36 	SYNC
     37 	MOVV	R5, R3
     38 	LLV(2, 1)	// R1 = *R2
     39 	SCV(2, 3)	// *R2 = R3
     40 	BEQ	R3, -3(PC)
     41 	MOVV	R1, old+16(FP)
     42 	SYNC
     43 	RET
     44 
     45 TEXT SwapUintptr(SB),NOSPLIT,$0-24
     46 	JMP	SwapUint64(SB)
     47 
     48 TEXT CompareAndSwapInt32(SB),NOSPLIT,$0-17
     49 	JMP	CompareAndSwapUint32(SB)
     50 
     51 TEXT CompareAndSwapUint32(SB),NOSPLIT,$0-17
     52 	MOVV	addr+0(FP), R1
     53 	MOVW	old+8(FP), R2
     54 	MOVW	new+12(FP), R5
     55 	SYNC
     56 cas_again:
     57 	MOVV	R5, R3
     58 	LL(1, 4)	// R4 = *R1
     59 	BNE	R2, R4, cas_fail
     60 	SC(1, 3)	// *R1 = R3
     61 	BEQ	R3, cas_again
     62 	MOVV	$1, R1
     63 	MOVB	R1, swapped+16(FP)
     64 	SYNC
     65 	RET
     66 cas_fail:
     67 	MOVV	$0, R1
     68 	JMP	-4(PC)
     69 
     70 TEXT CompareAndSwapUintptr(SB),NOSPLIT,$0-25
     71 	JMP	CompareAndSwapUint64(SB)
     72 
     73 TEXT CompareAndSwapInt64(SB),NOSPLIT,$0-25
     74 	JMP	CompareAndSwapUint64(SB)
     75 
     76 TEXT CompareAndSwapUint64(SB),NOSPLIT,$0-25
     77 	MOVV	addr+0(FP), R1
     78 	MOVV	old+8(FP), R2
     79 	MOVV	new+16(FP), R5
     80 	SYNC
     81 cas64_again:
     82 	MOVV	R5, R3
     83 	LLV(1, 4)	// R4 = *R1
     84 	BNE	R2, R4, cas64_fail
     85 	SCV(1, 3)	// *R1 = R3
     86 	BEQ	R3, cas64_again
     87 	MOVV	$1, R1
     88 	MOVB	R1, swapped+24(FP)
     89 	SYNC
     90 	RET
     91 cas64_fail:
     92 	MOVV	$0, R1
     93 	JMP	-4(PC)
     94 
     95 TEXT AddInt32(SB),NOSPLIT,$0-20
     96 	JMP	AddUint32(SB)
     97 
     98 TEXT AddUint32(SB),NOSPLIT,$0-20
     99 	MOVV	addr+0(FP), R2
    100 	MOVW	delta+8(FP), R3
    101 	SYNC
    102 	LL(2, 1)	// R1 = *R2
    103 	ADDU	R1, R3, R4
    104 	MOVV	R4, R1
    105 	SC(2, 4)	// *R2 = R4
    106 	BEQ	R4, -4(PC)
    107 	MOVW	R1, new+16(FP)
    108 	SYNC
    109 	RET
    110 
    111 TEXT AddUintptr(SB),NOSPLIT,$0-24
    112 	JMP	AddUint64(SB)
    113 
    114 TEXT AddInt64(SB),NOSPLIT,$0-24
    115 	JMP	AddUint64(SB)
    116 
    117 TEXT AddUint64(SB),NOSPLIT,$0-24
    118 	MOVV	addr+0(FP), R2
    119 	MOVV	delta+8(FP), R3
    120 	SYNC
    121 	LLV(2, 1)	// R1 = *R2
    122 	ADDVU	R1, R3, R4
    123 	MOVV	R4, R1
    124 	SCV(2, 4)	// *R2 = R4
    125 	BEQ	R4, -4(PC)
    126 	MOVV	R1, new+16(FP)
    127 	SYNC
    128 	RET
    129 
    130 TEXT LoadInt32(SB),NOSPLIT,$0-12
    131 	JMP	LoadUint32(SB)
    132 
    133 TEXT LoadUint32(SB),NOSPLIT,$0-12
    134 	MOVV	addr+0(FP), R1
    135 	SYNC
    136 	MOVWU	0(R1), R1
    137 	SYNC
    138 	MOVW	R1, val+8(FP)
    139 	RET
    140 
    141 TEXT LoadInt64(SB),NOSPLIT,$0-16
    142 	JMP	LoadUint64(SB)
    143 
    144 TEXT LoadUint64(SB),NOSPLIT,$0-16
    145 	MOVV	addr+0(FP), R1
    146 	SYNC
    147 	MOVV	0(R1), R1
    148 	SYNC
    149 	MOVV	R1, val+8(FP)
    150 	RET
    151 
    152 TEXT LoadUintptr(SB),NOSPLIT,$0-16
    153 	JMP	LoadPointer(SB)
    154 
    155 TEXT LoadPointer(SB),NOSPLIT,$0-16
    156 	JMP	LoadUint64(SB)
    157 
    158 TEXT StoreInt32(SB),NOSPLIT,$0-12
    159 	JMP	StoreUint32(SB)
    160 
    161 TEXT StoreUint32(SB),NOSPLIT,$0-12
    162 	MOVV	addr+0(FP), R1
    163 	MOVW	val+8(FP), R2
    164 	SYNC
    165 	MOVW	R2, 0(R1)
    166 	SYNC
    167 	RET
    168 
    169 TEXT StoreInt64(SB),NOSPLIT,$0-16
    170 	JMP	StoreUint64(SB)
    171 
    172 TEXT StoreUint64(SB),NOSPLIT,$0-16
    173 	MOVV	addr+0(FP), R1
    174 	MOVV	val+8(FP), R2
    175 	SYNC
    176 	MOVV	R2, 0(R1)
    177 	SYNC
    178 	RET
    179 
    180 TEXT StoreUintptr(SB),NOSPLIT,$0-16
    181 	JMP	StoreUint64(SB)
    182