Browse Source

Make small fixes and oops ran clang-format on dtoa

main
Justine Tunney 2 years ago
parent
commit
ac00be1a4e
  1. 2
      Makefile
  2. 8
      ape/ape.S
  3. 2
      ape/ape.lds
  4. 13
      ape/ape.mk
  5. 8
      ape/lib/pc.h
  6. 2
      build/do
  7. 3
      build/rules.mk
  8. 3
      examples/examples.mk
  9. 6
      examples/unbourne.c
  10. 254
      libc/bits/bits.h
  11. 4
      libc/bits/hamming.c
  12. 22
      libc/bits/popcnt.c
  13. 24
      libc/bits/popcnt.h
  14. 4
      libc/calls/mprotect.greg.c
  15. 2
      libc/conv/conv.h
  16. 23
      libc/conv/strtoimax.c
  17. 24
      libc/fmt/palandftoa.c
  18. 3
      libc/log/meminfo.c
  19. 1
      libc/macros.h
  20. 10
      libc/macros.inc
  21. 16
      libc/nexgen32e/doc/strcmp-avx2.c
  22. 4
      libc/rand/rdrand.c
  23. 7
      libc/runtime/balloc.c
  24. 6
      libc/runtime/missioncritical.h
  25. 3
      libc/stdio/fmemopen.c
  26. 4
      libc/stdio/setbuffer.c
  27. 4
      libc/stdio/setvbuf.c
  28. 17
      libc/tinymath/emodl.h
  29. 22
      test/libc/conv/strtoimax_test.c
  30. 2
      test/libc/fmt/palandprintf_test.c
  31. 16
      test/libc/math/round_test.c
  32. 32
      test/libc/tinymath/round_test.c
  33. 5
      test/libc/unicode/wcwidth_test.c
  34. 2
      third_party/compiler_rt/compiler_rt.mk
  35. 2
      third_party/dlmalloc/dlmalloc.c
  36. 9644
      third_party/dtoa/dtoa.c
  37. 9
      third_party/dtoa/dtoa.h
  38. 43
      third_party/xed/avx.h
  39. 44
      third_party/xed/avx512.h
  40. 167
      third_party/xed/x86.h
  41. 30
      third_party/xed/x86ild.greg.c
  42. 26
      third_party/xed/x86tab.S
  43. 2
      tool/build/lib/interner.c
  44. 2
      tool/build/mkdeps.c
  45. 1
      tool/build/refactor.c
  46. 8
      tool/decode/x86opinfo.c
  47. 7
      tool/viz/printvideo.c

2
Makefile

@ -212,7 +212,7 @@ depend: o/$(MODE)/depend @@ -212,7 +212,7 @@ depend: o/$(MODE)/depend
tags: TAGS HTAGS
o/$(MODE)/.x:
@mkdir -p $(dir $@) && touch $@
@$(MKDIR) $(dir $@) && touch $@
o/$(MODE)/srcs.txt: o/$(MODE)/.x $(MAKEFILES) $(call uniq,$(foreach x,$(SRCS),$(dir $(x))))
$(file >$@) $(foreach x,$(SRCS),$(file >>$@,$(x)))

8
ape/ape.S

@ -485,7 +485,6 @@ ape_disk: @@ -485,7 +485,6 @@ ape_disk:
apesh: .ascii "'\n#'\"\n" # sixth edition shebang
.ascii "o=\"$(command -v \"$0\")\"\n"
.ascii "set -- \"$o\" \"$@\"\n"
.ascii "if [ -d /Applications ]; then\n"
.ascii "dd if=\"$o\""
.ascii " of=\"$o\""
@ -521,14 +520,17 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang @@ -521,14 +520,17 @@ apesh: .ascii "'\n#'\"\n" # sixth edition shebang
.ascii "' >&7\n"
.ascii "exec 7<&-\n"
.ascii "fi\n"
.ascii "exec \"$@\"\n" # etxtbsy tail recursion
.ascii "exec \"$0\" \"$@\"\n" # etxtbsy tail recursion
.ascii "R=$?\n" # architecture optimistic
.ascii "\n"
.ascii "if [ $R -eq 126 ] && [ \"$(uname -m)\" != x86_64 ]; then\n"
.ascii "if Q=\"$(command -v qemu-x86_64)\"; then\n"
.ascii "exec \"$Q\" \"$@\"\n"
.ascii "exec \"$Q\" \"$0\" \"$@\"\n"
.ascii "else\n"
.ascii "echo error: need qemu-x86_64 >&2\n"
.ascii "fi\n"
.ascii "elif [ $R -eq 127 ]; then\n" # means argv[0] was wrong
.ascii " exec \"$o\" \"$@\"\n" # so do a path resolution
.ascii "fi\n"
.ascii "exit $R\n"
.endobj apesh

2
ape/ape.lds

