Pay off more technical debt

This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -1,29 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int bsf(int) pureconst;
int bsfl(long) pureconst;
int bsfll(long long) pureconst;
int bsf128(uintmax_t) pureconst;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsf(u) \
({ \
unsigned BiTs; \
asm("bsf\t%0,%0" : "=r"(BiTs) : "0"((unsigned)(u)) : "cc"); \
BiTs; \
})
#define bsfl(u) \
({ \
unsigned long BiTs; \
asm("bsf\t%0,%0" : "=r"(BiTs) : "0"((unsigned long)(u)) : "cc"); \
(unsigned)BiTs; \
})
#define bsfll(u) bsfl(u)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */

View file

@ -1,29 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
int bsr(int) pureconst;
int bsrl(long) pureconst;
int bsrll(long long) pureconst;
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
int bsr128(uint128_t) pureconst;
#define bsr(u) \
({ \
unsigned BiTs; \
asm("bsr\t%0,%0" : "=r"(BiTs) : "0"((unsigned)(u)) : "cc"); \
BiTs; \
})
#define bsrl(u) \
({ \
unsigned long BiTs; \
asm("bsr\t%0,%0" : "=r"(BiTs) : "0"((unsigned long)(u)) : "cc"); \
(unsigned)BiTs; \
})
#define bsrll(u) bsrl(u)
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */

View file

@ -1,44 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Returns binary logarithm of integer 𝑥.
//
// uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
// 0x00000000 wut 32 0 wut 32
// 0x00000001 0 0 1 0 31
// 0x80000001 0 0 1 31 0
// 0x80000000 31 31 32 31 0
// 0x00000010 4 4 5 4 27
// 0x08000010 4 4 5 27 4
// 0x08000000 27 27 28 27 4
// 0xffffffff 0 0 1 31 0
//
// @param rsi:rdi is 128-bit unsigned 𝑥 value
// @return eax number in range [0,128) or undef if 𝑥 is 0
// @see also treasure trove of nearly identical functions
bsr128: .leafprologue
.profilable
bsr %rsi,%rax
jnz 2f
bsr %rdi,%rax
1: .leafepilogue
2: add $64,%eax
jmp 1b
.endfn bsr128,globl

View file

@ -8,7 +8,7 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
unsigned getcachesize(int, int);
unsigned _getcachesize(int, int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -26,7 +26,7 @@
//
// @param dil contains byte to escape
// @see libc/nexgen32e/cescapec.c
cescapec:
_cescapec:
.leafprologue
.profilable
movzbl %dil,%edi
@ -35,7 +35,7 @@ cescapec:
ja 1f
mov $'\\',%eax
movzbl %cl,%ecx
jmp *cescapectab(,%rcx,8)
jmp *_cescapectab(,%rcx,8)
.Lanchorpoint:
.LBEL: mov $'a',%ah
.leafepilogue
@ -78,10 +78,10 @@ cescapec:
lea (%rdi,%rax,4),%eax
add $'0'<<030|'0'<<020|'0'<<010|'\\',%eax
.leafepilogue
.endfn cescapec,globl
.endfn _cescapec,globl
.initro 300,_init_cescapec
cescapectab.ro:
_cescapectab.ro:
.byte 1,.LBEL-.Lanchorpoint
.byte 1,.LBS-.Lanchorpoint
.byte 1,.LHT-.Lanchorpoint
@ -97,22 +97,22 @@ cescapectab.ro:
.byte 1,.LQM-.Lanchorpoint
.byte '\\'-'?'-1,1b-.Lanchorpoint
.byte 1,.LBSL-.Lanchorpoint
.equ .Lcescapectab.ro.size,.-cescapectab.ro
.org 8 - .Lcescapectab.ro.size % 8 + .
.endobj cescapectab.ro,globl,hidden
.equ .L_cescapectab.ro.size,.-_cescapectab.ro
.org 8 - .L_cescapectab.ro.size % 8 + .
.endobj _cescapectab.ro,globl,hidden
.previous
.initbss 300,_init_cescapec
cescapectab:
_cescapectab:
.rept '\\'-7+1
.quad 0
.endr
.endobj cescapectab
.endobj _cescapectab
.previous
.init.start 300,_init_cescapec
ezlea .Lanchorpoint,dx
mov $.Lcescapectab.ro.size/2,%ch
mov $.L_cescapectab.ro.size/2,%ch
0: xor %eax,%eax
lodsb
mov %al,%cl
@ -123,7 +123,7 @@ cescapectab:
jnz 1b
dec %ch
jnz 0b
.if .Lcescapectab.ro.size % 8
add $(8-.Lcescapectab.ro.size%8),%rsi
.if .L_cescapectab.ro.size % 8
add $(8-.L_cescapectab.ro.size%8),%rsi
.endif
.init.end 300,_init_cescapec

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 8-bit signed integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpsb: .leafprologue
.profilable
xor %eax,%eax
cmpsb
cmovl .Lone(%rip),%eax
cmovg .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpsb,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,44 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 32-bit signed integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpsl: .leafprologue
.profilable
xor %eax,%eax
cmpsl
// mov (%rdi),%edi
// mov (%rsi),%esi
// cmp %edi,%esi
setl %al
cmovg .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpsl,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 64-bit signed integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpsq: .leafprologue
.profilable
xor %eax,%eax
cmpsq
cmovl .Lone(%rip),%eax
cmovg .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpsq,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 16-bit signed integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpsw: .leafprologue
.profilable
xor %eax,%eax
cmpsw
cmovl .Lone(%rip),%eax
cmovg .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpsw,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 8-bit unsigned integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpub: .leafprologue
.profilable
xor %eax,%eax
cmpsb
cmovb .Lone(%rip),%eax
cmova .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpub,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 32-bit unsigned integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpul: .leafprologue
.profilable
xor %eax,%eax
cmpsl
cmovb .Lone(%rip),%eax
cmova .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpul,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 64-bit unsigned integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpuq: .leafprologue
.profilable
xor %eax,%eax
cmpsq
cmovb .Lone(%rip),%eax
cmova .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpuq,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,41 +0,0 @@
/*-*- 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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.internal.h"
// Compares 16-bit unsigned integers.
//
// @param rdi points to left integer
// @param rsi points to right integer
// @return <0, 0, or >0 based on comparison
.align 16
cmpuw: .leafprologue
.profilable
xor %eax,%eax
cmpsw
cmovb .Lone(%rip),%eax
cmova .Lneg1(%rip),%eax
.leafepilogue
.endfn cmpuw,globl
.rodata.cst4
.Lone: .long 1
.endobj .Lone
.Lneg1: .long -1
.endobj .Lneg1
.previous

View file

@ -1,5 +1,5 @@
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_GC_INTERNAL_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_GC_INTERNAL_H_
#include "libc/nexgen32e/stackframe.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -20,4 +20,4 @@ int64_t __gc(void);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_ */
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_GC_INTERNAL_H_ */

View file

@ -21,7 +21,7 @@
// Castagnoli CRC32 ISCSI Polynomial
// x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
// 0b00011110110111000110111101000001
// bitreverse32(0x1edc6f41)
// _bitreverse32(0x1edc6f41)
#define ISCSI_POLYNOMIAL 0x82f63b78
.initbss 300,_init_kCrc32cTab

View file

@ -21,7 +21,7 @@
.code16 # .code32 .code64
// Optional function stub.
missingno:
_missingno:
xor %ax,%ax
ret
.endfn missingno,globl,hidden
.endfn _missingno,globl,hidden