1
0
mirror of https://github.com/golang/go synced 2024-11-18 06:14:46 -07:00

runtime/internal/atomic: added mips64 support.

Change-Id: I2eaf0658771a0ff788429e2f503d116531166315
Reviewed-on: https://go-review.googlesource.com/16834
Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
Yao Zhang 2015-11-11 23:05:06 -05:00 committed by Minux Ma
parent 424738e43e
commit b2b8559987
5 changed files with 341 additions and 0 deletions

View File

@ -0,0 +1,9 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package atomic
const (
_CacheLineSize = 32
)

View File

@ -0,0 +1,9 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package atomic
const (
_CacheLineSize = 32
)

View File

@ -0,0 +1,231 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build mips64 mips64le
#include "textflag.h"
#define LL(base, rt) WORD $((060<<26)|((base)<<21)|((rt)<<16))
#define LLV(base, rt) WORD $((064<<26)|((base)<<21)|((rt)<<16))
#define SC(base, rt) WORD $((070<<26)|((base)<<21)|((rt)<<16))
#define SCV(base, rt) WORD $((074<<26)|((base)<<21)|((rt)<<16))
#define SYNC WORD $0xf
// bool cas(uint32 *ptr, uint32 old, uint32 new)
// Atomically:
// if(*val == old){
// *val = new;
// return 1;
// } else
// return 0;
TEXT ·Cas(SB), NOSPLIT, $0-17
MOVV ptr+0(FP), R1
MOVW old+8(FP), R2
MOVW new+12(FP), R5
SYNC
cas_again:
MOVV R5, R3
LL(1, 4) // R4 = *R1
BNE R2, R4, cas_fail
SC(1, 3) // *R1 = R3
BEQ R3, cas_again
MOVV $1, R1
MOVB R1, ret+16(FP)
SYNC
RET
cas_fail:
MOVV $0, R1
JMP -4(PC)
// bool cas64(uint64 *ptr, uint64 old, uint64 new)
// Atomically:
// if(*val == *old){
// *val = new;
// return 1;
// } else {
// return 0;
// }
TEXT ·Cas64(SB), NOSPLIT, $0-25
MOVV ptr+0(FP), R1
MOVV old+8(FP), R2
MOVV new+16(FP), R5
SYNC
cas64_again:
MOVV R5, R3
LLV(1, 4) // R4 = *R1
BNE R2, R4, cas64_fail
SCV(1, 3) // *R1 = R3
BEQ R3, cas64_again
MOVV $1, R1
MOVB R1, ret+24(FP)
SYNC
RET
cas64_fail:
MOVV $0, R1
JMP -4(PC)
TEXT ·Casuintptr(SB), NOSPLIT, $0-25
JMP ·Cas64(SB)
TEXT ·Loaduintptr(SB), NOSPLIT|NOFRAME, $0-16
JMP ·Load64(SB)
TEXT ·Loaduint(SB), NOSPLIT|NOFRAME, $0-16
JMP ·Load64(SB)
TEXT ·Storeuintptr(SB), NOSPLIT, $0-16
JMP ·Store64(SB)
TEXT ·Xadduintptr(SB), NOSPLIT, $0-24
JMP ·Xadd64(SB)
TEXT ·Loadint64(SB), NOSPLIT, $0-16
JMP ·Load64(SB)
TEXT ·Xaddint64(SB), NOSPLIT, $0-16
JMP ·Xadd64(SB)
// bool casp(void **val, void *old, void *new)
// Atomically:
// if(*val == old){
// *val = new;
// return 1;
// } else
// return 0;
TEXT ·Casp1(SB), NOSPLIT, $0-25
JMP runtimeinternalatomic·Cas64(SB)
// uint32 xadd(uint32 volatile *ptr, int32 delta)
// Atomically:
// *val += delta;
// return *val;
TEXT ·Xadd(SB), NOSPLIT, $0-20
MOVV ptr+0(FP), R2
MOVW delta+8(FP), R3
SYNC
LL(2, 1) // R1 = *R2
ADDU R1, R3, R4
MOVV R4, R1
SC(2, 4) // *R2 = R4
BEQ R4, -4(PC)
MOVW R1, ret+16(FP)
SYNC
RET
TEXT ·Xadd64(SB), NOSPLIT, $0-24
MOVV ptr+0(FP), R2
MOVV delta+8(FP), R3
SYNC
LLV(2, 1) // R1 = *R2
ADDVU R1, R3, R4
MOVV R4, R1
SCV(2, 4) // *R2 = R4
BEQ R4, -4(PC)
MOVV R1, ret+16(FP)
SYNC
RET
TEXT ·Xchg(SB), NOSPLIT, $0-20
MOVV ptr+0(FP), R2
MOVW new+8(FP), R5
SYNC
MOVV R5, R3
LL(2, 1) // R1 = *R2
SC(2, 3) // *R2 = R3
BEQ R3, -3(PC)
MOVW R1, ret+16(FP)
SYNC
RET
TEXT ·Xchg64(SB), NOSPLIT, $0-24
MOVV ptr+0(FP), R2
MOVV new+8(FP), R5
SYNC
MOVV R5, R3
LLV(2, 1) // R1 = *R2
SCV(2, 3) // *R2 = R3
BEQ R3, -3(PC)
MOVV R1, ret+16(FP)
SYNC
RET
TEXT ·Xchguintptr(SB), NOSPLIT, $0-24
JMP ·Xchg64(SB)
TEXT ·Storep1(SB), NOSPLIT, $0-16
JMP ·Store64(SB)
TEXT ·Store(SB), NOSPLIT, $0-12
MOVV ptr+0(FP), R1
MOVW val+8(FP), R2
SYNC
MOVW R2, 0(R1)
SYNC
RET
TEXT ·Store64(SB), NOSPLIT, $0-16
MOVV ptr+0(FP), R1
MOVV val+8(FP), R2
SYNC
MOVV R2, 0(R1)
SYNC
RET
// void Or8(byte volatile*, byte);
TEXT ·Or8(SB), NOSPLIT, $0-9
MOVV ptr+0(FP), R1
MOVBU val+8(FP), R2
// Align ptr down to 4 bytes so we can use 32-bit load/store.
MOVV $~3, R3
AND R1, R3
// Compute val shift.
#ifdef GOARCH_mips64
// Big endian. ptr = ptr ^ 3
XOR $3, R1
#endif
// R4 = ((ptr & 3) * 8)
AND $3, R1, R4
SLLV $3, R4
// Shift val for aligned ptr. R2 = val << R4
SLLV R4, R2
SYNC
LL(3, 4) // R4 = *R3
OR R2, R4
SC(3, 4) // *R3 = R4
BEQ R4, -4(PC)
SYNC
RET
// void And8(byte volatile*, byte);
TEXT ·And8(SB), NOSPLIT, $0-9
MOVV ptr+0(FP), R1
MOVBU val+8(FP), R2
// Align ptr down to 4 bytes so we can use 32-bit load/store.
MOVV $~3, R3
AND R1, R3
// Compute val shift.
#ifdef GOARCH_mips64
// Big endian. ptr = ptr ^ 3
XOR $3, R1
#endif
// R4 = ((ptr & 3) * 8)
AND $3, R1, R4
SLLV $3, R4
// Shift val for aligned ptr. R2 = val << R4 | ^(0xFF << R4)
MOVV $0xFF, R5
SLLV R4, R2
SLLV R4, R5
NOR R0, R5
OR R5, R2
SYNC
LL(3, 4) // R4 = *R3
AND R2, R4
SC(3, 4) // *R3 = R4
BEQ R4, -4(PC)
SYNC
RET

