Fold LIBC_RAND into LIBC_STDIO/TINYMATH/INTRIN

This commit is contained in:
Justine Tunney 2022-08-11 12:26:30 -07:00
parent 05b8f82371
commit 8a0a2c0c36
183 changed files with 149 additions and 322 deletions

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/intrin/spinlock.h"
#include "libc/nexgen32e/threaded.h"
#include "libc/rand/lcg.internal.h"
#include "libc/stdio/lcg.internal.h"
/**
* Returns handles of windows pids being tracked.

View file

@ -38,7 +38,7 @@
#include "libc/nt/struct/filetime.h"
#include "libc/nt/struct/processmemorycounters.h"
#include "libc/nt/synchronization.h"
#include "libc/rand/lcg.internal.h"
#include "libc/stdio/lcg.internal.h"
#include "libc/runtime/ezmap.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -29,7 +29,6 @@ LIBC_DNS_A_DIRECTDEPS = \
LIBC_FMT \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_SOCK \
LIBC_STDIO \

View file

@ -24,7 +24,7 @@
#include "libc/dns/dnsquestion.h"
#include "libc/dns/resolvconf.h"
#include "libc/mem/mem.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"

View file

@ -32,7 +32,7 @@
#include "libc/dns/dnsquestion.h"
#include "libc/dns/resolvconf.h"
#include "libc/mem/mem.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/str/str.h"

View file

@ -3,7 +3,7 @@
#include "libc/alg/alg.h"
#include "libc/fmt/conv.h"
#include "libc/mem/mem.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/temp.h"
#include "libc/sysv/consts/exit.h"

View file

@ -1,5 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_ISYSTEM_SYS_RANDOM_H_
#define COSMOPOLITAN_LIBC_ISYSTEM_SYS_RANDOM_H_
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/sysv/consts/grnd.h"
#endif /* COSMOPOLITAN_LIBC_ISYSTEM_SYS_RANDOM_H_ */

View file

@ -26,7 +26,6 @@ LIBC_LOG_A_CHECKS = \
$(LIBC_LOG_A_HDRS:%=o/$(MODE)/%.ok)
LIBC_LOG_A_DIRECTDEPS = \
LIBC_ALG \
LIBC_CALLS \
LIBC_ELF \
LIBC_FMT \
@ -35,7 +34,6 @@ LIBC_LOG_A_DIRECTDEPS = \
LIBC_NEXGEN32E \
LIBC_NT_KERNEL32 \
LIBC_NT_NTDLL \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \

View file

@ -33,7 +33,6 @@ LIBC_MEM_A_DIRECTDEPS = \
LIBC_FMT \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_STR \
LIBC_STUBS \

View file

@ -1,10 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_RAND_INTERNAL_H_
#define COSMOPOLITAN_LIBC_RAND_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
hidden extern uint64_t g_rando;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_RAND_INTERNAL_H_ */

60
libc/rand/rand.mk Normal file → Executable file
View file

