From a779c1d7560719ad064ace194296a1cffe8ebada Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 19 Jul 2022 17:11:14 +0800 Subject: [PATCH] support ./src/prng/*.c --- c2go.a.pub | 7 + c2go.cfg | 1 + c2go.pub | 7 + c2go_header.i.go | 200 +++++++++++++------------- drand48.c.i.go | 15 ++ lcong48.c.i.go | 7 + lrand48.c.i.go | 10 ++ mrand48.c.i.go | 10 ++ rand.c.i.go | 11 ++ rand_r.c.i.go | 16 +++ random.c.i.go | 117 +++++++++++++++ seed48.c.i.go | 11 ++ srand48.c.i.go | 7 + test/c2go.cfg | 28 ++-- test/cmd/test/random/c2go_header.i.go | 1 + test/cmd/test/random/random.c.i.go | 121 ++++++++++++++++ x2g__rand48_step.c.i.go | 15 ++ x2g__seed48.c.i.go | 3 + 18 files changed, 475 insertions(+), 112 deletions(-) create mode 100644 drand48.c.i.go create mode 100644 lcong48.c.i.go create mode 100644 lrand48.c.i.go create mode 100644 mrand48.c.i.go create mode 100644 rand.c.i.go create mode 100644 rand_r.c.i.go create mode 100644 random.c.i.go create mode 100644 seed48.c.i.go create mode 100644 srand48.c.i.go create mode 100644 test/cmd/test/random/c2go_header.i.go create mode 100644 test/cmd/test/random/random.c.i.go create mode 100644 x2g__rand48_step.c.i.go create mode 100644 x2g__seed48.c.i.go diff --git a/c2go.a.pub b/c2go.a.pub index 2c726d6..975fd26 100644 --- a/c2go.a.pub +++ b/c2go.a.pub @@ -41,6 +41,7 @@ frexpl fwrite getenv gid_t +initstate ino_t int16_t int32_t @@ -78,13 +79,19 @@ pthread_spinlock_t pthread_t ptrdiff_t qsort +rand +rand_r +random scalbn scalbnf scalbnl +setstate sigset_t size_t snprintf sprintf +srand +srandom ssize_t stderr stdin diff --git a/c2go.cfg b/c2go.cfg index 910f4e5..c34af68 100644 --- a/c2go.cfg +++ b/c2go.cfg @@ -28,6 +28,7 @@ ] }, "dirs": [ + "./src/prng", "./src/ctype", "./src/string" ], diff --git a/c2go.pub b/c2go.pub index 5185c89..59d78f6 100644 --- a/c2go.pub +++ b/c2go.pub @@ -8,6 +8,13 @@ __signbit __signbitl __FLOAT_BITS __DOUBLE_BITS +initstate +setstate +srandom +srand +random +rand +rand_r abort feclearexcept feraiseexcept diff --git a/c2go_header.i.go b/c2go_header.i.go index 8b666a3..08e1e91 100644 --- a/c2go_header.i.go +++ b/c2go_header.i.go @@ -2,6 +2,46 @@ package libc import unsafe "unsafe" +type uintptr_t = uint64 +type Uintptr_t = uint64 +type intptr_t = int64 +type Intptr_t = int64 +type int8_t = int8 +type Int8_t = int8 +type int16_t = int16 +type Int16_t = int16 +type int32_t = int32 +type Int32_t = int32 +type int64_t = int64 +type Int64_t = int64 +type intmax_t = int64 +type Intmax_t = int64 +type uint8_t = uint8 +type Uint8_t = uint8 +type uint16_t = uint16 +type Uint16_t = uint16 +type uint32_t = uint32 +type Uint32_t = uint32 +type uint64_t = uint64 +type Uint64_t = uint64 +type uintmax_t = uint64 +type Uintmax_t = uint64 +type int_fast8_t = int8 +type int_fast64_t = int64 +type int_least8_t = int8 +type int_least16_t = int16 +type int_least32_t = int32 +type int_least64_t = int64 +type uint_fast8_t = uint8 +type uint_fast64_t = uint64 +type uint_least8_t = uint8 +type uint_least16_t = uint16 +type uint_least32_t = uint32 +type uint_least64_t = uint64 +type int_fast16_t = int32 +type int_fast32_t = int32 +type uint_fast16_t = uint32 +type uint_fast32_t = uint32 type size_t = uint64 type Size_t = uint64 type time_t = int64 @@ -22,71 +62,71 @@ type pthread_key_t = uint32 type Pthread_key_t = uint32 type pthread_spinlock_t = int32 type Pthread_spinlock_t = int32 -type _cgoa_1___ctype_b_loc struct { +type _cgoa_1___rand48_step struct { __attr uint32 } -type pthread_mutexattr_t = _cgoa_1___ctype_b_loc -type Pthread_mutexattr_t = _cgoa_1___ctype_b_loc -type _cgoa_2___ctype_b_loc struct { +type pthread_mutexattr_t = _cgoa_1___rand48_step +type Pthread_mutexattr_t = _cgoa_1___rand48_step +type _cgoa_2___rand48_step struct { __attr uint32 } -type pthread_condattr_t = _cgoa_2___ctype_b_loc -type Pthread_condattr_t = _cgoa_2___ctype_b_loc -type _cgoa_3___ctype_b_loc struct { +type pthread_condattr_t = _cgoa_2___rand48_step +type Pthread_condattr_t = _cgoa_2___rand48_step +type _cgoa_3___rand48_step struct { __attr uint32 } -type pthread_barrierattr_t = _cgoa_3___ctype_b_loc -type Pthread_barrierattr_t = _cgoa_3___ctype_b_loc -type _cgoa_4___ctype_b_loc struct { +type pthread_barrierattr_t = _cgoa_3___rand48_step +type Pthread_barrierattr_t = _cgoa_3___rand48_step +type _cgoa_4___rand48_step struct { __attr [2]uint32 } -type pthread_rwlockattr_t = _cgoa_4___ctype_b_loc -type Pthread_rwlockattr_t = _cgoa_4___ctype_b_loc +type pthread_rwlockattr_t = _cgoa_4___rand48_step +type Pthread_rwlockattr_t = _cgoa_4___rand48_step type struct___sigset_t struct { __bits [16]uint64 } type sigset_t = struct___sigset_t type Sigset_t = struct___sigset_t -type _cgoa_6___ctype_b_loc struct { +type _cgoa_6___rand48_step struct { __i [14]int32 } -type _cgoa_5___ctype_b_loc struct { - __u _cgoa_6___ctype_b_loc +type _cgoa_5___rand48_step struct { + __u _cgoa_6___rand48_step } -type pthread_attr_t = _cgoa_5___ctype_b_loc -type Pthread_attr_t = _cgoa_5___ctype_b_loc -type _cgoa_8___ctype_b_loc struct { +type pthread_attr_t = _cgoa_5___rand48_step +type Pthread_attr_t = _cgoa_5___rand48_step +type _cgoa_8___rand48_step struct { __i [10]int32 } -type _cgoa_7___ctype_b_loc struct { - __u _cgoa_8___ctype_b_loc +type _cgoa_7___rand48_step struct { + __u _cgoa_8___rand48_step } -type pthread_mutex_t = _cgoa_7___ctype_b_loc -type Pthread_mutex_t = _cgoa_7___ctype_b_loc -type _cgoa_10___ctype_b_loc struct { +type pthread_mutex_t = _cgoa_7___rand48_step +type Pthread_mutex_t = _cgoa_7___rand48_step +type _cgoa_10___rand48_step struct { __i [12]int32 } -type _cgoa_9___ctype_b_loc struct { - __u _cgoa_10___ctype_b_loc +type _cgoa_9___rand48_step struct { + __u _cgoa_10___rand48_step } -type pthread_cond_t = _cgoa_9___ctype_b_loc -type Pthread_cond_t = _cgoa_9___ctype_b_loc -type _cgoa_12___ctype_b_loc struct { +type pthread_cond_t = _cgoa_9___rand48_step +type Pthread_cond_t = _cgoa_9___rand48_step +type _cgoa_12___rand48_step struct { __i [14]int32 } -type _cgoa_11___ctype_b_loc struct { - __u _cgoa_12___ctype_b_loc +type _cgoa_11___rand48_step struct { + __u _cgoa_12___rand48_step } -type pthread_rwlock_t = _cgoa_11___ctype_b_loc -type Pthread_rwlock_t = _cgoa_11___ctype_b_loc -type _cgoa_14___ctype_b_loc struct { +type pthread_rwlock_t = _cgoa_11___rand48_step +type Pthread_rwlock_t = _cgoa_11___rand48_step +type _cgoa_14___rand48_step struct { __i [8]int32 } -type _cgoa_13___ctype_b_loc struct { - __u _cgoa_14___ctype_b_loc +type _cgoa_13___rand48_step struct { + __u _cgoa_14___rand48_step } -type pthread_barrier_t = _cgoa_13___ctype_b_loc -type Pthread_barrier_t = _cgoa_13___ctype_b_loc +type pthread_barrier_t = _cgoa_13___rand48_step +type Pthread_barrier_t = _cgoa_13___rand48_step type pid_t = int32 type Pid_t = int32 type struct_sched_param struct { @@ -129,40 +169,39 @@ type struct___pthread struct { sys_r1 int64 locale *struct___locale_struct } -type uint16_t = uint16 -type Uint16_t = uint16 -type uint32_t = uint32 -type Uint32_t = uint32 -type uint64_t = uint64 -type Uint64_t = uint64 - -func __bswap16(__x uint16) uint16 { - return uint16(int32(__x)<>int32(8)) -} -func __bswap32(__x uint32) uint32 { - return __x>>int32(24) | __x>>int32(8)&uint32(65280) | __x<>int32(32)))) -} - type wchar_t = uint32 type Wchar_t = uint32 -type _cgoa_15___ctype_get_mb_cur_max struct { +type _cgoa_15_drand48 struct { quot int32 rem int32 } -type div_t = _cgoa_15___ctype_get_mb_cur_max -type _cgoa_16___ctype_get_mb_cur_max struct { +type div_t = _cgoa_15_drand48 +type _cgoa_16_drand48 struct { quot int64 rem int64 } -type ldiv_t = _cgoa_16___ctype_get_mb_cur_max -type _cgoa_17___ctype_get_mb_cur_max struct { +type ldiv_t = _cgoa_16_drand48 +type _cgoa_17_drand48 struct { quot int64 rem int64 } -type lldiv_t = _cgoa_17___ctype_get_mb_cur_max +type lldiv_t = _cgoa_17_drand48 +type _cgoa_18_drand48 struct { + quot int64 + rem int64 +} +type imaxdiv_t = _cgoa_18_drand48 + +func __bswap16(__x uint16) uint16 { + return uint16(int32(__x)<>int32(8)) +} +func __bswap32(__x uint32) uint32 { + return __x>>int32(24) | __x>>int32(8)&uint32(65280) | __x<>int32(32)))) +} + type struct_lconv struct { decimal_point *int8 thousands_sep *int8 @@ -235,40 +274,6 @@ type struct___locale_map struct { name [24]int8 next *struct___locale_map } -type uintptr_t = uint64 -type Uintptr_t = uint64 -type intptr_t = int64 -type Intptr_t = int64 -type int8_t = int8 -type Int8_t = int8 -type int16_t = int16 -type Int16_t = int16 -type int32_t = int32 -type Int32_t = int32 -type int64_t = int64 -type Int64_t = int64 -type intmax_t = int64 -type Intmax_t = int64 -type uint8_t = uint8 -type Uint8_t = uint8 -type uintmax_t = uint64 -type Uintmax_t = uint64 -type int_fast8_t = int8 -type int_fast64_t = int64 -type int_least8_t = int8 -type int_least16_t = int16 -type int_least32_t = int32 -type int_least64_t = int64 -type uint_fast8_t = uint8 -type uint_fast64_t = uint64 -type uint_least8_t = uint8 -type uint_least16_t = uint16 -type uint_least32_t = uint32 -type uint_least64_t = uint64 -type int_fast16_t = int32 -type int_fast32_t = int32 -type uint_fast16_t = uint32 -type uint_fast32_t = uint32 func __isspace(_c int32) int32 { return func() int32 { @@ -432,7 +437,7 @@ type struct_sigaction struct { } type _cgoa_30_strsignal struct { sigev_notify_function func(union_sigval) - sigev_notify_attributes *_cgoa_5___ctype_b_loc + sigev_notify_attributes *_cgoa_5___rand48_step } type _cgoa_29_strsignal struct { __pad [48]int8 @@ -2037,8 +2042,3 @@ type struct_winsize struct { ws_xpixel uint16 ws_ypixel uint16 } -type _cgoa_19_vfprintf struct { - quot int64 - rem int64 -} -type imaxdiv_t = _cgoa_19_vfprintf diff --git a/drand48.c.i.go b/drand48.c.i.go new file mode 100644 index 0000000..01329b7 --- /dev/null +++ b/drand48.c.i.go @@ -0,0 +1,15 @@ +package libc + +import unsafe "unsafe" + +func erand48(s *uint16) float64 { + type _cgoa_19_drand48 struct { + u uint64 + } + var x _cgoa_19_drand48 + x.u = uint64(4607182418800017408) | __rand48_step(s, (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))))+uintptr(int32(3))*2)))<> int32(17)) +} +func lrand48() int64 { + return nrand48((*uint16)(unsafe.Pointer(&__seed48))) +} diff --git a/mrand48.c.i.go b/mrand48.c.i.go new file mode 100644 index 0000000..e236786 --- /dev/null +++ b/mrand48.c.i.go @@ -0,0 +1,10 @@ +package libc + +import unsafe "unsafe" + +func jrand48(s *uint16) int64 { + return int64(int32(__rand48_step(s, (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))))+uintptr(int32(3))*2))) >> int32(16))) +} +func mrand48() int64 { + return jrand48((*uint16)(unsafe.Pointer(&__seed48))) +} diff --git a/rand.c.i.go b/rand.c.i.go new file mode 100644 index 0000000..14a6882 --- /dev/null +++ b/rand.c.i.go @@ -0,0 +1,11 @@ +package libc + +var seed_cgo18_rand uint64 + +func Srand(s uint32) { + seed_cgo18_rand = uint64(s - uint32(1)) +} +func Rand() int32 { + seed_cgo18_rand = uint64(6364136223846793005)*seed_cgo18_rand + uint64(1) + return int32(seed_cgo18_rand >> int32(33)) +} diff --git a/rand_r.c.i.go b/rand_r.c.i.go new file mode 100644 index 0000000..d55ce64 --- /dev/null +++ b/rand_r.c.i.go @@ -0,0 +1,16 @@ +package libc + +func temper_cgo18_rand_r(x uint32) uint32 { + x ^= x >> int32(11) + x ^= x << int32(7) & uint32(2636928640) + x ^= x << int32(15) & uint32(4022730752) + x ^= x >> int32(18) + return x +} +func Rand_r(seed *uint32) int32 { + return int32(temper_cgo18_rand_r(func() (_cgo_ret uint32) { + _cgo_addr := &*seed + *_cgo_addr = *seed*uint32(1103515245) + uint32(12345) + return *_cgo_addr + }()) / uint32(2)) +} diff --git a/random.c.i.go b/random.c.i.go new file mode 100644 index 0000000..3ad1a4e --- /dev/null +++ b/random.c.i.go @@ -0,0 +1,117 @@ +package libc + +import unsafe "unsafe" + +var init_cgo18_random [32]uint32 = [32]uint32{uint32(0), uint32(1481765933), uint32(3232861391), uint32(3417699910), uint32(3338875177), uint32(812669700), uint32(553475508), uint32(2592833400), uint32(1344887256), uint32(2877900904), uint32(1812158119), uint32(2295183359), uint32(3027751999), uint32(1889772843), uint32(2833562353), uint32(4253237756), uint32(2330030041), uint32(1949118330), uint32(220137366), uint32(1979932169), uint32(1089957932), uint32(1873226917), uint32(2863153495), uint32(1486937972), uint32(3343516516), uint32(2924690628), uint32(68706223), uint32(1843638549), uint32(212567592), uint32(4030971812), uint32(964776169), uint32(928126551)} +var n_cgo19_random int32 = int32(31) +var i_cgo20_random int32 = int32(3) +var j_cgo21_random int32 = int32(0) +var x_cgo22_random *uint32 = (*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint32)(unsafe.Pointer(&init_cgo18_random)))) + uintptr(int32(1))*4)) +var lock_cgo23_random [1]int32 +var __random_lockptr *int32 = (*int32)(unsafe.Pointer(&lock_cgo23_random)) + +func lcg31_cgo24_random(x uint32) uint32 { + return (uint32(1103515245)*x + uint32(12345)) & uint32(2147483647) +} +func lcg64_cgo25_random(x uint64) uint64 { + return uint64(6364136223846793005)*x + uint64(1) +} +func savestate_cgo26_random() unsafe.Pointer { + *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) - uintptr(1)*4)) = uint32(n_cgo19_random<> int32(16)) + i_cgo20_random = int32(*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) - uintptr(1)*4)) >> int32(8) & uint32(255)) + j_cgo21_random = int32(*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) - uintptr(1)*4)) & uint32(255)) +} +func __srandom_cgo28_random(seed uint32) { + var k int32 + var s uint64 = uint64(seed) + if n_cgo19_random == int32(0) { + *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(int32(0))*4)) = uint32(s) + return + } + i_cgo20_random = func() int32 { + if n_cgo19_random == int32(31) || n_cgo19_random == int32(7) { + return int32(3) + } else { + return int32(1) + } + }() + j_cgo21_random = int32(0) + for k = int32(0); k < n_cgo19_random; k++ { + s = lcg64_cgo25_random(s) + *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(k)*4)) = uint32(s >> int32(32)) + } + *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(int32(0))*4)) |= uint32(1) +} +func Srandom(seed uint32) { + __lock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + __srandom_cgo28_random(seed) + __unlock((*int32)(unsafe.Pointer(&lock_cgo23_random))) +} +func Initstate(seed uint32, state *int8, size uint64) *int8 { + var old unsafe.Pointer + if size < uint64(8) { + return (*int8)(nil) + } + __lock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + old = savestate_cgo26_random() + if size < uint64(32) { + n_cgo19_random = int32(0) + } else if size < uint64(64) { + n_cgo19_random = int32(7) + } else if size < uint64(128) { + n_cgo19_random = int32(15) + } else if size < uint64(256) { + n_cgo19_random = int32(31) + } else { + n_cgo19_random = int32(63) + } + x_cgo22_random = (*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer((*uint32)(unsafe.Pointer(state)))) + uintptr(int32(1))*4)) + __srandom_cgo28_random(seed) + savestate_cgo26_random() + __unlock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + return (*int8)(old) +} +func Setstate(state *int8) *int8 { + var old unsafe.Pointer + __lock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + old = savestate_cgo26_random() + loadstate_cgo27_random((*uint32)(unsafe.Pointer(state))) + __unlock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + return (*int8)(old) +} +func Random() int64 { + var k int64 + __lock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + if n_cgo19_random == int32(0) { + k = int64(func() (_cgo_ret uint32) { + _cgo_addr := &*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(int32(0))*4)) + *_cgo_addr = lcg31_cgo24_random(*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(int32(0))*4))) + return *_cgo_addr + }()) + goto end + } + *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(i_cgo20_random)*4)) += *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(j_cgo21_random)*4)) + k = int64(*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(x_cgo22_random)) + uintptr(i_cgo20_random)*4)) >> int32(1)) + if func() (_cgo_ret int32) { + _cgo_addr := &i_cgo20_random + *_cgo_addr++ + return *_cgo_addr + }() == n_cgo19_random { + i_cgo20_random = int32(0) + } + if func() (_cgo_ret int32) { + _cgo_addr := &j_cgo21_random + *_cgo_addr++ + return *_cgo_addr + }() == n_cgo19_random { + j_cgo21_random = int32(0) + } +end: + __unlock((*int32)(unsafe.Pointer(&lock_cgo23_random))) + return k +} diff --git a/seed48.c.i.go b/seed48.c.i.go new file mode 100644 index 0000000..2fa8636 --- /dev/null +++ b/seed48.c.i.go @@ -0,0 +1,11 @@ +package libc + +import unsafe "unsafe" + +func seed48(s *uint16) *uint16 { + Memcpy(unsafe.Pointer((*uint16)(unsafe.Pointer(&p_cgo18_seed48))), unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))), 6) + Memcpy(unsafe.Pointer((*uint16)(unsafe.Pointer(&__seed48))), unsafe.Pointer(s), 6) + return (*uint16)(unsafe.Pointer(&p_cgo18_seed48)) +} + +var p_cgo18_seed48 [3]uint16 diff --git a/srand48.c.i.go b/srand48.c.i.go new file mode 100644 index 0000000..4690d39 --- /dev/null +++ b/srand48.c.i.go @@ -0,0 +1,7 @@ +package libc + +import unsafe "unsafe" + +func srand48(seed int64) { + seed48((*uint16)(unsafe.Pointer(&[3]uint16{uint16(13070), uint16(seed), uint16(seed >> int32(16))}))) +} diff --git a/test/c2go.cfg b/test/c2go.cfg index bdfe4dc..8a18b05 100644 --- a/test/c2go.cfg +++ b/test/c2go.cfg @@ -2,35 +2,39 @@ "target": { "cmds": [ { - "dir": "cmd/test_frexpl", + "for": [ + "random", + "qsort", + "strtod", + "string", + "string_memcpy", + "string_memset", + "snprintf" + ], + "dir": "cmd/test_$(it)", "deps": [ + "github.com/goplus/libc/test/common", "github.com/goplus/libc" ], "source": { "files": [ - "./src/math/frexpl.c", - "./src/common/mtest.c", - "./src/common/print.c" + "./src/functional/$(it).c" ] } }, { "for": [ - "qsort", - "strtod", - "string", - "string_memcpy", - "string_memset", - "snprintf" + "frexpl" ], "dir": "cmd/test_$(it)", "deps": [ - "github.com/goplus/libc/test/common", "github.com/goplus/libc" ], "source": { "files": [ - "./src/functional/$(it).c" + "./src/math/$(it).c", + "./src/common/mtest.c", + "./src/common/print.c" ] } } diff --git a/test/cmd/test/random/c2go_header.i.go b/test/cmd/test/random/c2go_header.i.go new file mode 100644 index 0000000..eeab28a --- /dev/null +++ b/test/cmd/test/random/c2go_header.i.go @@ -0,0 +1 @@ +package random diff --git a/test/cmd/test/random/random.c.i.go b/test/cmd/test/random/random.c.i.go new file mode 100644 index 0000000..b5d72e4 --- /dev/null +++ b/test/cmd/test/random/random.c.i.go @@ -0,0 +1,121 @@ +package random + +import ( + unsafe "unsafe" + libc "github.com/goplus/libc" + common "github.com/goplus/libc/test/common" + testing "testing" +) + +func chkmissing_cgo1_random(x *int64) int32 { + var d [8]int32 = [8]int32{int32(0)} + var i int32 + for i = int32(0); i < int32(100); i++ { + *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&d)))) + uintptr(*(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + uintptr(i)*8))%int64(8))*4))++ + } + for i = int32(0); i < int32(8); i++ { + if *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer((*int32)(unsafe.Pointer(&d)))) + uintptr(i)*4)) == int32(0) { + return int32(1) + } + } + return int32(0) +} +func chkrepeat_cgo2_random(x *int64) int32 { + var i int32 + var j int32 + for i = int32(0); i < int32(100); i++ { + for j = int32(0); j < i; j++ { + if *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + uintptr(i)*8)) == *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + uintptr(j)*8)) { + return int32(1) + } + } + } + return int32(0) +} + +var orx_cgo3_random uint32 + +func chkones_cgo4_random(x *int64) int32 { + var i int32 + orx_cgo3_random = uint32(0) + for i = int32(0); i < int32(20); i++ { + orx_cgo3_random |= uint32(*(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + uintptr(i)*8))) + } + return func() int32 { + if orx_cgo3_random != uint32(2147483647) { + return 1 + } else { + return 0 + } + }() +} +func checkseed(seed uint32, x *int64) { + var i int32 + libc.Srandom(seed) + for i = int32(0); i < int32(100); i++ { + *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(x)) + uintptr(i)*8)) = libc.Random() + } + if chkmissing_cgo1_random(x) != 0 { + common.T_printf((*int8)(unsafe.Pointer(&[71]int8{'s', 'r', 'c', '/', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 'a', 'l', '/', 'r', 'a', 'n', 'd', 'o', 'm', '.', 'c', ':', '5', '0', ':', ' ', 'w', 'e', 'a', 'k', ' ', 's', 'e', 'e', 'd', ' ', '%', 'd', ',', ' ', 'm', 'i', 's', 's', 'i', 'n', 'g', ' ', 'p', 'a', 't', 't', 'e', 'r', 'n', ' ', 'i', 'n', ' ', 'l', 'o', 'w', ' ', 'b', 'i', 't', 's', '\n', '\x00'})), seed) + } + if chkrepeat_cgo2_random(x) != 0 { + common.T_printf((*int8)(unsafe.Pointer(&[57]int8{'s', 'r', 'c', '/', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 'a', 'l', '/', 'r', 'a', 'n', 'd', 'o', 'm', '.', 'c', ':', '5', '2', ':', ' ', 'w', 'e', 'a', 'k', ' ', 's', 'e', 'e', 'd', ' ', '%', 'd', ',', ' ', 'e', 'x', 'a', 'c', 't', ' ', 'r', 'e', 'p', 'e', 'a', 't', 's', '\n', '\x00'})), seed) + } + if chkones_cgo4_random(x) != 0 { + common.T_printf((*int8)(unsafe.Pointer(&[62]int8{'s', 'r', 'c', '/', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 'a', 'l', '/', 'r', 'a', 'n', 'd', 'o', 'm', '.', 'c', ':', '5', '4', ':', ' ', 'w', 'e', 'a', 'k', ' ', 's', 'e', 'e', 'd', ' ', '%', 'd', ',', ' ', 'o', 'r', ' ', 'p', 'a', 't', 't', 'e', 'r', 'n', ':', ' ', '0', 'x', '%', '0', '8', 'x', '\n', '\x00'})), seed, orx_cgo3_random) + } +} +func _cgo_main() int32 { + var x [100]int64 + var y int64 + var z int64 + var i int32 + var state [128]int8 + var p *int8 + var q *int8 + for i = int32(0); i < int32(100); i++ { + *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer((*int64)(unsafe.Pointer(&x)))) + uintptr(i)*8)) = libc.Random() + } + p = libc.Initstate(uint32(1), (*int8)(unsafe.Pointer(&state)), 128) + for i = int32(0); i < int32(100); i++ { + if *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer((*int64)(unsafe.Pointer(&x)))) + uintptr(i)*8)) != func() (_cgo_ret int64) { + _cgo_addr := &y + *_cgo_addr = libc.Random() + return *_cgo_addr + }() { + common.T_printf((*int8)(unsafe.Pointer(&[88]int8{'s', 'r', 'c', '/', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 'a', 'l', '/', 'r', 'a', 'n', 'd', 'o', 'm', '.', 'c', ':', '7', '1', ':', ' ', 'i', 'n', 'i', 't', 's', 't', 'a', 't', 'e', '(', '1', ')', ' ', 'i', 's', ' ', 'n', 'o', 't', ' ', 'd', 'e', 'f', 'a', 'u', 'l', 't', ':', ' ', '(', '%', 'd', ')', ' ', 'd', 'e', 'f', 'a', 'u', 'l', 't', ':', ' ', '%', 'l', 'd', ',', ' ', 's', 'e', 'e', 'd', '1', ':', ' ', '%', 'l', 'd', '\n', '\x00'})), i, *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer((*int64)(unsafe.Pointer(&x)))) + uintptr(i)*8)), y) + } + } + for i = int32(0); i < int32(10); i++ { + z = libc.Random() + q = libc.Setstate(p) + if z != func() (_cgo_ret int64) { + _cgo_addr := &y + *_cgo_addr = libc.Random() + return *_cgo_addr + }() { + common.T_printf((*int8)(unsafe.Pointer(&[72]int8{'s', 'r', 'c', '/', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 'a', 'l', '/', 'r', 'a', 'n', 'd', 'o', 'm', '.', 'c', ':', '7', '6', ':', ' ', 's', 'e', 't', 's', 't', 'a', 't', 'e', ' ', 'f', 'a', 'i', 'l', 'e', 'd', ' ', '(', '%', 'd', ')', ' ', 'o', 'r', 'i', 'g', ':', ' ', '%', 'l', 'd', ',', ' ', 'r', 'e', 's', 'e', 't', ':', ' ', '%', 'l', 'd', '\n', '\x00'})), i, z, y) + } + p = libc.Setstate(q) + } + libc.Srandom(uint32(1)) + for i = int32(0); i < int32(100); i++ { + if *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer((*int64)(unsafe.Pointer(&x)))) + uintptr(i)*8)) != func() (_cgo_ret int64) { + _cgo_addr := &y + *_cgo_addr = libc.Random() + return *_cgo_addr + }() { + common.T_printf((*int8)(unsafe.Pointer(&[86]int8{'s', 'r', 'c', '/', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n', 'a', 'l', '/', 'r', 'a', 'n', 'd', 'o', 'm', '.', 'c', ':', '8', '2', ':', ' ', 's', 'r', 'a', 'n', 'd', 'o', 'm', '(', '1', ')', ' ', 'i', 's', ' ', 'n', 'o', 't', ' ', 'd', 'e', 'f', 'a', 'u', 'l', 't', ':', ' ', '(', '%', 'd', ')', ' ', 'd', 'e', 'f', 'a', 'u', 'l', 't', ':', ' ', '%', 'l', 'd', ',', ' ', 's', 'e', 'e', 'd', '1', ':', ' ', '%', 'l', 'd', '\n', '\x00'})), i, *(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer((*int64)(unsafe.Pointer(&x)))) + uintptr(i)*8)), y) + } + } + checkseed(uint32(2147483647), (*int64)(unsafe.Pointer(&x))) + for i = int32(0); i < int32(10); i++ { + checkseed(uint32(i), (*int64)(unsafe.Pointer(&x))) + } + return common.T_status +} +func TestMain(t *testing.T) { + if _cgo_ret := _cgo_main(); _cgo_ret != 0 { + t.Fatal("exit status", _cgo_ret) + } +} diff --git a/x2g__rand48_step.c.i.go b/x2g__rand48_step.c.i.go new file mode 100644 index 0000000..fbff1b3 --- /dev/null +++ b/x2g__rand48_step.c.i.go @@ -0,0 +1,15 @@ +package libc + +import unsafe "unsafe" + +func __rand48_step(xi *uint16, lc *uint16) uint64 { + var a uint64 + var x uint64 + x = uint64(uint32(*(*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(xi)) + uintptr(int32(0))*2)))|(uint32(*(*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(xi)) + uintptr(int32(1))*2)))+uint32(0))<> int32(16)) + *(*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(xi)) + uintptr(int32(2))*2)) = uint16(x >> int32(32)) + return x & uint64(281474976710655) +} diff --git a/x2g__seed48.c.i.go b/x2g__seed48.c.i.go new file mode 100644 index 0000000..87631cd --- /dev/null +++ b/x2g__seed48.c.i.go @@ -0,0 +1,3 @@ +package libc + +var __seed48 [7]uint16 = [7]uint16{uint16(0), uint16(0), uint16(0), uint16(58989), uint16(57068), uint16(5), uint16(11)}