runtime: stubs init hashkey

This commit is contained in:
visualfc
2024-07-01 16:20:14 +08:00
parent 8d193ab39f
commit 4286a510b4

View File

@@ -8,12 +8,16 @@ import (
"unsafe"
"github.com/goplus/llgo/c/sync/atomic"
"github.com/goplus/llgo/c/time"
"github.com/goplus/llgo/internal/runtime/math"
)
//go:linkname fastrand C.rand
func fastrand() uint32
//go:linkname srand C.srand
func srand(uint32)
func fastrand64() uint64 {
n := uint64(fastrand())
n += 0xa0761d6478bd642f
@@ -21,6 +25,14 @@ func fastrand64() uint64 {
return hi ^ lo
}
func init() {
srand(uint32(time.Time(nil)))
hashkey[0] = uintptr(fastrand()) | 1
hashkey[1] = uintptr(fastrand()) | 1
hashkey[2] = uintptr(fastrand()) | 1
hashkey[3] = uintptr(fastrand()) | 1
}
/* TODO(xsw):
func fastrand() uint32 {
mp := getg().m