@ -333,7 +333,7 @@ SECTIONS { @@ -333,7 +333,7 @@ SECTIONS {
/*BEGIN: Read only data that needn't be mapped after initialization */
/* Legal Notices */
#ifndef IM_FEELING_NAUGHTY
#if !defined(IM_FEELING_NAUGHTY) || defined(EMBED_NOTICES)
KEEP(*(.commentprologue))
KEEP(*(.comment))
KEEP(*(.commentepilogue))

13
ape/ape.mk

@ -21,6 +21,8 @@ APE = $(APE_DEPS) \ @@ -21,6 +21,8 @@ APE = $(APE_DEPS) \
APELINK = \
ACTION=LINK.ape \
$(MKDIR) \
$(dir $@) && \
$(LINK) \
$(LINKARGS) \
$(OUTPUT_OPTION) && \
@ -30,6 +32,15 @@ APELINK = \ @@ -30,6 +32,15 @@ APELINK = \
$(ZFLAGS) \
-f $@.map
APECOPY = \
ACTION=OBJCOPY.ape \
TARGET=$@ \
build/do \
$(OBJCOPY) \
-SO binary \
$< \
$@
DEFAULT_COPTS += -mno-red-zone
DEFAULT_LDFLAGS += -z max-page-size=0x1000
@ -41,7 +52,7 @@ APE_DEPS = $(APE_LIB) @@ -41,7 +52,7 @@ APE_DEPS = $(APE_LIB)
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
o/%.com: o/%.com.dbg
@ACTION=OBJCOPY.ape TARGET=$@ build/do $(OBJCOPY) -SO binary $< $@
@$(APECOPY)
o/ape/idata.inc: \
ape/idata.h \

8
ape/lib/pc.h

@ -148,12 +148,12 @@ @@ -148,12 +148,12 @@
0b00000000000011111111111111111111111111111111111111000000000000
6666555555555544444444443333333333222222222211111111110000000000
3210987654321098765432109876543210987654321098765432109876543210*/
#define PAGE_V /* */ 0b000000001
#define PAGE_RW /* */ 0b000000010
#define PAGE_U /* */ 0b000000100
#define PAGE_V /* */ 0b000000001
#define PAGE_RW /* */ 0b000000010
#define PAGE_U /* */ 0b000000100
#define PAGE_2MB /* */ 0b110000000
#define PAGE_1GB /* */ 0b110000000
#define PAGE_TA 0b011111111111111111111111111111111111111000000000000
#define PAGE_TA 0b11111111111111111111111111111111111111000000000000
#define PAGE_PA2 0b11111111111111111111111111111000000000000000000000
#if !(__ASSEMBLER__ + __LINKER__ + 0)

2
build/do

@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
# Ensure directory creation if -o PATH flag is passed.
OUT=
OUT="$TARGET"
FIRST=1
OUTARG=0
for x; do

3
build/rules.mk

@ -33,7 +33,7 @@ o/%.inc: %.h; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) -D @@ -33,7 +33,7 @@ o/%.inc: %.h; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) -D
o/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
o/%.h.ok: %.h; @ACTION=CHECK.h build/compile $(COMPILE.c) -x c -g0 -o $@ $<
o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
o/%.zip.o: %; @build/zipobj $(OUTPUT_OPTION) $<
o/%.zip.o: o/%; @build/zipobj $(OUTPUT_OPTION) $<
o/$(MODE)/%.a:; @$(ARCHIVE) $@ $^
o/$(MODE)/%.o: %.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
@ -95,4 +95,3 @@ build/bootstrap/%.c.gz: %.rl @@ -95,4 +95,3 @@ build/bootstrap/%.c.gz: %.rl
@$(GZ) $(ZFLAGS) -f $(@:%.gz=%)
%.svgz: %.rl
@$(RAGEL) -V -p $< | $(DOT) -Tsvg | $(GZ) $(ZFLAGS) >$@

3
examples/examples.mk

@ -124,7 +124,8 @@ o/$(MODE)/examples/ispell.com.dbg: \ @@ -124,7 +124,8 @@ o/$(MODE)/examples/ispell.com.dbg: \
@$(APELINK)
o/$(MODE)/usr/share/dict/words: usr/share/dict/words.gz
$(GZ) $(ZFLAGS) <$< >$@
@$(MKDIR) $(dir $@)
@$(GZ) $(ZFLAGS) <$< >$@
.PHONY: o/$(MODE)/examples
o/$(MODE)/examples: \

6
examples/unbourne.c

@ -606,11 +606,7 @@ @@ -606,11 +606,7 @@
#define printf out1fmt
/* #define putc(c, file) outc(c, file) */
/* #define putchar(c) out1c(c) */
#define FILE struct output
#undef fprintf
#define fprintf outfmt
#define fputs outstr
#define fflush flushout
#define FILE struct output
#define fileno(f) ((f)->fd)
/* #define ferror outerr */
#define INITARGS(argv)

254
libc/bits/bits.h