@ -1,60 +0,0 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += LIBC_RAND
LIBC_RAND_ARTIFACTS += LIBC_RAND_A
LIBC_RAND = $(LIBC_RAND_A_DEPS) $(LIBC_RAND_A)
LIBC_RAND_A = o/$(MODE)/libc/rand/rand.a
LIBC_RAND_A_FILES := $(wildcard libc/rand/*)
LIBC_RAND_A_HDRS = $(filter %.h,$(LIBC_RAND_A_FILES))
LIBC_RAND_A_SRCS_S = $(filter %.S,$(LIBC_RAND_A_FILES))
LIBC_RAND_A_SRCS_C = $(filter %.c,$(LIBC_RAND_A_FILES))
LIBC_RAND_A_SRCS = \
$(LIBC_RAND_A_SRCS_S) \
$(LIBC_RAND_A_SRCS_C)
LIBC_RAND_A_OBJS = \
$(LIBC_RAND_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(LIBC_RAND_A_SRCS_C:%.c=o/$(MODE)/%.o)
LIBC_RAND_A_CHECKS = \
$(LIBC_RAND_A).pkg \
$(LIBC_RAND_A_HDRS:%=o/$(MODE)/%.ok)
LIBC_RAND_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_NT_ADVAPI32 \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV \
LIBC_SYSV_CALLS \
LIBC_TINYMATH
LIBC_RAND_A_DEPS := \
$(call uniq,$(foreach x,$(LIBC_RAND_A_DIRECTDEPS),$($(x))))
$(LIBC_RAND_A): libc/rand/ \
$(LIBC_RAND_A).pkg \
$(LIBC_RAND_A_OBJS)
$(LIBC_RAND_A).pkg: \
$(LIBC_RAND_A_OBJS) \
$(foreach x,$(LIBC_RAND_A_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/libc/rand/mt19937-64.o: private \
OVERRIDE_CFLAGS += \
-ffunction-sections
LIBC_RAND_LIBS = $(foreach x,$(LIBC_RAND_ARTIFACTS),$($(x)))
LIBC_RAND_SRCS = $(foreach x,$(LIBC_RAND_ARTIFACTS),$($(x)_SRCS))
LIBC_RAND_HDRS = $(foreach x,$(LIBC_RAND_ARTIFACTS),$($(x)_HDRS))
LIBC_RAND_CHECKS = $(foreach x,$(LIBC_RAND_ARTIFACTS),$($(x)_CHECKS))
LIBC_RAND_OBJS = $(foreach x,$(LIBC_RAND_ARTIFACTS),$($(x)_OBJS))
$(LIBC_RAND_OBJS): $(BUILD_FILES) libc/rand/rand.mk
.PHONY: o/$(MODE)/libc/rand
o/$(MODE)/libc/rand: $(LIBC_RAND_CHECKS)

View file

@ -41,7 +41,7 @@
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/struct/processmemorycounters.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/directmap.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/memtrack.internal.h"

View file

@ -20,6 +20,7 @@
#include "libc/errno.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"
int __fflush_impl(FILE *f) {

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/sysv/consts/grnd.h"
/**

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h"
@ -25,15 +24,16 @@
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/bits.h"
#include "libc/nexgen32e/kcpuids.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/nexgen32e/x86info.h"
#include "libc/nt/runtime.h"
#include "libc/rand/rand.h"
#include "libc/rand/xorshift.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/xorshift.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/sysv/consts/auxv.h"

View file

@ -11,6 +11,8 @@ extern char g_stdinbuf[BUFSIZ];
extern char g_stdoutbuf[BUFSIZ];
extern char g_stderrbuf[BUFSIZ];
hidden extern uint64_t g_rando;
int __fflush_impl(FILE *) hidden;
int __fflush_register(FILE *) hidden;
void __fflush_unregister(FILE *) hidden;

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
/**
* Returns linear congruential deterministic pseudorandom data, e.g.

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"

View file

@ -20,8 +20,8 @@
#include "libc/calls/calls.h"
#include "libc/calls/strace.internal.h"
#include "libc/errno.h"
#include "libc/rand/lcg.internal.h"
#include "libc/rand/rand.h"
#include "libc/stdio/lcg.internal.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"

View file

@ -36,7 +36,7 @@
*/
#include "libc/intrin/likely.h"
#include "libc/macros.internal.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
asm(".ident\t\"\\n\\n\
mt19937 (BSD-3)\\n\

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/internal.h"
#include "libc/rand/lcg.internal.h"
#include "libc/rand/rand.h"
#include "libc/stdio/internal.h"
#include "libc/stdio/lcg.internal.h"
#include "libc/stdio/rand.h"
/**
* Returns 31-bit linear congruential pseudorandom number, e.g.

0
libc/stdio/rand.mk Executable file
View file

View file

@ -25,7 +25,7 @@
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\

View file

@ -19,7 +19,7 @@
#include "libc/intrin/asmflag.h"
#include "libc/errno.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/sysv/consts/grnd.h"
STATIC_YOINK("rdrand_init");

View file

@ -20,7 +20,7 @@
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/nexgen32e/x86info.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
textstartup void rdrand_init(int argc, char **argv, char **envp,
intptr_t *auxv) {

View file

@ -18,7 +18,7 @@
*/
#include "libc/intrin/asmflag.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/grnd.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
/**
* Generates number on [0,1]-real-interval, e.g.

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
/**
* Generates number on [0,1)-real-interval, e.g.

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
/**
* Generates number on (0,1)-real-interval, e.g.

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
/**

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
extern uint64_t g_rando;

View file

@ -29,8 +29,8 @@ LIBC_STDIO_A_DIRECTDEPS = \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_NT_ADVAPI32 \
LIBC_NT_KERNEL32 \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_STR \
LIBC_STUBS \
@ -57,6 +57,10 @@ o//libc/stdio/appendw.o: private \
OVERRIDE_CFLAGS += \
-Os
o/$(MODE)/libc/stdio/mt19937.o: private \
OVERRIDE_CFLAGS += \
-ffunction-sections
LIBC_STDIO_LIBS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)))
LIBC_STDIO_SRCS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_SRCS))
LIBC_STDIO_HDRS = $(foreach x,$(LIBC_STDIO_ARTIFACTS),$($(x)_HDRS))

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/alg/shuffle.internal.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
/**

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
static uint64_t g_vigna;

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/xorshift.h"
#include "libc/stdio/xorshift.h"
uint32_t MarsagliaXorshift32(uint32_t state[hasatleast 1]) {
uint32_t x = state[0];

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/rand/xorshift.h"
#include "libc/stdio/xorshift.h"
uint64_t MarsagliaXorshift64(uint64_t state[hasatleast 1]) {
uint64_t x = state[0];

View file

@ -101,7 +101,6 @@ LIBC_TESTLIB_A_DIRECTDEPS = \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_NT_KERNEL32 \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/math.h"
#include "libc/rand/rand.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
/**