mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 00:08:30 +00:00
Reduce header complexity
- Remove most __ASSEMBLER__ __LINKER__ ifdefs - Rename libc/intrin/bits.h to libc/serialize.h - Block pthread cancelation in fchmodat() polyfill - Remove `clang-format off` statements in third_party
This commit is contained in:
parent
96f979dfc5
commit
fa20edc44d
3057 changed files with 410 additions and 4398 deletions
17
third_party/stb/stb_image.c
vendored
17
third_party/stb/stb_image.c
vendored
|
@ -20,7 +20,8 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/serialize.h"
|
||||
#include "libc/intrin/bswap.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/log/gdb.h"
|
||||
#include "libc/log/log.h"
|
||||
|
@ -2937,11 +2938,23 @@ typedef struct {
|
|||
uint16_t value[288];
|
||||
} stbi__zhuffman;
|
||||
|
||||
static uint32_t ReverseBits32(uint32_t x) {
|
||||
x = bswap_32(x);
|
||||
x = (x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1;
|
||||
x = (x & 0xcccccccc) >> 2 | (x & 0x33333333) << 2;
|
||||
x = (x & 0xf0f0f0f0) >> 4 | (x & 0x0f0f0f0f) << 4;
|
||||
return x;
|
||||
}
|
||||
|
||||
static int ReverseBits16(int x) {
|
||||
return ReverseBits32(x) >> 16;
|
||||
}
|
||||
|
||||
forceinline int stbi__bit_reverse(int v, int bits) {
|
||||
assert(bits <= 16);
|
||||
// to bit reverse n bits, reverse 16 and shift
|
||||
// e.g. 11 bits, bit reverse and shift away 5
|
||||
return _bitreverse16(v) >> (16 - bits);
|
||||
return ReverseBits16(v) >> (16 - bits);
|
||||
}
|
||||
|
||||
static int stbi__zbuild_huffman(stbi__zhuffman *z,
|
||||
|
|
2
third_party/stb/stb_image.h
vendored
2
third_party/stb/stb_image.h
vendored
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
enum {
|
||||
|
@ -114,5 +113,4 @@ int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen,
|
|||
const char *ibuffer, int ilen);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_H_ */
|
||||
|
|
2
third_party/stb/stb_image_resize.h
vendored
2
third_party/stb/stb_image_resize.h
vendored
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_RESIZE_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_RESIZE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
// Easy-to-use API:
|
||||
|
@ -188,5 +187,4 @@ int stbir_resize_region(
|
|||
// style: [0, 1]x[0, 1]) of a region of the input image to use.
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_RESIZE_H_ */
|
||||
|
|
2
third_party/stb/stb_image_write.h
vendored
2
third_party/stb/stb_image_write.h
vendored
|
@ -1,6 +1,5 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_WRITE_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_WRITE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern int stbi_write_png_compression_level;
|
||||
|
@ -32,5 +31,4 @@ unsigned char *stbi_write_png_to_mem(const unsigned char *, int, int, int, int,
|
|||
void stbi_flip_vertically_on_write(int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_WRITE_H_ */
|
||||
|
|
1
third_party/stb/stb_rect_pack.c
vendored
1
third_party/stb/stb_rect_pack.c
vendored
|
@ -34,7 +34,6 @@ asm(".ident\t\"\\n\\n\
|
|||
stb_rect_pack (MIT License)\\n\
|
||||
Copyright 2017 Sean Barrett\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
|
|
2
third_party/stb/stb_rect_pack.h
vendored
2
third_party/stb/stb_rect_pack.h
vendored
|
@ -8,7 +8,6 @@
|
|||
#define STBRP_HEURISTIC_Skyline_BL_sortHeight 0
|
||||
#define STBRP_HEURISTIC_Skyline_BF_sortHeight 1
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
|
@ -46,5 +45,4 @@ void stbrp_setup_heuristic(stbrp_context *, int);
|
|||
int stbrp_pack_rects(stbrp_context *, stbrp_rect *, int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_STB_STB_RECT_PACK_H_ */
|
||||
|
|
3
third_party/stb/stb_truetype.c
vendored
3
third_party/stb/stb_truetype.c
vendored
|
@ -27,7 +27,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/stb/stb_truetype.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/serialize.h"
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
|
@ -40,7 +40,6 @@ asm(".ident\t\"\\n\\n\
|
|||
stb_truetype (MIT License)\\n\
|
||||
Copyright 2017 Sean Barrett\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
/* clang-format off */
|
||||
|
||||
// stb_truetype.h - v1.26 - public domain
|
||||
// authored from 2009-2021 by Sean Barrett / RAD Game Tools
|
||||
|
|
2
third_party/stb/stb_truetype.h
vendored
2
third_party/stb/stb_truetype.h
vendored
|
@ -69,7 +69,6 @@
|
|||
|
||||
#define STBTT_POINT_SIZE(x) (-(x))
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
typedef int16_t stbtt_vertex_type;
|
||||
|
@ -258,5 +257,4 @@ const char *stbtt_GetFontNameString(const stbtt_fontinfo *, int *, int, int,
|
|||
int, int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_STB_STB_TRUETYPE_H_ */
|
||||
|
|
36
third_party/stb/stb_vorbis.c
vendored
36
third_party/stb/stb_vorbis.c
vendored
|
@ -32,17 +32,18 @@
|
|||
// manxorist@github saga musix github:infatum
|
||||
// Timur Gagiev Maxwell Koo
|
||||
//
|
||||
#include "third_party/stb/stb_vorbis.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/serialize.h"
|
||||
#include "libc/intrin/bswap.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/alloca.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/stb/stb_vorbis.h"
|
||||
|
||||
// STB_VORBIS_NO_PUSHDATA_API
|
||||
// does not compile the code for the various stb_vorbis_*_pushdata()
|
||||
|
@ -66,7 +67,7 @@
|
|||
// STB_VORBIS_NO_FAST_SCALED_FLOAT
|
||||
// does not use a fast float-to-int trick to accelerate float-to-int on
|
||||
// most platforms which requires endianness be defined correctly.
|
||||
//#define STB_VORBIS_NO_FAST_SCALED_FLOAT
|
||||
// #define STB_VORBIS_NO_FAST_SCALED_FLOAT
|
||||
|
||||
// STB_VORBIS_MAX_CHANNELS [number]
|
||||
// globally define this to the maximum number of channels you need.
|
||||
|
@ -141,7 +142,7 @@
|
|||
// because otherwise an integer divide-per-vector-element is required to
|
||||
// unpack the index. If you define STB_VORBIS_DIVIDES_IN_CODEBOOK, you can
|
||||
// trade off storage for speed.
|
||||
//#define STB_VORBIS_DIVIDES_IN_CODEBOOK
|
||||
// #define STB_VORBIS_DIVIDES_IN_CODEBOOK
|
||||
|
||||
#ifdef STB_VORBIS_CODEBOOK_SHORTS
|
||||
#error \
|
||||
|
@ -613,6 +614,17 @@ static void add_entry(Codebook *c, uint32 huff_code, int symbol, int count,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverses bits in 32-bit word.
|
||||
*/
|
||||
static uint32_t ReverseBits32(uint32_t x) {
|
||||
x = bswap_32(x);
|
||||
x = (x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1;
|
||||
x = (x & 0xcccccccc) >> 2 | (x & 0x33333333) << 2;
|
||||
x = (x & 0xf0f0f0f0) >> 4 | (x & 0x0f0f0f0f) << 4;
|
||||
return x;
|
||||
}
|
||||
|
||||
static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) {
|
||||
int i, k, m = 0;
|
||||
uint32 available[32];
|
||||
|
@ -649,7 +661,7 @@ static int compute_codewords(Codebook *c, uint8 *len, int n, uint32 *values) {
|
|||
res = available[z];
|
||||
assert(z >= 0 && z < 32);
|
||||
available[z] = 0;
|
||||
add_entry(c, _bitreverse32(res), i, m++, len[i], values);
|
||||
add_entry(c, ReverseBits32(res), i, m++, len[i], values);
|
||||
// propagate availability up the tree
|
||||
if (z != len[i]) {
|
||||
assert(len[i] >= 0 && len[i] < 32);
|
||||
|
@ -675,7 +687,7 @@ static void compute_accelerated_huffman(Codebook *c) {
|
|||
for (i = 0; i < len; ++i) {
|
||||
if (c->codeword_lengths[i] <= STB_VORBIS_FAST_HUFFMAN_LENGTH) {
|
||||
uint32 z =
|
||||
c->sparse ? _bitreverse32(c->sorted_codewords[i]) : c->codewords[i];
|
||||
c->sparse ? ReverseBits32(c->sorted_codewords[i]) : c->codewords[i];
|
||||
// set table entries for all bit combinations in the higher bits
|
||||
while (z < FAST_HUFFMAN_TABLE_SIZE) {
|
||||
c->fast_huffman[z] = i;
|
||||
|
@ -720,11 +732,11 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths,
|
|||
int k = 0;
|
||||
for (i = 0; i < c->entries; ++i)
|
||||
if (include_in_sort(c, lengths[i]))
|
||||
c->sorted_codewords[k++] = _bitreverse32(c->codewords[i]);
|
||||
c->sorted_codewords[k++] = ReverseBits32(c->codewords[i]);
|
||||
assert(k == c->sorted_entries);
|
||||
} else {
|
||||
for (i = 0; i < c->sorted_entries; ++i)
|
||||
c->sorted_codewords[i] = _bitreverse32(c->codewords[i]);
|
||||
c->sorted_codewords[i] = ReverseBits32(c->codewords[i]);
|
||||
}
|
||||
|
||||
qsort(c->sorted_codewords, c->sorted_entries, sizeof(c->sorted_codewords[0]),
|
||||
|
@ -740,7 +752,7 @@ static void compute_sorted_huffman(Codebook *c, uint8 *lengths,
|
|||
for (i = 0; i < len; ++i) {
|
||||
int huff_len = c->sparse ? lengths[values[i]] : lengths[i];
|
||||
if (include_in_sort(c, huff_len)) {
|
||||
uint32 code = _bitreverse32(c->codewords[i]);
|
||||
uint32 code = ReverseBits32(c->codewords[i]);
|
||||
int x = 0, n = c->sorted_entries;
|
||||
while (n > 1) {
|
||||
// invariant: sc[x] <= code < sc[x+n]
|
||||
|
@ -808,7 +820,7 @@ static void compute_window(int n, float *window) {
|
|||
static void compute_bitreverse(int n, uint16 *rev) {
|
||||
int ld = ilog(n) - 1; // ilog is off-by-one from normal definitions
|
||||
int i, n8 = n >> 3;
|
||||
for (i = 0; i < n8; ++i) rev[i] = (_bitreverse32(i) >> (32 - ld + 3)) << 2;
|
||||
for (i = 0; i < n8; ++i) rev[i] = (ReverseBits32(i) >> (32 - ld + 3)) << 2;
|
||||
}
|
||||
|
||||
static int init_blocksize(vorb *f, int b, int n) {
|
||||
|
@ -1182,7 +1194,7 @@ static int codebook_decode_scalar_raw(vorb *f, Codebook *c) {
|
|||
// sorted_codewords && c->entries > 8
|
||||
if (c->entries > 8 ? c->sorted_codewords != NULL : !c->codewords) {
|
||||
// binary search
|
||||
uint32 code = _bitreverse32(f->acc);
|
||||
uint32 code = ReverseBits32(f->acc);
|
||||
int x = 0, n = c->sorted_entries, len;
|
||||
|
||||
while (n > 1) {
|
||||
|
@ -2560,7 +2572,7 @@ void inverse_mdct_naive(float *buffer, int n)
|
|||
|
||||
// step 4
|
||||
for (i=0; i < n8; ++i) {
|
||||
int j = _bitreverse32(i) >> (32-ld+3);
|
||||
int j = ReverseBits32(i) >> (32-ld+3);
|
||||
assert(j < n8);
|
||||
if (i == j) {
|
||||
// paper bug: original code probably swapped in place; if copying,
|
||||
|
|
2
third_party/stb/stb_vorbis.h
vendored
2
third_party/stb/stb_vorbis.h
vendored
|
@ -1,7 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_STB_STB_VORBIS_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_STB_STB_VORBIS_H_
|
||||
#include "libc/stdio/stdio.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
enum STBVorbisError {
|
||||
|
@ -260,5 +259,4 @@ int stb_vorbis_get_samples_short(stb_vorbis *f, int channels, short **buffer,
|
|||
// no more samples in the file, returns 0.
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_STB_STB_VORBIS_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue