github.com/goplus/llgo@v0.8.3/internal/runtime/stubs.go (about)

     1  // Copyright 2014 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  package runtime
     6  
     7  import _ "unsafe"
     8  
     9  //go:linkname fastrand C.rand
    10  func fastrand() uint32
    11  
    12  /* TODO(xsw):
    13  func fastrand() uint32 {
    14  	mp := getg().m
    15  	// Implement wyrand: https://github.com/wangyi-fudan/wyhash
    16  	// Only the platform that math.Mul64 can be lowered
    17  	// by the compiler should be in this list.
    18  	if goarch.IsAmd64|goarch.IsArm64|goarch.IsPpc64|
    19  		goarch.IsPpc64le|goarch.IsMips64|goarch.IsMips64le|
    20  		goarch.IsS390x|goarch.IsRiscv64|goarch.IsLoong64 == 1 {
    21  		mp.fastrand += 0xa0761d6478bd642f
    22  		hi, lo := math.Mul64(mp.fastrand, mp.fastrand^0xe7037ed1a0b428db)
    23  		return uint32(hi ^ lo)
    24  	}
    25  
    26  	// Implement xorshift64+: 2 32-bit xorshift sequences added together.
    27  	// Shift triplet [17,7,16] was calculated as indicated in Marsaglia's
    28  	// Xorshift paper: https://www.jstatsoft.org/article/view/v008i14/xorshift.pdf
    29  	// This generator passes the SmallCrush suite, part of TestU01 framework:
    30  	// http://simul.iro.umontreal.ca/testu01/tu01.html
    31  	t := (*[2]uint32)(unsafe.Pointer(&mp.fastrand))
    32  	s1, s0 := t[0], t[1]
    33  	s1 ^= s1 << 17
    34  	s1 = s1 ^ s0 ^ s1>>7 ^ s0>>16
    35  	t[0], t[1] = s0, s1
    36  	return s0 + s1
    37  }
    38  */