| author | |
| committer | |
| log | ad3828db45b7830d5953e7c728c227e78f574cf9 |
| tree | 187aefc2f705e6c0c9ec0d8c1ff2b0c94de86e7c |
| parent | 9d1a39c50ffeca1e42ed5f1b75a05d92eec869db |
| signature |
* also remove their musl implementation6 files changed, 32 insertions(+), 34 deletions(-)
lib/c/stdlib.zig+2| ... | @@ -7,6 +7,8 @@ const ldiv_t = std.c.ldiv_t; | ... | @@ -7,6 +7,8 @@ const ldiv_t = std.c.ldiv_t; |
| 7 | const lldiv_t = std.c.lldiv_t; | 7 | const lldiv_t = std.c.lldiv_t; |
| 8 | 8 | ||
| 9 | comptime { | 9 | comptime { |
| 10 | _ = @import("stdlib/rand.zig"); | ||
| 11 | |||
| 10 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 12 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { |
| 11 | // Functions specific to musl and wasi-libc. | 13 | // Functions specific to musl and wasi-libc. |
| 12 | @export(&abs, .{ .name = "abs", .linkage = common.linkage, .visibility = common.visibility }); | 14 | @export(&abs, .{ .name = "abs", .linkage = common.linkage, .visibility = common.visibility }); |
lib/c/stdlib/rand.zig created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const common = @import("../common.zig"); | ||
| 3 | const builtin = @import("builtin"); | ||
| 4 | |||
| 5 | comptime { | ||
| 6 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | ||
| 7 | @export(&rand, .{ .name = "rand", .linkage = common.linkage, .visibility = common.visibility }); | ||
| 8 | @export(&srand, .{ .name = "srand", .linkage = common.linkage, .visibility = common.visibility }); | ||
| 9 | @export(&rand_r, .{ .name = "rand_r", .linkage = common.linkage, .visibility = common.visibility }); | ||
| 10 | } | ||
| 11 | } | ||
| 12 | |||
| 13 | // NOTE: The PRNG used for `rand` is unspecified, so it can be any! | ||
| 14 | var rand_state: std.Random.SplitMix64 = .init(1); | ||
| 15 | |||
| 16 | fn rand_r(seed: *c_uint) callconv(.c) c_int { | ||
| 17 | var mix: std.Random.SplitMix64 = .init(seed.*); | ||
| 18 | defer seed.* = @truncate(mix.s); | ||
| 19 | |||
| 20 | // Every bundled libc defines RAND_MAX as `std.math.maxInt(u31)` (except windows where it is `std.math.maxInt(u15)`) | ||
| 21 | return @as(u31, @truncate(mix.next() >> 33)); | ||
| 22 | } | ||
| 23 | |||
| 24 | fn srand(seed: c_uint) callconv(.c) void { | ||
| 25 | rand_state = .init(seed); | ||
| 26 | } | ||
| 27 | |||
| 28 | fn rand() callconv(.c) c_int { | ||
| 29 | return @as(u31, @truncate(rand_state.next() >> 33)); | ||
| 30 | } | ||
lib/libc/musl/src/prng/rand.c deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | static uint64_t seed; | ||
| 5 | |||
| 6 | void srand(unsigned s) | ||
| 7 | { | ||
| 8 | 	seed = s-1; | ||
| 9 | } | ||
| 10 | |||
| 11 | int rand(void) | ||
| 12 | { | ||
| 13 | 	seed = 6364136223846793005ULL*seed + 1; | ||
| 14 | 	return seed>>33; | ||
| 15 | } | ||
lib/libc/musl/src/prng/rand_r.c deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | static unsigned temper(unsigned x) | ||
| 4 | { | ||
| 5 | 	x ^= x>>11; | ||
| 6 | 	x ^= x<<7 & 0x9D2C5680; | ||
| 7 | 	x ^= x<<15 & 0xEFC60000; | ||
| 8 | 	x ^= x>>18; | ||
| 9 | 	return x; | ||
| 10 | } | ||
| 11 | |||
| 12 | int rand_r(unsigned *seed) | ||
| 13 | { | ||
| 14 | 	return temper(*seed = *seed * 1103515245 + 12345)/2; | ||
| 15 | } | ||
src/libs/musl.zig-2| ... | @@ -1310,9 +1310,7 @@ const src_files = [_][]const u8{ | ... | @@ -1310,9 +1310,7 @@ const src_files = [_][]const u8{ |
| 1310 | "musl/src/prng/lrand48.c", | 1310 | "musl/src/prng/lrand48.c", |
| 1311 | "musl/src/prng/mrand48.c", | 1311 | "musl/src/prng/mrand48.c", |
| 1312 | "musl/src/prng/__rand48_step.c", | 1312 | "musl/src/prng/__rand48_step.c", |
| 1313 | "musl/src/prng/rand.c", | ||
| 1314 | "musl/src/prng/random.c", | 1313 | "musl/src/prng/random.c", |
| 1315 | "musl/src/prng/rand_r.c", | ||
| 1316 | "musl/src/prng/__seed48.c", | 1314 | "musl/src/prng/__seed48.c", |
| 1317 | "musl/src/prng/seed48.c", | 1315 | "musl/src/prng/seed48.c", |
| 1318 | "musl/src/prng/srand48.c", | 1316 | "musl/src/prng/srand48.c", |
src/libs/wasi_libc.zig-2| ... | @@ -890,8 +890,6 @@ const libc_top_half_src_files = [_][]const u8{ | ... | @@ -890,8 +890,6 @@ const libc_top_half_src_files = [_][]const u8{ |
| 890 | "musl/src/prng/lrand48.c", | 890 | "musl/src/prng/lrand48.c", |
| 891 | "musl/src/prng/mrand48.c", | 891 | "musl/src/prng/mrand48.c", |
| 892 | "musl/src/prng/__rand48_step.c", | 892 | "musl/src/prng/__rand48_step.c", |
| 893 | "musl/src/prng/rand.c", | ||
| 894 | "musl/src/prng/rand_r.c", | ||
| 895 | "musl/src/prng/__seed48.c", | 893 | "musl/src/prng/__seed48.c", |
| 896 | "musl/src/prng/seed48.c", | 894 | "musl/src/prng/seed48.c", |
| 897 | "musl/src/prng/srand48.c", | 895 | "musl/src/prng/srand48.c", |