View File

@ -0,0 +1,56 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build mips64 mips64le
package atomic
import "unsafe"
//go:noescape
func Xadd(ptr *uint32, delta int32) uint32
//go:noescape
func Xadd64(ptr *uint64, delta int64) uint64
//go:noescape
func Xadduintptr(ptr *uintptr, delta uintptr) uintptr
//go:noescape
func Xchg(ptr *uint32, new uint32) uint32
//go:noescape
func Xchg64(ptr *uint64, new uint64) uint64
//go:noescape
func Xchguintptr(ptr *uintptr, new uintptr) uintptr
//go:noescape
func Load(ptr *uint32) uint32
//go:noescape
func Load64(ptr *uint64) uint64
//go:noescape
func Loadp(ptr unsafe.Pointer) unsafe.Pointer
//go:noescape
func And8(ptr *uint8, val uint8)
//go:noescape
func Or8(ptr *uint8, val uint8)
// NOTE: Do not add atomicxor8 (XOR is not idempotent).
//go:noescape
func Cas64(ptr *uint64, old, new uint64) bool
//go:noescape
func Store(ptr *uint32, val uint32)
//go:noescape
func Store64(ptr *uint64, val uint64)
// NO go:noescape annotation; see atomic_pointer.go.
func Storep1(ptr unsafe.Pointer, val unsafe.Pointer)

View File

@ -0,0 +1,36 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build mips64 mips64le
#include "textflag.h"
#define SYNC WORD $0xf
// uint32 runtimeinternalatomic·Load(uint32 volatile* addr)
TEXT ·Load(SB),NOSPLIT,$-8-12
MOVV addr+0(FP), R1
SYNC
MOVWU 0(R1), R1
SYNC
MOVW R1, ret+8(FP)
RET
// uint64 runtimeinternalatomic·Load64(uint64 volatile* addr)
TEXT ·Load64(SB),NOSPLIT,$-8-16
MOVV addr+0(FP), R1
SYNC
MOVV 0(R1), R1
SYNC
MOVV R1, ret+8(FP)
RET
// void *runtimeinternalatomic·Loadp(void *volatile *addr)
TEXT ·Loadp(SB),NOSPLIT,$-8-16
MOVV addr+0(FP), R1
SYNC
MOVV 0(R1), R1
SYNC
MOVV R1, ret+8(FP)
RET