@ -16,7 +16,6 @@ extern const uint8_t kReverseBits[256]; @@ -16,7 +16,6 @@ extern const uint8_t kReverseBits[256];
uint16_t bswap_16(uint16_t) pureconst;
uint32_t bswap_32(uint32_t) pureconst;
uint32_t bswap_64(uint32_t) pureconst;
unsigned long popcount(unsigned long) pureconst;
uint32_t gray(uint32_t) pureconst;
uint32_t ungray(uint32_t) pureconst;
unsigned bcdadd(unsigned, unsigned) pureconst;
@ -87,36 +86,36 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -87,36 +86,36 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
})
#endif
#define WRITE16LE(P, V) \
do { \
uint8_t *Ple = (P); \
uint16_t Vle = (V); \
Ple[0] = (uint8_t)(Vle >> 000); \
Ple[1] = (uint8_t)(Vle >> 010); \
#define WRITE16LE(P, V) \
do { \
uint8_t *Ple = (unsigned char *)(P); \
uint16_t Vle = (V); \
Ple[0] = (uint8_t)(Vle >> 000); \
Ple[1] = (uint8_t)(Vle >> 010); \
} while (0)
#define WRITE32LE(P, V) \
do { \
uint8_t *Ple = (P); \
uint32_t Vle = (V); \
Ple[0] = (uint8_t)(Vle >> 000); \
Ple[1] = (uint8_t)(Vle >> 010); \
Ple[2] = (uint8_t)(Vle >> 020); \
Ple[3] = (uint8_t)(Vle >> 030); \
#define WRITE32LE(P, V) \
do { \
uint8_t *Ple = (unsigned char *)(P); \
uint32_t Vle = (V); \
Ple[0] = (uint8_t)(Vle >> 000); \
Ple[1] = (uint8_t)(Vle >> 010); \
Ple[2] = (uint8_t)(Vle >> 020); \
Ple[3] = (uint8_t)(Vle >> 030); \
} while (0)
#define WRITE64LE(P, V) \
do { \
uint8_t *Ple = (P); \
uint64_t Vle = (V); \
Ple[0] = (uint8_t)(Vle >> 000); \
Ple[1] = (uint8_t)(Vle >> 010); \
Ple[2] = (uint8_t)(Vle >> 020); \
Ple[3] = (uint8_t)(Vle >> 030); \
Ple[4] = (uint8_t)(Vle >> 040); \
Ple[5] = (uint8_t)(Vle >> 050); \
Ple[6] = (uint8_t)(Vle >> 060); \
Ple[7] = (uint8_t)(Vle >> 070); \
#define WRITE64LE(P, V) \
do { \
uint8_t *Ple = (unsigned char *)(P); \
uint64_t Vle = (V); \
Ple[0] = (uint8_t)(Vle >> 000); \
Ple[1] = (uint8_t)(Vle >> 010); \
Ple[2] = (uint8_t)(Vle >> 020); \
Ple[3] = (uint8_t)(Vle >> 030); \
Ple[4] = (uint8_t)(Vle >> 040); \
Ple[5] = (uint8_t)(Vle >> 050); \
Ple[6] = (uint8_t)(Vle >> 060); \
Ple[7] = (uint8_t)(Vle >> 070); \
} while (0)
/* TODO(jart): these ones aren't coded correctly */
@ -135,27 +134,27 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -135,27 +134,27 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @note we beseech clang devs for flag constraints
*/
#ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */
#define CF "=@ccc"
#define CFLAG(OP) OP
#define ZF "=@ccz"
#define ZFLAG(OP) OP
#define OF "=@cco"
#define OFLAG(OP) OP
#define SF "=@ccs"
#define SFLAG(SP) SP
#define ABOVEF "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG(OP) OP
#define CFLAG_CONSTRAINT "=@ccc"
#define CFLAG_ASM(OP) OP
#define ZFLAG_CONSTRAINT "=@ccz"
#define ZFLAG_ASM(OP) OP
#define OFLAG_CONSTRAINT "=@cco"
#define OFLAG_ASM(OP) OP
#define SFLAG_CONSTRAINT "=@ccs"
#define SFLAG_ASM(SP) SP
#define ABOVE_CONSTRAINT "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG_ASM(OP) OP
#else
#define CF "=q"
#define CFLAG(OP) OP "\n\tsetc\t%b0"
#define ZF "=q"
#define ZFLAG(OP) OP "\n\tsetz\t%b0"
#define OF "=q"
#define OFLAG(OP) OP "\n\tseto\t%b0"
#define SF "=q"
#define SFLAG(SP) OP "\n\tsets\t%b0"
#define ABOVEF "=@cca"
#define ABOVEFLAG(OP) OP "\n\tseta\t%b0"
#define CFLAG_CONSTRAINT "=q"
#define CFLAG_ASM(OP) OP "\n\tsetc\t%b0"
#define ZFLAG_CONSTRAINT "=q"
#define ZFLAG_ASM(OP) OP "\n\tsetz\t%b0"
#define OFLAG_CONSTRAINT "=q"
#define OFLAG_ASM(OP) OP "\n\tseto\t%b0"
#define SFLAG_CONSTRAINT "=q"
#define SFLAG_ASM(SP) OP "\n\tsets\t%b0"
#define ABOVE_CONSTRAINT "=@cca"
#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0"
#endif
/**
@ -226,23 +225,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -226,23 +225,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @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("bt%z1\t%2,%1") \
: CF(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("bt\t%w2,%1") : CF(OldBit) : "m"((MEM)[0]), "r"(BIT) : "cc"); \
} else if (sizeof((MEM)[0]) == 4) { \
asm(CFLAG("bt\t%k2,%1") : CF(OldBit) : "m"((MEM)[0]), "r"(BIT) : "cc"); \
} else if (sizeof((MEM)[0]) == 8) { \
asm(CFLAG("bt\t%q2,%1") : CF(OldBit) : "m"((MEM)[0]), "r"(BIT) : "cc"); \
} \
OldBit; \
#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 */
@ -285,27 +293,27 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -285,27 +293,27 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
#define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
asm(ZFLAG("cmpxchg\t%3,%1") \
: ZF(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \
: "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \
: "cc"); \
DidIt; \
#define cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
asm(ZFLAG_ASM("cmpxchg\t%3,%1") \
: ZFLAG_CONSTRAINT(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \
: "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \
: "cc"); \
DidIt; \
})
#define ezcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
autotype(IFTHING) IfThing = (IFTHING); \
typeof(*IfThing) IsEqualToMe = (ISEQUALTOME); \
typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME); \
asm(ZFLAG("cmpxchg\t%3,%1") \
: ZF(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
: "r"(ReplaceItWithMe) \
: "cc"); \
DidIt; \
#define ezcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
autotype(IFTHING) IfThing = (IFTHING); \
typeof(*IfThing) IsEqualToMe = (ISEQUALTOME); \
typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME); \
asm(ZFLAG_ASM("cmpxchg\t%3,%1") \
: ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
: "r"(ReplaceItWithMe) \
: "cc"); \
DidIt; \
})
/**
@ -315,14 +323,14 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -315,14 +323,14 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
* @return true if value was exchanged, otherwise false
* @see lockcmpxchg()
*/
#define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
asm(ZFLAG("lock cmpxchg\t%3,%1") \
: ZF(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \
: "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \
: "cc"); \
DidIt; \
#define lockcmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
({ \
bool DidIt; \
asm(ZFLAG_ASM("lock cmpxchg\t%3,%1") \
: ZFLAG_CONSTRAINT(DidIt), "+m"(*(IFTHING)), "+a"(*(ISEQUALTOME)) \
: "r"((typeof(*(IFTHING)))(REPLACEITWITHME)) \
: "cc"); \
DidIt; \
})
/**
@ -431,19 +439,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -431,19 +439,6 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define popcount(X) (isconstant(X) ? __builtin_popcount(X) : __popcount(X))
#define popcount$nehalem(X) \
({ \
typeof(X) BitCount; \
asm("popcnt\t%1,%0" : "=r,r"(BitCount) : "r,m"(X) : "cc"); \
BitCount; \
})
#ifdef __POPCNT__
#define __popcount(X) popcount$nehalem(X)
#else
#define __popcount(X) (popcount)(X)
#endif
#define bswap_16(U16) \
(isconstant(U16) ? ((((U16)&0xff00) >> 010) | (((U16)&0x00ff) << 010)) : ({ \
uint16_t Swapped16, Werd16 = (U16); \
@ -500,31 +495,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst; @@ -500,31 +495,32 @@ unsigned long hamming(unsigned long, unsigned long) pureconst;
MEM; \
})
#define __BitOp(OP, BIT, MEM) \
({ \
bool OldBit; \
if (isconstant(BIT)) { \
asm(CFLAG(OP "%z1\t%2,%1") \
: CF(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(OP "\t%w2,%1") \
: CF(OldBit), "+m"((MEM)[0]) \
: "r"(BIT) \
: "cc"); \
} else if (sizeof((MEM)[0]) == 4) { \
asm(CFLAG(OP "\t%k2,%1") \
: CF(OldBit), "+m"((MEM)[0]) \
: "r"(BIT) \
: "cc"); \
} else if (sizeof((MEM)[0]) == 8) { \
asm(CFLAG(OP "\t%q2,%1") \
: CF(OldBit), "+m"((MEM)[0]) \
: "r"(BIT) \
: "cc"); \
} \
OldBit; \
#define __BitOp(OP, BIT, MEM) \
({ \
bool OldBit; \
if (isconstant(BIT)) { \
asm(CFLAG_ASM(OP "%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(OP "\t%w2,%1") \
: CFLAG_CONSTRAINT(OldBit), "+m"((MEM)[0]) \
: "r"(BIT) \
: "cc"); \
} else if (sizeof((MEM)[0]) == 4) { \
asm(CFLAG_ASM(OP "\t%k2,%1") \
: CFLAG_CONSTRAINT(OldBit), "+m"((MEM)[0]) \
: "r"(BIT) \
: "cc"); \
} else if (sizeof((MEM)[0]) == 8) { \
asm(CFLAG_ASM(OP "\t%q2,%1") \
: CFLAG_CONSTRAINT(OldBit), "+m"((MEM)[0]) \
: "r"(BIT) \
: "cc"); \
} \
OldBit; \
})
COSMOPOLITAN_C_END_

4
libc/bits/hamming.c

@ -17,11 +17,11 @@ @@ -17,11 +17,11 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/popcnt.h"
/**
* Counts number of different bits.
*/
unsigned long hamming(unsigned long x, unsigned long y) {
return popcount(x ^ y);
return popcnt(x ^ y);
}

22
libc/bits/popcount.c → libc/bits/popcnt.c

@ -17,26 +17,20 @@ @@ -17,26 +17,20 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/bits/popcnt.h"
static noinline uint32_t popcount$swar32(uint32_t x) {
static uint32_t popcnt32(uint32_t x) {
x -= (x >> 1) & 0x55555555;
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
return (((x + (x >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
}
unsigned long(popcount)(unsigned long x) {
size_t i;
unsigned long(popcnt)(unsigned long x) {
unsigned long r;
if (X86_HAVE(POPCNT)) {
return popcount$nehalem(x);
} else {
r = 0;
for (i = 0; i < sizeof(x); i += 4) {
r |= popcount$swar32(x);
x >>= 32;
}
return r;
r = 0;
while (x) {
r += popcnt32(x);
x >>= 32;
}
return r;
}

24
libc/bits/popcnt.h

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
#ifndef COSMOPOLITAN_LIBC_BITS_POPCNT_H_
#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
#include "libc/nexgen32e/x86feature.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
unsigned long popcnt(unsigned long) pureconst;
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define popcnt(X) \
(isconstant(X) ? __builtin_popcount(X) : ({ \
unsigned long Res, Pop = (X); \
if (X86_HAVE(POPCNT)) { \
asm("popcnt\t%1,%0" : "=r"(Res) : "r"(Pop) : "cc"); \
} else { \
Res = (popcnt)(Pop); \
} \
Res; \
}))
#endif /* GNUC && !ANSI */
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_BITS_POPCNT_H_ */

4
libc/calls/mprotect.greg.c

@ -32,8 +32,8 @@ privileged int __mprotect(void *addr, uint64_t len, int prot) { @@ -32,8 +32,8 @@ privileged int __mprotect(void *addr, uint64_t len, int prot) {
int64_t rc;
uint32_t oldprot;
if (!IsWindows()) {
asm volatile(CFLAG("syscall")
: CF(cf), "=a"(rc)
asm volatile(CFLAG_ASM("syscall")
: CFLAG_CONSTRAINT(cf), "=a"(rc)
: "1"(__NR_mprotect), "D"(addr), "S"(len), "d"(prot)
: "rcx", "r11", "memory", "cc");
if (cf) {

2
libc/conv/conv.h

@ -30,7 +30,7 @@ unsigned long strtoul(const char *, char **, int) paramsnonnull((1)); @@ -30,7 +30,7 @@ unsigned long strtoul(const char *, char **, int) paramsnonnull((1));
long long strtoll(const char *, char **, int) paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
long long strtonum(const char *, long long, long long, const char **);
intmax_t div10(intmax_t x, unsigned *rem) hidden;
intmax_t div10(intmax_t, unsigned *) hidden;
intmax_t strtoimax(const char *, char **, int) paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int);

23
libc/conv/strtoimax.c

@ -37,10 +37,10 @@ @@ -37,10 +37,10 @@
* @see strtoumax
*/
intmax_t strtoimax(const char *s, char **endptr, int base) {
bool neg;
uintmax_t x;
intmax_t res;
unsigned diglet, bits;
bool neg, islong, isunsigned;
x = 0;
bits = 0;
@ -100,10 +100,23 @@ intmax_t strtoimax(const char *s, char **endptr, int base) { @@ -100,10 +100,23 @@ intmax_t strtoimax(const char *s, char **endptr, int base) {
}
}
if (endptr) {
*endptr = s;
if ((isunsigned = *s == 'u' || *s == 'U')) s++;
if ((islong = *s == 'l' || *s == 'L')) s++;
if (endptr) *endptr = s;
if (neg) {
res = -x;
} else {
res = x;
}
if (isunsigned) {
if (islong) {
res = (uint64_t)res;
} else {
res = (uint32_t)res;
}
}
res = x;
return neg ? -res : res;
return res;
}

24
libc/fmt/palandftoa.c

@ -54,23 +54,17 @@ int ftoa(int out(int, void *), void *arg, long double value, unsigned long prec, @@ -54,23 +54,17 @@ int ftoa(int out(int, void *), void *arg, long double value, unsigned long prec,
diff = 0;
if (isnan(value)) {
buf[0] = 'N';
buf[1] = 'A';
buf[2] = 'N';
buf[0] = 'n';
buf[1] = 'a';
buf[2] = 'n';
buf[3] = '\0';
len += 3;
} else if (isinf(value) || fabsl(value) > 0x7ffffffffffffffful) {
buf[0] = 'f';
buf[1] = 'n';
buf[2] = 'i';
buf[3] = '\0';
len += 3;
} else if (isinf(value) ||
(/* TODO(jart): need this? */ fabsl(value) > 0x7fffffff)) {
buf[0] = 'Y';
buf[1] = 'T';
buf[2] = 'I';
buf[3] = 'N';
buf[4] = 'I';
buf[5] = 'F';
buf[6] = 'N';
buf[7] = 'I';
buf[8] = '\0';
len += 8;
} else {
/* set default precision to 6, if not set explicitly */

3
libc/log/meminfo.c

@ -31,6 +31,9 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) { @@ -31,6 +31,9 @@ static void onmemchunk(void *start, void *end, size_t used_bytes, void *arg) {
(intptr_t)end - (intptr_t)start);
}
/**
* Prints memory mappings.
*/
void meminfo(FILE *f) {
memsummary(f);
(fprintf)(f, "%*s %*s %*s %*s\n", POINTER_XDIGITS, "start",

1
libc/macros.h

@ -20,7 +20,6 @@ @@ -20,7 +20,6 @@
#define ABS(X) ((X) >= 0 ? (X) : -(X))
#define MIN(X, Y) ((Y) > (X) ? (X) : (Y))
#define MAX(X, Y) ((Y) < (X) ? (X) : (Y))
#define MOD(X, Y) ((X) - (ABS(Y)) * ((X) / ABS(Y)))
#define PASTE(A, B) __PASTE(A, B)
#define STRINGIFY(A) __STRINGIFY(A)
#define EQUIVALENT(X, Y) (isconstant((X) == (Y)) && ((X) == (Y)))

10
libc/macros.inc

@ -264,6 +264,16 @@ _init_\name: @@ -264,6 +264,16 @@ _init_\name:
.popsection
.endm
/ ICE Breakpoint.
/ Modern gas forgot this but objdump knows
/ @mode long,legacy,real
.macro icebp
.byte 0xF1
.endm
.macro int1
icebp
.endm
/ Sets breakpoint for software debugger.
/ @mode long,legacy,real
.macro .softicebp

16
libc/nexgen32e/doc/strcmp-avx2.c

@ -41,14 +41,14 @@ bLoop: @@ -41,14 +41,14 @@ bLoop:
vbitmask_t r1;
uint8_v v1, v2;
const uint8_v kZero = {0};
asm(ZFLAG("vmovdqu\t%5,%2\n\t" /* move because gcc problematic */
"vpcmpeqb\t%4,%2,%1\n\t" /* check for equality in p1 and p2 */
"vpcmpeqb\t%6,%2,%2\n\t" /* check for nul in p1 */
"vpandn\t%7,%1,%2\n\t" /* most complicated bitwise not ever */
"vpor\t%2,%1,%1\n\t" /* check for nul in p2 */
"pmovmskb\t%1,%3\n\t" /* turn 256 bits into 32 bits */
"bsf\t%3,%3") /* find stop byte */
: ZF(zf), "=x"(v1), "=x"(v2), "=r"(r1)
asm(ZFLAG_ASM("vmovdqu\t%5,%2\n\t" /* move because gcc problematic */
"vpcmpeqb\t%4,%2,%1\n\t" /* check for equality in p1 and p2 */
"vpcmpeqb\t%6,%2,%2\n\t" /* check for nul in p1 */
"vpandn\t%7,%1,%2\n\t" /* most complicated bitwise not ever */
"vpor\t%2,%1,%1\n\t" /* check for nul in p2 */
"pmovmskb\t%1,%3\n\t" /* turn 256 bits into 32 bits */
"bsf\t%3,%3") /* find stop byte */
: ZFLAG_CONSTRAINT(zf), "=x"(v1), "=x"(v2), "=r"(r1)
: "m"(*(const uint8_v *)(p1 + i)), "m"(*(const uint8_v *)(p2 + i)),
"x"(kZero), "m"(kVectorSize));
if (zf) goto vLoop;

4
libc/rand/rdrand.c

@ -36,8 +36,8 @@ uint64_t rdrand(void) { @@ -36,8 +36,8 @@ uint64_t rdrand(void) {
for (;;) {
for (i = 0; i < 10; ++i) {
/* CF=1: Destination register valid. Quoth Intel DRNG-SIG 4.1.3 */
asm volatile(CFLAG("rdrand\t%1")
: CF(cf), "=r"(res)
asm volatile(CFLAG_ASM("rdrand\t%1")
: CFLAG_CONSTRAINT(cf), "=r"(res)
: /* no inputs */
: "cc");
if (cf) return res;

7
libc/runtime/balloc.c

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
*/
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/popcnt.h"
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/runtime/buffer.h"
@ -54,9 +55,9 @@ void *balloc(struct GuardedBuffer *b, unsigned a, size_t n) { @@ -54,9 +55,9 @@ void *balloc(struct GuardedBuffer *b, unsigned a, size_t n) {
assert(a >= 1);
assert(a <= kGuard);
assert(kGuard < kGrain);
assert(popcount(a) == 1);
assert(popcount(kGuard) == 1);
assert(popcount(kGrain) == 1);
assert(popcnt(a) == 1);
assert(popcnt(kGuard) == 1);
assert(popcnt(kGrain) == 1);
assert(n < 0x800000000000ul - kGrain - kGuard);
if (n) {

6
libc/runtime/missioncritical.h

@ -45,9 +45,9 @@ @@ -45,9 +45,9 @@
({ \
int KillAx; \
unsigned char Cf; \
asm volatile(CFLAG("clc\n\t" \
"syscall") \
: CF(Cf), "=a"(KillAx) \
asm volatile(CFLAG_ASM("clc\n\t" \
"syscall") \
: CFLAG_CONSTRAINT(Cf), "=a"(KillAx) \
: "1"(__NR_kill), "D"(pid), "S"(sig) \
: "rcx", "r11", "cc", "memory"); \
Cf ? -KillAx : KillAx; \

3
libc/stdio/fmemopen.c

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/popcnt.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/mem/mem.h"
@ -46,7 +47,7 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) { @@ -46,7 +47,7 @@ FILE *fmemopen(void *buf, size_t size, const char *mode) {
return NULL;
}
if (size && popcount(size) != 1) {
if (size && popcnt(size) != 1) {
einval();
return NULL;
}

4
libc/stdio/setbuffer.c

@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/popcnt.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/errfuns.h"
@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
* Sets buffer on stdio stream.
*/
void setbuffer(FILE *f, char *buf, size_t size) {
if (size && popcount(size) != 1) abort();
if (size && popcnt(size) != 1) abort();
if (buf && f->buf != (unsigned char *)buf) {
free_s(&f->buf);
if (!size) size = BUFSIZ;

4
libc/stdio/setvbuf.c

@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/popcnt.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/errfuns.h"
@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
* @return 0 on success or -1 on error
*/
int setvbuf(FILE *f, char *buf, int mode, size_t size) {
if (size && popcount(size) != 1) return einval();
if (size && popcnt(size) != 1) return einval();
setbuffer(f, buf, size);
f->bufmode = mode;
return 0;

17
libc/tinymath/emodl.h

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
#ifndef COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_
#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_
#include "libc/math.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
/**
* Returns Euclidean floating-point division remainder.
*
* @return (𝑥 mod 𝑦) [0.,𝑦)
* @see fmodl()
*/
static long double emodl(long double x, long double y) {
return x - fabsl(y) * floorl(x / fabsl(y));
}
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_ */

22
test/libc/conv/strtoimax_test.c

@ -23,10 +23,18 @@ @@ -23,10 +23,18 @@
/* todo(jart): work on this more */
TEST(strtoimax, testZero) { EXPECT_EQ(0, strtoimax("0", NULL, 0)); }
TEST(strtoimax, testDecimal) { EXPECT_EQ(-123, strtoimax("-123", NULL, 0)); }
TEST(strtoimax, testHex) { EXPECT_EQ(-255, strtoimax("-0xff", NULL, 0)); }
TEST(strtoimax, testOctal) { EXPECT_EQ(-123, strtoimax("-0173", NULL, 0)); }
TEST(strtoimax, testZero) {
EXPECT_EQ(0, strtoimax("0", NULL, 0));
}
TEST(strtoimax, testDecimal) {
EXPECT_EQ(-123, strtoimax("-123", NULL, 0));
}
TEST(strtoimax, testHex) {
EXPECT_EQ(-255, strtoimax("-0xff", NULL, 0));
}
TEST(strtoimax, testOctal) {
EXPECT_EQ(-123, strtoimax("-0173", NULL, 0));
}
TEST(strtoimax, testLimits) {
EXPECT_EQ(
@ -36,3 +44,9 @@ TEST(strtoimax, testLimits) { @@ -36,3 +44,9 @@ TEST(strtoimax, testLimits) {
((uintmax_t)0x7fffffffffffffff) << 64 | (uintmax_t)0xffffffffffffffff,
strtoimax("0x7fffffffffffffffffffffffffffffff", NULL, 0));
}
TEST(strtoimax, testZeroExtend) {
EXPECT_EQ(-1, strtoimax("-1", NULL, 0));
EXPECT_EQ(0xffffffff, strtoimax("-1u", NULL, 0));
EXPECT_EQ(0xffffffffffffffff, strtoimax("-1ul", NULL, 0));
}

2
test/libc/fmt/palandprintf_test.c

@ -434,7 +434,7 @@ TEST(sprintf, test_float) { @@ -434,7 +434,7 @@ TEST(sprintf, test_float) {
EXPECT_STREQ("a0.5 ", Format("a%-5.1f", 0.5));
EXPECT_STREQ("a0.5 end", Format("a%-5.1fend", 0.5));
/* out of range in the moment, need to be fixed by someone */
EXPECT_STREQ("INFINITY", Format("%.1f", 1E20));
EXPECT_STREQ("inf", Format("%.1f", 1E20));
}
TEST(sprintf, test_types) {

16
test/libc/math/round_test.c

@ -33,10 +33,10 @@ TEST(round, test) { @@ -33,10 +33,10 @@ TEST(round, test) {
TEST(round, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(round(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(round(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(round(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(round(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(round(-INFINITY))));
EXPECT_STREQ("nan", gc(xdtoa(round(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(round(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(round(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(round(-INFINITY))));
}
TEST(lround, test) {
@ -60,10 +60,10 @@ TEST(roundf, test) { @@ -60,10 +60,10 @@ TEST(roundf, test) {
TEST(roundf, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(roundf(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(roundf(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(roundf(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(roundf(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(roundf(-INFINITY))));
EXPECT_STREQ("nan", gc(xdtoa(roundf(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(roundf(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(roundf(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(roundf(-INFINITY))));
}
TEST(lroundf, test) {

32
test/libc/tinymath/round_test.c

@ -38,10 +38,10 @@ TEST(round, test) { @@ -38,10 +38,10 @@ TEST(round, test) {
TEST(round, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_round(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(tinymath_round(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_round(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_round(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_round(-INFINITY))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_round(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_round(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_round(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_round(-INFINITY))));
}
TEST(lround, test) {
@ -65,10 +65,10 @@ TEST(roundf, test) { @@ -65,10 +65,10 @@ TEST(roundf, test) {
TEST(roundf, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundf(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(tinymath_roundf(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_roundf(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_roundf(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_roundf(-INFINITY))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundf(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_roundf(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_roundf(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_roundf(-INFINITY))));
}
TEST(lroundf, test) {
@ -103,18 +103,18 @@ TEST(roundf$k8, test) { @@ -103,18 +103,18 @@ TEST(roundf$k8, test) {
TEST(round$k8, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_round$k8(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(tinymath_round$k8(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_round$k8(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_round$k8(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_round$k8(-INFINITY))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_round$k8(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_round$k8(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_round$k8(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_round$k8(-INFINITY))));
}
TEST(roundf$k8, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundf$k8(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(tinymath_roundf$k8(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(tinymath_roundf$k8(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(tinymath_roundf$k8(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(tinymath_roundf$k8(-INFINITY))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundf$k8(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_roundf$k8(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_roundf$k8(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_roundf$k8(-INFINITY))));
}
#endif

5
test/libc/unicode/wcwidth_test.c

@ -83,3 +83,8 @@ TEST(strwidth, tab) { @@ -83,3 +83,8 @@ TEST(strwidth, tab) {
TEST(wcwidth, block) {
EXPECT_EQ(1, wcwidth(u''));
}
TEST(strwidth, testTextDelimitingControlCodes_dontHaveSubstance) {
EXPECT_EQ(0, strwidth("\0"));
EXPECT_EQ(0, strwidth("\1"));
}

2
third_party/compiler_rt/compiler_rt.mk vendored

@ -27,7 +27,7 @@ THIRD_PARTY_COMPILER_RT_A_CHECKS = \ @@ -27,7 +27,7 @@ THIRD_PARTY_COMPILER_RT_A_CHECKS = \
$(THIRD_PARTY_COMPILER_RT_A_HDRS:%=o/$(MODE)/%.ok)
THIRD_PARTY_COMPILER_RT_A_DIRECTDEPS = \
LIBC_MATH \
LIBC_TINYMATH \
LIBC_STUBS
THIRD_PARTY_COMPILER_RT_A_DEPS := \

2
third_party/dlmalloc/dlmalloc.c vendored

@ -1029,5 +1029,3 @@ void *dlrealloc(void *oldmem, size_t bytes) { @@ -1029,5 +1029,3 @@ void *dlrealloc(void *oldmem, size_t bytes) {
}
return mem;
}
asm(".include \"third_party/dlmalloc/COPYING\"");

9644
third_party/dtoa/dtoa.c vendored

File diff suppressed because it is too large Load Diff

9
third_party/dtoa/dtoa.h vendored

@ -3,20 +3,15 @@ @@ -3,20 +3,15 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/* see also xdtoa() in //libc/x */
double strtod(const char *s00, char **se);
char *g_fmt(char *buf /*[32]*/, double x);
char *dtoa(double d, int mode, int ndigits, int *decpt, int *sign,
char **rve) nodiscard;
void freedtoa(char *s);
char *dtoa_r(double dd, int mode, int ndigits, int *decpt, int *sign,
char **rve, char *buf, size_t blen);
double plan9_strtod(const char *as, char **aas);
/* #if defined(TINY) || defined(TINY_STRTOD) */
/* #define strtod(X, Y) plan9_strtod(X, Y) */
/* #endif */
double strtod(const char *, char **);
double plan9_strtod(const char *, char **);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

43
third_party/xed/avx.h vendored

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_XED_AVX_H_
#define COSMOPOLITAN_THIRD_PARTY_XED_AVX_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
union XedAvxC4Payload1 {
struct {
unsigned map : 5;
unsigned b_inv : 1;
unsigned x_inv : 1;
unsigned r_inv : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
union XedAvxC4Payload2 {
struct {
unsigned pp : 2;
unsigned l : 1;
unsigned vvv210 : 3;
unsigned v3 : 1;
unsigned w : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
union XedAvxC5Payload {
struct {
unsigned pp : 2;
unsigned l : 1;
unsigned vvv210 : 3;
unsigned v3 : 1;
unsigned r_inv : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_XED_AVX_H_ */

44
third_party/xed/avx512.h vendored

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
#ifndef COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
union XedAvx512Payload1 {
struct {
unsigned map : 4;
unsigned rr_inv : 1;
unsigned b_inv : 1;
unsigned x_inv : 1;
unsigned r_inv : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
union XedAvx512Payload2 {
struct {
unsigned pp : 2;
unsigned ubit : 1;
unsigned vexdest210 : 3;
unsigned vexdest3 : 1;
unsigned rexw : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
union XedAvx512Payload3 {
struct {
unsigned mask : 3;
unsigned vexdest4p : 1;
unsigned bcrc : 1;
unsigned llrc : 2;
unsigned z : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_ */

167
third_party/xed/x86.h vendored

@ -313,12 +313,18 @@ struct XedChipFeatures { @@ -313,12 +313,18 @@ struct XedChipFeatures {
};
struct XedOperands {
/* data structure optimized for gcc code size */
uint8_t imm_width;
uint8_t map; /* enum XedIldMap */
uint8_t error; /* enum XedError */
uint8_t mode;
uint8_t rexw;
uint8_t osz;
uint8_t mode; /* real,legacy,long */
uint8_t modrm; /* selects address register */
uint8_t sib; /* scaled index base x86_64 */
uint8_t rexw : 1;
uint8_t rexr : 1;
uint8_t rexx : 1;
uint8_t rexb : 1;
uint8_t osz; /* operand size override prefix */
uint8_t max_bytes;
uint8_t nominal_opcode;
uint8_t out_of_bytes;
@ -326,6 +332,7 @@ struct XedOperands { @@ -326,6 +332,7 @@ struct XedOperands {
int64_t disp;
uint64_t uimm0;
enum XedChip chip;
uint8_t srm;
uint8_t amd3dnow;
uint8_t asz;
uint8_t bcrc;
@ -334,16 +341,11 @@ struct XedOperands { @@ -334,16 +341,11 @@ struct XedOperands {
uint8_t ild_f2;