Get Cosmopolitan into releasable state
A new rollup tool now exists for flattening out the headers in a way that works better for our purposes than cpp. A lot of the API clutter has been removed. APIs that aren't a sure thing in terms of general recommendation are now marked internal. There's now a smoke test for the amalgamation archive and gigantic header file. So we can now guarantee you can use this project on the easiest difficulty setting without the gigantic repository. A website is being created, which is currently a work in progress: https://justine.storage.googleapis.com/cosmopolitan/index.htmlmain
parent
dba7552c1e
commit
ea0b5d9d1c
33
Makefile
33
Makefile
|
@ -187,6 +187,7 @@ include test/libc/rand/test.mk
|
|||
include test/libc/time/test.mk
|
||||
include test/libc/stdio/test.mk
|
||||
include test/libc/conv/test.mk
|
||||
include test/libc/release/test.mk
|
||||
include test/libc/test.mk
|
||||
include test/ape/lib/test.mk
|
||||
include test/ape/test.mk
|
||||
|
@ -253,8 +254,9 @@ COSMOPOLITAN_OBJECTS = \
|
|||
LIBC_CONV \
|
||||
LIBC_CRYPTO \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_ELF \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
|
@ -270,7 +272,9 @@ COSMOPOLITAN_OBJECTS = \
|
|||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_DTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
|
@ -279,22 +283,31 @@ COSMOPOLITAN_OBJECTS = \
|
|||
|
||||
COSMOPOLITAN_HEADERS = \
|
||||
LIBC \
|
||||
LIBC_ALG \
|
||||
LIBC_BITS \
|
||||
LIBC_CALLS \
|
||||
LIBC_CONV \
|
||||
LIBC_CRYPTO \
|
||||
LIBC_DNS \
|
||||
LIBC_ELF \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_NT \
|
||||
LIBC_OHMYPLUS \
|
||||
LIBC_RAND \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_SOCK \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_TIME \
|
||||
LIBC_UNICODE \
|
||||
LIBC_ZIPOS \
|
||||
LIBC_SYSV \
|
||||
LIBC_NT \
|
||||
LIBC_TIME \
|
||||
LIBC_TINYMATH \
|
||||
LIBC_UNICODE \
|
||||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_DTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
|
@ -302,11 +315,11 @@ COSMOPOLITAN_HEADERS = \
|
|||
THIRD_PARTY_REGEX
|
||||
|
||||
o/$(MODE)/cosmopolitan.a: $(filter-out o/libc/stubs/exit11.o,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_OBJS)))
|
||||
o/$(MODE)/.cosmopolitan.h: $(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))
|
||||
build/rollup $^ >$@
|
||||
o/$(MODE)/cosmopolitan.h: o/$(MODE)/.cosmopolitan.h
|
||||
build/compile $(PREPROCESS) -P $(OUTPUT_OPTION) $<
|
||||
clang-format-10 -i $@
|
||||
o/cosmopolitan.h: \
|
||||
o/$(MODE)/tool/build/rollup.com.dbg \
|
||||
libc/integral/normalize.inc \
|
||||
$(foreach x,$(COSMOPOLITAN_HEADERS),$($(x)_HDRS))
|
||||
@ACTION=ROLLUP TARGET=$@ build/do $^ >$@
|
||||
|
||||
# UNSPECIFIED PREREQUISITES TUTORIAL
|
||||
#
|
||||
|
|
67
ape/ape.S
67
ape/ape.S
|
@ -40,11 +40,10 @@
|
|||
#include "ape/notice.inc"
|
||||
#include "ape/relocations.h"
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/macho.h"
|
||||
#include "libc/nexgen32e/uart.h"
|
||||
#include "libc/nexgen32e/vidya.h"
|
||||
#include "libc/nt/pedef.h"
|
||||
#include "libc/nexgen32e/vidya.h"
|
||||
#include "libc/macho.internal.h"
|
||||
#include "libc/nexgen32e/uart.internal.h"
|
||||
#include "libc/nexgen32e/vidya.internal.h"
|
||||
#include "libc/nt/pedef.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
||||
|
@ -440,33 +439,6 @@ apmoff: mov $0x5300,%ax # apm installation check
|
|||
1: call panic
|
||||
.endfn apmoff,globl
|
||||
|
||||
/ Video put char.
|
||||
/
|
||||
/ @param al is the char
|
||||
/ @mode real
|
||||
rvputc: push %bx # don't clobber bp,bx,di,si,cx
|
||||
push %bp # original ibm pc scroll up bug
|
||||
mov $7,%bx # normal mda/cga style page zero
|
||||
mov $0x0e,%ah # teletype output al cp437
|
||||
int $0x10 # vidya service
|
||||
pop %bp # preserves al
|
||||
pop %bx
|
||||
ret
|
||||
.endfn rvputc
|
||||
|
||||
/ Video put string.
|
||||
/
|
||||
/ @param di is the string
|
||||
/ @mode real
|
||||
rvputs: mov %di,%si
|
||||
0: lodsb
|
||||
test %al,%al
|
||||
je 1f
|
||||
call rvputc
|
||||
jmp 0b
|
||||
1: ret
|
||||
.endfn rvputs,globl,hidden
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § partition table ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
@ -1267,6 +1239,33 @@ sputs: push %bx
|
|||
ret
|
||||
.endfn sputs,globl
|
||||
|
||||
/ Video put string.
|
||||
/
|
||||
/ @param di is the string
|
||||
/ @mode real
|
||||
rvputs: mov %di,%si
|
||||
0: lodsb
|
||||
test %al,%al
|
||||
je 1f
|
||||
rlcall rvputc
|
||||
jmp 0b
|
||||
1: ret
|
||||
.endfn rvputs,globl,hidden
|
||||
|
||||
/ Video put char.
|
||||
/
|
||||
/ @param al is the char
|
||||
/ @mode real
|
||||
rvputc: push %bx # don't clobber bp,bx,di,si,cx
|
||||
push %bp # original ibm pc scroll up bug
|
||||
mov $7,%bx # normal mda/cga style page zero
|
||||
mov $0x0e,%ah # teletype output al cp437
|
||||
int $0x10 # vidya service
|
||||
pop %bp # preserves al
|
||||
pop %bx
|
||||
ret
|
||||
.endfn rvputc
|
||||
|
||||
/* █ █▒
|
||||
█ █
|
||||
█▓▄ █ █
|
||||
|
@ -1613,8 +1612,8 @@ metal:
|
|||
mov $.Lape.bss.vaddr,%edi
|
||||
mov $.Lape.bss.memsz,%ecx
|
||||
rep stosb
|
||||
.weak hostos
|
||||
ezlea hostos,ax
|
||||
.weak __hostos
|
||||
ezlea __hostos,ax
|
||||
test %rax,%rax
|
||||
jz 1f
|
||||
movb $METAL,(%rax)
|
||||
|
|
|
@ -177,7 +177,7 @@
|
|||
#ifdef __LINKER__
|
||||
#include "ape/macros.h"
|
||||
#include "ape/config.h"
|
||||
#include "libc/nt/pedef.h"
|
||||
#include "libc/nt/pedef.internal.h"
|
||||
#include "libc/zip.h"
|
||||
|
||||
ENTRY(_start)
|
||||
|
|
|
@ -39,7 +39,7 @@ APE_DEPS = $(APE_LIB)
|
|||
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
|
||||
|
||||
o/ape/idata.inc: \
|
||||
ape/idata.h \
|
||||
ape/idata.internal.h \
|
||||
ape/relocations.h
|
||||
|
||||
$(APE_OBJS): $(BUILD_FILES) \
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
/**
|
||||
* PC Display Configuration (MDA/CGA)
|
||||
* @see www.lammertbies.nl/comm/info/serial-uart.html
|
||||
* @see ape/lib/vidya.h
|
||||
* @see ape/lib/vidya.internal.h
|
||||
*/
|
||||
#ifndef VIDYA_MODE
|
||||
#define VIDYA_MODE VIDYA_MODE_CGA
|
||||
|
|
|
@ -1,22 +1,3 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef APE_IDATA_H_
|
||||
#define APE_IDATA_H_
|
||||
#ifdef __ASSEMBLER__
|
|
@ -20,7 +20,7 @@
|
|||
#include "ape/config.h"
|
||||
#include "ape/lib/pc.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
|
||||
/**
|
||||
* Virtualizes physical memory.
|
||||
|
|
35
ape/macros.h
35
ape/macros.h
|
@ -1,38 +1,3 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╠──────────────────────────────────────────────────────────────────────────────╣
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀█░█▀█░▀█▀░█░█░█▀█░█░░░█░░░█░█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀█░█░▄░░█░░█░█░█▀█░█░░░█░░░▀█▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░▀░▀░▀▀▀░░▀░░▀▀▀░▀░▀░▀▀▀░▀▀▀░░▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀█░█▀█░█▀█░▀█▀░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀▀░█ █░██▀░░█░░█▀█░█▀█░█░░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░▀░░░▀▀▀░▀░▀░░▀░░▀░▀░▀▀▀░▀▀▀░▀▀▀░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│
|
||||
│░░░░░░░█▀▀░█░█░█▀▀░█▀█░█░█░▀█▀░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░░░░░░░░░░░░░▄▄░░░▐█░░│
|
||||
│░░░░░░░█▀▀░▄▀▄░█▀▀░█░▄░█░█░░█░░█▀█░█▀█░█░░█▀▀░░░░░░░░░░░░▄▄▄░░░▄██▄░░█▀░░░█░▄░│
|
||||
│░░░░░░░▀▀▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░░▀░░▀░▀░▀▀▀░▀▀░▀▀▀░░░░░░░░░░▄██▀█▌░██▄▄░░▐█▀▄░▐█▀░░│
|
||||
│░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▐█▀▀▌░░░▄▀▌░▌░█░▌░░▌░▌░░│
|
||||
╠──────────────────────────────────────────────────────▌▀▄─▐──▀▄─▐▄─▐▄▐▄─▐▄─▐▄─│
|
||||
│ αcτµαlly pδrταblε εxεcµταblε § macros │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#ifndef APE_MACROS_H_
|
||||
#define APE_MACROS_H_
|
||||
#include "libc/macros.h"
|
||||
|
|
41
ape/mtime.h
41
ape/mtime.h
|
@ -1,41 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_APE_MTIME_H_
|
||||
#define COSMOPOLITAN_APE_MTIME_H_
|
||||
#include "libc/dos.h"
|
||||
|
||||
/**
|
||||
* @fileoverview Deterministic last modified timestamp embedding.
|
||||
*/
|
||||
|
||||
#ifndef MTIME_YEAR
|
||||
#define MTIME_YEAR 2019
|
||||
#endif
|
||||
|
||||
#ifndef MTIME_MONTH
|
||||
#define MTIME_MONTH 1
|
||||
#endif
|
||||
|
||||
#ifndef MTIME_DAY
|
||||
#define MTIME_DAY 1
|
||||
#endif
|
||||
|
||||
#ifndef MTIME_HOUR
|
||||
#define MTIME_HOUR 0
|
||||
#endif
|
||||
|
||||
#ifndef MTIME_MINUTES
|
||||
#define MTIME_MINUTES 0
|
||||
#endif
|
||||
|
||||
#ifndef MTIME_SECONDS
|
||||
#define MTIME_SECONDS 0
|
||||
#endif
|
||||
|
||||
#ifndef ZIP_MTIME_DATE
|
||||
#define ZIP_MTIME_DATE DOS_DATE(MTIME_YEAR, MTIME_MONTH, MTIME_DAY)
|
||||
#endif
|
||||
|
||||
#ifndef ZIP_MTIME_TIME
|
||||
#define ZIP_MTIME_TIME DOS_TIME(MTIME_HOUR, MTIME_MINUTES, MTIME_SECONDS)
|
||||
#endif
|
||||
|
||||
#endif /* COSMOPOLITAN_APE_MTIME_H_ */
|
|
@ -383,5 +383,5 @@ TAGSFLAGS = \
|
|||
--if0=no \
|
||||
--langmap=c:.c.h.i \
|
||||
--line-directives=yes \
|
||||
--exclude=libc/nt/struct/imagefileheader.h \
|
||||
--exclude=libc/nt/struct/imagefileheader.internal.h \
|
||||
--exclude=libc/nt/struct/filesegmentelement.h
|
||||
|
|
18
build/htags
18
build/htags
|
@ -59,13 +59,13 @@ set -- --regex-c='/^extern [^(]*(\*const \([^)]*\))(/\1/b' "$@"
|
|||
# struct WorstSoftwareEver;
|
||||
set -- --regex-c='/^struct.*;$/uehocruehcroue/b' "$@"
|
||||
|
||||
exec ${TAGS:-ctags} \
|
||||
-e \
|
||||
--langmap=c:.c.h \
|
||||
--exclude=libc/nt/struct/imagefileheader.h \
|
||||
--exclude=libc/nt/struct/imageseparatedebugheader.h \
|
||||
--exclude=libc/nt/struct/importobjectheader.h \
|
||||
--exclude=libc/nt/struct/nonpageddebuginfo.h \
|
||||
--exclude=libc/nt/struct/ansistring.h \
|
||||
--exclude=libc/nt/struct/filesegmentelement.h \
|
||||
exec ${TAGS:-ctags} \
|
||||
-e \
|
||||
--langmap=c:.c.h \
|
||||
--exclude=libc/nt/struct/imagefileheader.internal.h \
|
||||
--exclude=libc/nt/struct/imageseparatedebugheader.internal.h \
|
||||
--exclude=libc/nt/struct/importobjectheader.h \
|
||||
--exclude=libc/nt/struct/nonpageddebuginfo.h \
|
||||
--exclude=libc/nt/struct/ansistring.h \
|
||||
--exclude=libc/nt/struct/filesegmentelement.h \
|
||||
"$@"
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
double rgb2stdpc(double x, double g) {
|
||||
return COMPANDLUMA_SRGB(x, g);
|
||||
}
|
||||
|
||||
double rgb2linpc(double x, double g) {
|
||||
return UNCOMPANDLUMA_SRGB(x, g);
|
||||
}
|
||||
|
@ -31,6 +32,7 @@ double rgb2linpc(double x, double g) {
|
|||
double rgb2stdtv(double x) {
|
||||
return COMPANDLUMA_BT1886(x);
|
||||
}
|
||||
|
||||
double rgb2lintv(double x) {
|
||||
return UNCOMPANDLUMA_BT1886(x);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/core/core.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
|
||||
/**
|
||||
|
@ -43,7 +43,7 @@ void scalevolume(size_t n, int16_t pcm[n][8], int p) {
|
|||
if (p > 15) p = 15;
|
||||
for (i = 0; i < n; ++i) {
|
||||
for (j = 0; j < 8; ++j) {
|
||||
pcm[i][j] = SAR(pcm[i][j], p);
|
||||
pcm[i][j] = pcm[i][j] >> p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "dsp/mpeg/idct.h"
|
||||
#include "dsp/mpeg/mpeg.h"
|
||||
#include "dsp/mpeg/video.h"
|
||||
#include "libc/bits/initializer.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
|
|
|
@ -40,8 +40,8 @@
|
|||
signed char g_magikarp[8];
|
||||
const signed char kMagikarp[8][8] = {
|
||||
{-1, -3, 3, 17, 17, 3, -3, -1}, /* 1331+161 derived w/ one off cas */
|
||||
{-1, -3, 6, 28, 6, -3, -1, 0}, /* due to the convolution theorem? */
|
||||
{0, 0, -11, 53, -11, 0, 0, 0}, /* plus, some random experimenting */
|
||||
{-1, -3, 6, 28, 6, -3, -1, 0}, /* no due to the convolution theorem? */
|
||||
{0, 0, -11, 53, -11, 0, 0, 0}, /* no plus, some random experimenting */
|
||||
{-2, -6, 2, 22, 22, 2, -6, -2}, /* one a line please clang-format? */
|
||||
{-3, -9, 1, 27, 27, 1, -9, -3},
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/termios.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_DSP_TTY_INTERNAL_H_
|
||||
#define COSMOPOLITAN_DSP_TTY_INTERNAL_H_
|
||||
#include "dsp/tty/ttyrgb.h"
|
||||
#include "libc/bits/xmmintrin.h"
|
||||
#include "libc/bits/xmmintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/itoa8.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/initializer.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
struct Itoa8 kItoa8;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "dsp/tty/ttyrgb.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/xmmintrin.h"
|
||||
#include "libc/bits/xmmintrin.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/str/str.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "dsp/core/core.h"
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/initializer.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/bits/xmmintrin.h"
|
||||
#include "libc/bits/xmmintrin.internal.h"
|
||||
|
||||
struct TtyRgb rgb2ttyf2i_(__m128 rgb) {
|
||||
__v4si i4;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/itoa8.h"
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/internal.h"
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/bits/initializer.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "dsp/tty/windex.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
* @see examples and reference material on using the asm() keyword
|
||||
* - libc/nexgen32e/bsf.h
|
||||
* - libc/nexgen32e/tzcnt.h
|
||||
* - libc/nexgen32e/cpuid4.h
|
||||
* - libc/nexgen32e/tinystrcmp.h
|
||||
* - libc/nexgen32e/cpuid4.internal.h
|
||||
* - libc/nexgen32e/tinystrcmp.internal.h
|
||||
* - https://gist.github.com/jart/fe8d104ef93149b5ba9b72912820282c
|
||||
*/
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
showcrashreports();
|
||||
asm("int3"); /* cf. die(), perror("msg"), abort(), exit(1), _Exit(1) */
|
||||
asm("int3"); /* cf. __die(), perror("msg"), abort(), exit(1), _Exit(1) */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/backtrace.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
/*
|
||||
|
||||
Your executables will try to find the addr2line tool, which is needed
|
||||
to decrypt gcc debug information, enabling backtraces like this:
|
||||
|
||||
0x0000000000403a7a: Hello at examples/backtrace.c:31
|
||||
0x0000000000403ac3: World at examples/backtrace.c:38
|
||||
0x0000000000401608: main at examples/backtrace.c:42
|
||||
0x0000000000401379: _start at libc/crt/crt.S:61
|
||||
|
||||
If that doesn't work, then your αcτµαlly pδrταblε εxεcµταblε will use
|
||||
its own builtin fallback solution:
|
||||
|
||||
0000ac2fa7e0 000000403a9b Hello+0x49
|
||||
0000ac2fa7f0 000000403ac4 World+0x22
|
||||
0000ac2fa800 000000401609 main+0x7
|
||||
0000ac2fa810 00000040137a _start+0x63
|
||||
|
||||
This is guaranteed to work if the .com.dbg file can be found.
|
||||
Otherwise it'll print numbers:
|
||||
|
||||
0000268a8390 000000403a90 (null)+0x403a8f
|
||||
0000268a83a0 000000403aef (null)+0x403aee
|
||||
0000268a83b0 0000004015fe (null)+0x4015fd
|
||||
0000268a83c0 00000040137a (null)+0x401379
|
||||
|
||||
*/
|
||||
|
||||
void hello(void) {
|
||||
gc(malloc(1));
|
||||
ShowBacktrace(STDOUT_FILENO, NULL);
|
||||
setenv("ADDR2LINE", "", true);
|
||||
ShowBacktrace(STDOUT_FILENO, NULL);
|
||||
}
|
||||
|
||||
void world(void) {
|
||||
gc(malloc(1));
|
||||
hello();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
world();
|
||||
return 0;
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
@ -31,9 +31,15 @@ class Log {
|
|||
int *x_;
|
||||
};
|
||||
|
||||
Log::Log() { x_ = new int[64]; }
|
||||
Log::~Log() { delete x_; }
|
||||
int *Log::x() { return x_; }
|
||||
Log::Log() {
|
||||
x_ = new int[64];
|
||||
}
|
||||
Log::~Log() {
|
||||
delete x_;
|
||||
}
|
||||
int *Log::x() {
|
||||
return x_;
|
||||
}
|
||||
|
||||
class Log g_log;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/color.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "dsp/scale/scale.h"
|
||||
#include "dsp/tty/itoa8.h"
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/ioctl.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "libc/conv/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/color.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/nt/enum/messageboxtype.h"
|
||||
#include "libc/nt/enum/mb.h"
|
||||
#include "libc/nt/messagebox.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist.h"
|
||||
#include "libc/alg/arraylist.internal.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/conv/conv.h"
|
||||
|
@ -18,7 +19,7 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/tpdecode.h"
|
||||
#include "libc/str/tpdecode.internal.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ Contact: antirez@gmail.com\"\n\
|
|||
#define _GNU_SOURCE
|
||||
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/termios.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
#include "dsp/tty/itoa8.h"
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "dsp/tty/tty.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/hefty/spawn.h"
|
||||
#include "libc/calls/struct/itimerval.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/elf/elf.h"
|
||||
#include "libc/log/backtrace.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/runtime/symbols.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int rc = 0;
|
||||
char *filename;
|
||||
struct SymbolTable *tab = NULL;
|
||||
if ((filename = FindDebugBinary()) != NULL &&
|
||||
(tab = OpenSymbolTable(filename))) {
|
||||
for (unsigned i = 0; i < tab->count; ++i) {
|
||||
printf("%p %s\n", tab->addr_base + tab->symbols[i].addr_rva,
|
||||
GetElfString(tab->elf, tab->elfsize, tab->name_base,
|
||||
tab->symbols[i].name_rva));
|
||||
}
|
||||
} else {
|
||||
perror("printmysymbols");
|
||||
ShowBacktrace(STDERR_FILENO, NULL);
|
||||
rc = 1;
|
||||
}
|
||||
CloseSymbolTable(&tab);
|
||||
return rc;
|
||||
}
|
|
@ -12,7 +12,7 @@ void *bsearch(const void *, const void *, size_t, size_t,
|
|||
void *bsearch_r(const void *, const void *, size_t, size_t,
|
||||
int cmp(const void *, const void *, void *), void *)
|
||||
paramsnonnull((1, 2, 5)) nothrow nosideeffect;
|
||||
void djbsort(size_t n, int32_t[n]);
|
||||
void djbsort(int32_t *, size_t);
|
||||
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
|
||||
paramsnonnull();
|
||||
void qsort_r(void *, size_t, size_t,
|
||||
|
@ -43,72 +43,14 @@ char16_t *concatstr16(const char16_t *, ...) nullterminated()
|
|||
wchar_t *concatwcs(const wchar_t *, ...) nullterminated()
|
||||
paramsnonnull() __algalloc;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § algorithms » containers ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
struct critbit0 {
|
||||
void *root;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
bool critbit0_contains(struct critbit0 *, const char *) nothrow nosideeffect
|
||||
paramsnonnull();
|
||||
bool critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
|
||||
bool critbit0_delete(struct critbit0 *, const char *) nothrow paramsnonnull();
|
||||
void critbit0_clear(struct critbit0 *) nothrow paramsnonnull();
|
||||
char *critbit0_get(struct critbit0 *, const char *);
|
||||
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
|
||||
intptr_t (*)(const char *, void *), void *)
|
||||
paramsnonnull((1, 2, 3)) nothrow;
|
||||
bool critbit0_emplace(struct critbit0 *, char *, size_t) paramsnonnull();
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § algorithms » comparators ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
int cmpsb(/*const signed char[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpub(/*const unsigned char[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpsw(/*const signed short[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpuw(/*const unsigned short[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpsl(/*const signed int[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpul(/*const unsigned int[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpsq(/*const signed long[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
int cmpuq(/*const unsigned long[1]*/ const void *, const void *)
|
||||
paramsnonnull() nothrow nocallback nosideeffect;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § algorithms » generics ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
#if __STDC_VERSION__ + 0 >= 201112
|
||||
|
||||
#define memmem(haystack, haystacklen, needle, needlelen) \
|
||||
_Generic(*(haystack), wchar_t \
|
||||
: wmemmem, char16_t \
|
||||
: memmem16, default \
|
||||
: memmem)(haystack, haystacklen, needle, needlelen)
|
||||
|
||||
#define replacestr(s, needle, replacement) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: replacewcs, char16_t \
|
||||
: replacestr16, default \
|
||||
: replacestr)(s, needle, replacement)
|
||||
|
||||
#define concatstr(s, ...) \
|
||||
_Generic(*(s), wchar_t \
|
||||
: concatwcs, char16_t \
|
||||
: concatstr16, default \
|
||||
: concatstr)(s, __VA_ARGS__)
|
||||
|
||||
#endif /* C11 */
|
||||
int cmpsb(const void *, const void *);
|
||||
int cmpub(const void *, const void *);
|
||||
int cmpsw(const void *, const void *);
|
||||
int cmpuw(const void *, const void *);
|
||||
int cmpsl(const void *, const void *);
|
||||
int cmpul(const void *, const void *);
|
||||
int cmpsq(const void *, const void *);
|
||||
int cmpuq(const void *, const void *);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -28,20 +28,20 @@
|
|||
|
||||
#define append(ARRAYLIST, ITEM) concat((ARRAYLIST), (ITEM), 1)
|
||||
|
||||
#define concat(ARRAYLIST, ITEM, COUNT) \
|
||||
({ \
|
||||
autotype(ARRAYLIST) List = (ARRAYLIST); \
|
||||
autotype(&List->p[0]) Item = (ITEM); \
|
||||
size_t SizE = sizeof(*Item); \
|
||||
size_t Count = (COUNT); \
|
||||
size_t Idx = List->i; \
|
||||
if (Idx + Count < List->n || grow(&List->p, &List->n, SizE, Count)) { \
|
||||
memcpy(&List->p[Idx], Item, SizE *Count); \
|
||||
atomic_store(&List->i, Idx + Count); \
|
||||
} else { \
|
||||
Idx = -1UL; \
|
||||
} \
|
||||
(ssize_t)(Idx); \
|
||||
#define concat(ARRAYLIST, ITEM, COUNT) \
|
||||
({ \
|
||||
autotype(ARRAYLIST) List = (ARRAYLIST); \
|
||||
autotype(&List->p[0]) Item = (ITEM); \
|
||||
size_t SizE = sizeof(*Item); \
|
||||
size_t Count = (COUNT); \
|
||||
size_t Idx = List->i; \
|
||||
if (Idx + Count < List->n || __grow(&List->p, &List->n, SizE, Count)) { \
|
||||
memcpy(&List->p[Idx], Item, SizE *Count); \
|
||||
atomic_store(&List->i, Idx + Count); \
|
||||
} else { \
|
||||
Idx = -1UL; \
|
||||
} \
|
||||
(ssize_t)(Idx); \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
@ -10,26 +10,26 @@ COSMOPOLITAN_C_START_
|
|||
#define APPEND(LIST_P, LIST_I, LIST_N, ITEM) \
|
||||
CONCAT(LIST_P, LIST_I, LIST_N, ITEM, 1)
|
||||
|
||||
#define CONCAT(LIST_P, LIST_I, LIST_N, ITEM, COUNT) \
|
||||
({ \
|
||||
autotype(LIST_P) ListP = (LIST_P); \
|
||||
autotype(LIST_I) ListI = (LIST_I); \
|
||||
autotype(LIST_N) ListN = (LIST_N); \
|
||||
typeof(&(*ListP)[0]) Item = (ITEM); \
|
||||
size_t SizE = sizeof(*Item); \
|
||||
size_t Count = (COUNT); \
|
||||
ssize_t Entry = -1; \
|
||||
/* NOTE: We use `<` to guarantee one additional slot */ \
|
||||
/* grow() will memset(0) extended memory, thus */ \
|
||||
/* you get a nul-terminator for free sometimes */ \
|
||||
/* the exception is if you list.i=0 and re-use */ \
|
||||
/* so you need concat(...); list.p[list.i++]=0 */ \
|
||||
if (*ListI + Count < *ListN || grow(ListP, ListN, SizE, Count)) { \
|
||||
memcpy(&(*ListP)[*ListI], Item, (SizE) * (Count)); \
|
||||
Entry = *ListI; \
|
||||
*ListI += Count; /* happens after copy in case signal */ \
|
||||
} \
|
||||
Entry; \
|
||||
#define CONCAT(LIST_P, LIST_I, LIST_N, ITEM, COUNT) \
|
||||
({ \
|
||||
autotype(LIST_P) ListP = (LIST_P); \
|
||||
autotype(LIST_I) ListI = (LIST_I); \
|
||||
autotype(LIST_N) ListN = (LIST_N); \
|
||||
typeof(&(*ListP)[0]) Item = (ITEM); \
|
||||
size_t SizE = sizeof(*Item); \
|
||||
size_t Count = (COUNT); \
|
||||
ssize_t Entry = -1; \
|
||||
/* NOTE: We use `<` to guarantee one additional slot */ \
|
||||
/* grow() will memset(0) extended memory, thus */ \
|
||||
/* you get a nul-terminator for free sometimes */ \
|
||||
/* the exception is if you list.i=0 and re-use */ \
|
||||
/* so you need concat(...); list.p[list.i++]=0 */ \
|
||||
if (*ListI + Count < *ListN || __grow(ListP, ListN, SizE, Count)) { \
|
||||
memcpy(&(*ListP)[*ListI], Item, (SizE) * (Count)); \
|
||||
Entry = *ListI; \
|
||||
*ListI += Count; /* happens after copy in case signal */ \
|
||||
} \
|
||||
Entry; \
|
||||
})
|
||||
|
||||
COSMOPOLITAN_C_END_
|
|
@ -3,13 +3,8 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/**
|
||||
* Floor binary search of low 32-bits of 64-bit array items.
|
||||
*
|
||||
* This is well-suited to NexGen-32e, requiring less than 32 bytes of
|
||||
* code. It's particularly useful for frozen maps, requiring less effort
|
||||
* and memory than a perfect hash table.
|
||||
*/
|
||||
/* TODO: DELETE */
|
||||
|
||||
forceinline int32_t bisectcarleft(const int32_t (*cons)[2], size_t count,
|
||||
const int32_t key) {
|
||||
size_t left = 0;
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_
|
||||
#define COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
forceinline size_t bisectleft(const void *key, const void *base, size_t count,
|
||||
size_t sz, int cmp(const void *, const void *)) {
|
||||
size_t m, l, r;
|
||||
l = 0;
|
||||
r = count;
|
||||
while (l < r) {
|
||||
m = (l + r) >> 1;
|
||||
if (cmp((char *)base + m * sz, key) < 0) {
|
||||
l = m + 1;
|
||||
} else {
|
||||
r = m;
|
||||
}
|
||||
}
|
||||
if (l && (l == count || cmp((char *)base + l * sz, key) > 0)) {
|
||||
l--;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ */
|
|
@ -1,26 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_
|
||||
#define COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
forceinline size_t bisectright(const void *key, const void *base, size_t count,
|
||||
size_t sz, int cmp(const void *, const void *)) {
|
||||
size_t left = 0;
|
||||
size_t right = count;
|
||||
while (left < right) {
|
||||
size_t m = (right + right) >> 1;
|
||||
if (cmp((char *)base + m * sz, key) > 0) {
|
||||
right = m + 1;
|
||||
} else {
|
||||
right = m;
|
||||
}
|
||||
}
|
||||
if (right && (right == count || cmp((char *)base + right * sz, key) > 0)) {
|
||||
right--;
|
||||
}
|
||||
return right;
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ */
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/bisect.h"
|
||||
#include "libc/alg/bisect.internal.h"
|
||||
|
||||
/**
|
||||
* Searches sorted array for exact item in logarithmic time.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/bisect.h"
|
||||
#include "libc/alg/bisect.internal.h"
|
||||
|
||||
/**
|
||||
* Searches sorted array for exact item in logarithmic time.
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
|
||||
#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § data structures » critical bit tree (for c strings) ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
struct critbit0 {
|
||||
void *root;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
bool critbit0_contains(struct critbit0 *, const char *) nothrow nosideeffect
|
||||
paramsnonnull();
|
||||
bool critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
|
||||
bool critbit0_delete(struct critbit0 *, const char *) nothrow paramsnonnull();
|
||||
void critbit0_clear(struct critbit0 *) nothrow paramsnonnull();
|
||||
char *critbit0_get(struct critbit0 *, const char *);
|
||||
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
|
||||
intptr_t (*)(const char *, void *), void *)
|
||||
paramsnonnull((1, 2, 3)) nothrow;
|
||||
bool critbit0_emplace(struct critbit0 *, char *, size_t) paramsnonnull();
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_ */
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/critbit0.h"
|
||||
#include "libc/alg/internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_ALG_INSERTIONSORT_H_
|
||||
#define COSMOPOLITAN_LIBC_ALG_INSERTIONSORT_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define siftbackwards(C, X, V, i) \
|
||||
do { \
|
||||
autotype(V) V_ = (V); \
|
||||
for (autotype(i) j = (i); j && C(&V_[j - 1], &V_[j]) > 0; --j) { \
|
||||
X(&V_[j - 1], &V_[j]); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Tiny in-place quadratic sorting algorithm.
|
||||
*
|
||||
* The only advantage to insertion sort is saving on code size when
|
||||
* there's a strong level of certainty the array won't have more than
|
||||
* sixteen items. Sometimes Insertion Sort is favored for sorting data
|
||||
* that's almost sorted. SmoothSort should be a better choice (see
|
||||
* qsort()) since it has that advantage and a linearithmic worst-case.
|
||||
*/
|
||||
#endif
|
||||
#define INSERTIONSORT(C, X, A, n) \
|
||||
do { \
|
||||
autotype(A) A_ = (A); \
|
||||
autotype(n) n_ = (n); \
|
||||
for (autotype(n) i = 1; i < n_; ++i) { \
|
||||
siftbackwards(C, X, A_, i); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_ALG_INSERTIONSORT_H_ */
|
|
@ -18,8 +18,8 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
|
|
|
@ -18,14 +18,15 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/alg/arraylist2.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/alg/arraylist2.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#undef strlen
|
||||
#undef replacestr
|
||||
#define replacestr replacestr16
|
||||
#define memmem memmem16
|
||||
#define char char16_t
|
||||
#define strlen strlen16
|
||||
#include "libc/alg/replacestr.c"
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "libc/bits/xchg.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Reverses array.
|
||||
*
|
||||
|
@ -12,7 +11,6 @@
|
|||
* @return pointer to start of array
|
||||
* @see ARRAYLEN()
|
||||
*/
|
||||
#endif
|
||||
#define reverse(ARRAY, COUNT) \
|
||||
({ \
|
||||
autotype(&(ARRAY)[0]) Array = (ARRAY); \
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#include "libc/bits/xchg.h"
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Fisher-Yates shuffle.
|
||||
*
|
||||
|
@ -12,7 +11,6 @@
|
|||
* @param n is the number of items in A
|
||||
* @see ARRAYLEN()
|
||||
*/
|
||||
#endif
|
||||
#define shuffle(R, A, n) \
|
||||
do { \
|
||||
autotype(A) Array = (A); \
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_AVX2INTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_AVX2INTRIN_H_
|
||||
#include "libc/bits/avxintrin.h"
|
||||
#include "libc/bits/avxintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_BIGWORD_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_BIGWORD_H_
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Let BIGWORD be the the number of bytes in the largest cpu register
|
||||
* available within the instruction set architecture requirements chosen
|
||||
* at compile-time.
|
||||
*
|
||||
* In plainer terms, if you tune with flags like -mavx, you're not just
|
||||
* giving the compiler permission to generate code that's incompatible
|
||||
* with older computers; you're also asking Cosmopolitan to systemically
|
||||
* change alignment, vectoring, buffering, ABIs, memory allocation, etc.
|
||||
*/
|
||||
#endif
|
||||
#ifndef BIGWORD
|
||||
#if __AVX512F__ + 0
|
||||
#define BIGWORD 64
|
||||
#elif __AVX2__ + 0
|
||||
#define BIGWORD 32
|
||||
#elif __SSE2__ + 0
|
||||
#define BIGWORD 16
|
||||
#else
|
||||
#define BIGWORD __BIGGEST_ALIGNMENT__
|
||||
#endif
|
||||
#endif /*BIGWORD*/
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ */
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_BIGWORD_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_BIGWORD_H_
|
||||
|
||||
#ifndef BIGWORD
|
||||
#if __AVX512F__ + 0
|
||||
#define BIGWORD 64
|
||||
#elif __AVX2__ + 0
|
||||
#define BIGWORD 32
|
||||
#elif __SSE2__ + 0
|
||||
#define BIGWORD 16
|
||||
#else
|
||||
#define BIGWORD __BIGGEST_ALIGNMENT__
|
||||
#endif
|
||||
#endif /*BIGWORD*/
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_BIGWORD_H_ */
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -17,15 +17,8 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/bits/bits.h"
|
||||
|
||||
bitreverse16:
|
||||
push %rbx
|
||||
mov %edi,%eax
|
||||
mov $kReverseBits,%ebx
|
||||
xlat
|
||||
xchg %al,%ah
|
||||
xlat
|
||||
pop %rbx
|
||||
ret
|
||||
.endfn bitreverse16,globl
|
||||
uint16_t(bitreverse16)(uint16_t x) {
|
||||
return kReverseBits[x & 0x00FF] << 8 | kReverseBits[(x & 0xFF00) >> 8];
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
|
@ -17,15 +17,8 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/bits/bits.h"
|
||||
|
||||
bitreverse8:
|
||||
.leafprologue
|
||||
.profilable
|
||||
push %rbx
|
||||
mov %edi,%eax
|
||||
mov $kReverseBits,%ebx
|
||||
xlat
|
||||
pop %rbx
|
||||
.leafepilogue
|
||||
.endfn bitreverse8,globl
|
||||
uint8_t(bitreverse8)(uint8_t x) {
|
||||
return kReverseBits[x];
|
||||
}
|
|
@ -9,42 +9,26 @@ COSMOPOLITAN_C_START_
|
|||
│ cosmopolitan § bits ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
extern const bool kTrue;
|
||||
extern const bool kFalse;
|
||||
extern const uint8_t kReverseBits[256];
|
||||
|
||||
uint32_t gray(uint32_t) pureconst;
|
||||
uint32_t ungray(uint32_t) pureconst;
|
||||
unsigned bcdadd(unsigned, unsigned) pureconst;
|
||||
unsigned long bcd2i(unsigned long) pureconst;
|
||||
unsigned long i2bcd(unsigned long) pureconst;
|
||||
void bcxcpy(unsigned char (*)[16], unsigned long);
|
||||
int ffs(int) pureconst;
|
||||
int ffsl(long int) pureconst;
|
||||
int ffsll(long long int) pureconst;
|
||||
int fls(int) pureconst;
|
||||
int flsl(long int) pureconst;
|
||||
int flsll(long long int) pureconst;
|
||||
|
||||
uint8_t bitreverse8(uint8_t) libcesque pureconst;
|
||||
uint16_t bitreverse16(uint16_t) libcesque pureconst;
|
||||
uint32_t bitreverse32(uint32_t) libcesque pureconst;
|
||||
uint64_t bitreverse64(uint64_t) libcesque pureconst;
|
||||
|
||||
unsigned long roundup2pow(unsigned long) libcesque pureconst;
|
||||
unsigned long roundup2log(unsigned long) libcesque pureconst;
|
||||
unsigned long rounddown2pow(unsigned long) libcesque pureconst;
|
||||
|
||||
unsigned long hamming(unsigned long, unsigned long) pureconst;
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § bits » no assembly required ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
/**
|
||||
* Undocumented incantations for ROR, ROL, and SAR.
|
||||
*/
|
||||
#define ROR(w, k) (CheckUnsigned(w) >> (k) | (w) << (sizeof(w) * 8 - (k)))
|
||||
#define ROL(w, k) ((w) << (k) | CheckUnsigned(w) >> (sizeof(w) * 8 - (k)))
|
||||
#define SAR(w, k) (((w) & ~(~0u >> (k))) | ((w) >> ((k) & (sizeof(w) * 8 - 1))))
|
||||
|
||||
#define bitreverse8(X) (kReverseBits[(uint8_t)(X)])
|
||||
#define bitreverse16(X) \
|
||||
((uint16_t)kReverseBits[(uint8_t)(X)] << 010 | \
|
||||
|
@ -253,49 +237,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
|
|||
Val; \
|
||||
})
|
||||
|
||||
/**
|
||||
* Returns true if bit is set in memory.
|
||||
*
|
||||
* This is a generically-typed Bitset<T> ∀ RAM. This macro is intended
|
||||
* to be container-like with optimal machine instruction encoding, cf.
|
||||
* machine-agnostic container abstractions. Memory accesses are words.
|
||||
* Register allocation can be avoided if BIT is known. Be careful when
|
||||
* casting character arrays since that should cause a page fault.
|
||||
*
|
||||
* @param MEM is uint𝑘_t[] where 𝑘 ∈ {16,32,64} base address
|
||||
* @param BIT ∈ [-(2**(𝑘-1)),2**(𝑘-1)) is zero-based index
|
||||
* @return true if bit is set, otherwise false
|
||||
* @see Intel's Six Thousand Page Manual V.2A 3-113
|
||||
* @see bts(), btr(), btc()
|
||||
*/
|
||||
#define bt(MEM, BIT) \
|
||||
({ \
|
||||
bool OldBit; \
|
||||
if (isconstant(BIT)) { \
|
||||
asm(CFLAG_ASM("bt%z1\t%2,%1") \
|
||||
: CFLAG_CONSTRAINT(OldBit) \
|
||||
: "m"((MEM)[(BIT) / (sizeof((MEM)[0]) * CHAR_BIT)]), \
|
||||
"J"((BIT) % (sizeof((MEM)[0]) * CHAR_BIT)) \
|
||||
: "cc"); \
|
||||
} else if (sizeof((MEM)[0]) == 2) { \
|
||||
asm(CFLAG_ASM("bt\t%w2,%1") \
|
||||
: CFLAG_CONSTRAINT(OldBit) \
|
||||
: "m"((MEM)[0]), "r"(BIT) \
|
||||
: "cc"); \
|
||||
} else if (sizeof((MEM)[0]) == 4) { \
|
||||
asm(CFLAG_ASM("bt\t%k2,%1") \
|
||||
: CFLAG_CONSTRAINT(OldBit) \
|
||||
: "m"((MEM)[0]), "r"(BIT) \
|
||||
: "cc"); \
|
||||
} else if (sizeof((MEM)[0]) == 8) { \
|
||||
asm(CFLAG_ASM("bt\t%q2,%1") \
|
||||
: CFLAG_CONSTRAINT(OldBit) \
|
||||
: "m"((MEM)[0]), "r"(BIT) \
|
||||
: "cc"); \
|
||||
} \
|
||||
OldBit; \
|
||||
})
|
||||
|
||||
#define bts(MEM, BIT) __BitOp("bts", BIT, MEM) /** bit test and set */
|
||||
#define btr(MEM, BIT) __BitOp("btr", BIT, MEM) /** bit test and reset */
|
||||
#define btc(MEM, BIT) __BitOp("btc", BIT, MEM) /** bit test and complement */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_EMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_EMMINTRIN_H_
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/bits/xmmintrin.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/xmmintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
@ -17,14 +17,8 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
|
||||
uint32_t gray(uint32_t x) { return x ^ (x >> 1); }
|
||||
|
||||
uint32_t ungray(uint32_t x) {
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
x ^= x >> 4;
|
||||
x ^= x >> 2;
|
||||
x ^= x >> 1;
|
||||
return x;
|
||||
uint32_t gray(uint32_t x) {
|
||||
return x ^ (x >> 1);
|
||||
}
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 sw=8 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Converts integer to binary-coded decimal.
|
||||
i2bcd: .leafprologue
|
||||
.profilable
|
||||
test %rdi,%rdi
|
||||
je 2f
|
||||
mov %rdi,%rsi
|
||||
xor %r9d,%r9d
|
||||
mov $0xcccccccccccccccd,%r8
|
||||
xor %ecx,%ecx
|
||||
1: mov %rsi,%rax
|
||||
mul %r8
|
||||
shr $3,%rdx
|
||||
lea (%rdx,%rdx),%rax
|
||||
lea (%rax,%rax,4),%rax
|
||||
mov %rsi,%rdi
|
||||
sub %rax,%rdi
|
||||
shl %cl,%rdi
|
||||
add %rdi,%r9
|
||||
add $4,%rcx
|
||||
cmp $9,%rsi
|
||||
mov %rdx,%rsi
|
||||
ja 1b
|
||||
jmp 3f
|
||||
2: xor %r9d,%r9d
|
||||
3: mov %r9,%rax
|
||||
.leafepilogue
|
||||
.endfn i2bcd,globl
|
|
@ -2,6 +2,8 @@
|
|||
#define COSMOPOLITAN_LIBC_BITS_INITIALIZER_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/* TODO: DELETE */
|
||||
|
||||
/**
|
||||
* Teleports code fragment inside _init().
|
||||
*/
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_SHAINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_SHAINTRIN_H_
|
||||
#include "libc/bits/emmintrin.h"
|
||||
#include "libc/bits/xmmintrin.h"
|
||||
#include "libc/bits/emmintrin.internal.h"
|
||||
#include "libc/bits/xmmintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define _mm_sha1rnds4_epu32(M128I_0, M128I_1, MEM) \
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_TMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_TMMINTRIN_H_
|
||||
#include "libc/bits/emmintrin.h"
|
||||
#include "libc/bits/emmintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
|
@ -1,14 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_TYPECHECK_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_TYPECHECK_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define TYPECHECK(T, X) \
|
||||
({ \
|
||||
T Lol1; \
|
||||
typeof(X) Lol2; \
|
||||
(void)(&Lol1 == &Lol2); \
|
||||
X; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_BITS_TYPECHECK_H_ */
|
|
@ -17,16 +17,13 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/dos.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/bits/bits.h"
|
||||
|
||||
TEST(DosDateTimeToUnix, test) {
|
||||
EXPECT_EQ(1601929396,
|
||||
DosDateTimeToUnix(DOS_DATE(2020, 10, 5), DOS_TIME(20, 23, 16)));
|
||||
}
|
||||
|
||||
TEST(DosDateTimeToUnix, testNotLeapYear) {
|
||||
EXPECT_EQ(4107529396,
|
||||
DosDateTimeToUnix(DOS_DATE(2100, 2, 28), DOS_TIME(20, 23, 16)));
|
||||
uint32_t ungray(uint32_t x) {
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
x ^= x >> 4;
|
||||
x ^= x >> 2;
|
||||
x ^= x >> 1;
|
||||
return x;
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
|
||||
/**
|
||||
* Subtracts unsigned integers w/ wraparound.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_WMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_WMMINTRIN_H_
|
||||
#include "libc/bits/emmintrin.h"
|
||||
#include "libc/bits/emmintrin.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define _mm_clmulepi64_si128(X, Y, IMM) \
|
|
@ -1,8 +1,8 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
|
||||
#define COSMOPOLITAN_LIBC_BITS_XMMINTRIN_H_
|
||||
#include "libc/bits/emmintrin.h"
|
||||
#include "libc/bits/mmintrin.h"
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/bits/emmintrin.internal.h"
|
||||
#include "libc/bits/mmintrin.internal.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
||||
#define _MM_EXCEPT_MASK 0x003f
|
|
@ -226,7 +226,6 @@ uint32_t getsid(int) nosideeffect;
|
|||
uint32_t gettid(void) nosideeffect;
|
||||
uint32_t getuid(void) nosideeffect;
|
||||
uint32_t umask(int32_t);
|
||||
void *getprocaddressmodule(const char *, const char *);
|
||||
|
||||
#define getcwd(BUF, SIZE) \
|
||||
(isconstant(BUF) && (&(BUF)[0] == NULL) ? get_current_dir_name() \
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
|
|
|
@ -17,14 +17,13 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/nt/ntdll.h"
|
||||
#include "libc/runtime/missioncritical.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/errno.h"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/enum/filemapflags.h"
|
||||
#include "libc/nt/enum/pageflags.h"
|
||||
#include "libc/nt/memory.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/conv/conv.h"
|
||||
|
@ -32,8 +32,8 @@
|
|||
#include "libc/sysv/consts/s.h"
|
||||
|
||||
textwindows int fstat$nt(int64_t handle, struct stat *st) {
|
||||
int filetype;
|
||||
uint64_t actualsize;
|
||||
enum NtFileType filetype;
|
||||
struct NtByHandleFileInformation wst;
|
||||
struct NtFileCompressionInfo fci;
|
||||
if (GetFileInformationByHandle(handle, &wst)) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/initializer.h"
|
||||
#include "libc/bits/initializer.internal.h"
|
||||
#include "libc/bits/pushpop.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
|
|
|
@ -22,21 +22,20 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/runtime/missioncritical.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
static int g_pid;
|
||||
|
||||
static void __updatepid(void) {
|
||||
g_pid = __getpid();
|
||||
static int __get_pid(void) {
|
||||
if (!IsWindows()) {
|
||||
return getpid$sysv();
|
||||
} else {
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
}
|
||||
|
||||
int __getpid(void) {
|
||||
if (!IsWindows()) {
|
||||
return GETPID();
|
||||
} else {
|
||||
return NtGetPid();
|
||||
}
|
||||
static void __update_pid(void) {
|
||||
g_pid = __get_pid();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,8 +45,8 @@ int __getpid(void) {
|
|||
int getpid(void) {
|
||||
static bool once;
|
||||
if (!once) {
|
||||
__updatepid();
|
||||
atfork(__updatepid, NULL);
|
||||
__update_pid();
|
||||
atfork(__update_pid, NULL);
|
||||
once = true;
|
||||
}
|
||||
return g_pid;
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/kntprioritycombos.h"
|
||||
#include "libc/calls/kntprioritycombos.internal.h"
|
||||
#include "libc/conv/conv.h"
|
||||
#include "libc/nexgen32e/ffs.h"
|
||||
#include "libc/nt/enum/processcreationflags.h"
|
||||
#include "libc/nt/enum/threadpriority.h"
|
||||
#include "libc/nt/process.h"
|
||||
|
|
|
@ -17,12 +17,12 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/nt/dll.h"
|
||||
#include "libc/calls/calls.h"
|
||||
|
||||
/**
|
||||
* Returns address of function in a DLL that's already loaded.
|
||||
*/
|
||||
textwindows void *getprocaddressmodule(const char *module, const char *symbol) {
|
||||
textwindows void *GetProcAddressModule(const char *module, const char *symbol) {
|
||||
return GetProcAddress(GetModuleHandle(module), symbol);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "libc/nt/createfile.h"
|
||||
#include "libc/nt/enum/accessmask.h"
|
||||
#include "libc/nt/enum/creationdisposition.h"
|
||||
#include "libc/nt/enum/fileflagandattributes.h"
|
||||
#include "libc/nt/enum/filesharemode.h"
|
||||
#include "libc/nt/files.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/bits/progn.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/dirent.h"
|
||||
#include "libc/dce.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/alg.h"
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/runtime/memtrack.h"
|
||||
#include "libc/runtime/missioncritical.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue