mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-30 06:20:28 +00:00
Make more fixes and improvements
- Remove PAGESIZE constant - Fix realloc() documentation - Fix ttyname_r() error reporting - Make forking more reliable on Windows - Make execvp() a few microseconds faster - Make system() a few microseconds faster - Tighten up the socket-related magic numbers - Loosen restrictions on mmap() offset alignment - Improve GetProgramExecutableName() with getenv("_") - Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd() - Fix flakes in pthread_cancel_test, unix_test, fork_test - Fix recently introduced futex stack overflow regression - Let sockets be passed as stdio to subprocesses on Windows - Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
parent
140a8a52e5
commit
18bb5888e1
311 changed files with 1239 additions and 2622 deletions
|
@ -35,6 +35,10 @@
|
|||
#define W 64
|
||||
#define C 253
|
||||
|
||||
static unsigned long roundup2pow(unsigned long x) {
|
||||
return x > 1 ? 2ul << _bsrl(x - 1) : x ? 1 : 0;
|
||||
}
|
||||
|
||||
void bf(int fd) {
|
||||
ssize_t rc;
|
||||
uint64_t w;
|
||||
|
@ -44,7 +48,7 @@ void bf(int fd) {
|
|||
char ibuf[W], obuf[12 + 1 + W * 6 + 1 + W * (2 + 11) + 11 + 1];
|
||||
o = 0;
|
||||
if (fstat(fd, &st) != -1 && S_ISREG(st.st_mode) && st.st_size) {
|
||||
bits = _bsr(_roundup2pow(st.st_size));
|
||||
bits = _bsr(roundup2pow(st.st_size));
|
||||
bits = ROUNDUP(bits, 4);
|
||||
} else {
|
||||
bits = 48;
|
||||
|
|
|
@ -18,13 +18,12 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/tty/quant.h"
|
||||
#include "libc/intrin/hilbert.h"
|
||||
#include "libc/intrin/morton.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/viz/lib/graphic.h"
|
||||
#include "tool/viz/lib/knobs.h"
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "dsp/scale/scale.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/intrin/bsr.h"
|
||||
#include "libc/intrin/pmulhrsw.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/log.h"
|
||||
|
@ -80,6 +81,14 @@ struct YCbCr {
|
|||
} luma, chroma;
|
||||
};
|
||||
|
||||
static unsigned long roundup2pow(unsigned long x) {
|
||||
return x > 1 ? 2ul << _bsrl(x - 1) : x ? 1 : 0;
|
||||
}
|
||||
|
||||
static unsigned long rounddown2pow(unsigned long x) {
|
||||
return x ? 1ul << _bsrl(x) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes magnums for Y′CbCr decoding.
|
||||
*
|
||||
|
@ -95,8 +104,8 @@ void YCbCrComputeCoefficients(int swing, double gamma,
|
|||
double x;
|
||||
double f1[6][3];
|
||||
long longs[6][6];
|
||||
long bitlimit = _roundup2pow(swing);
|
||||
long wordoffset = _rounddown2pow((bitlimit - swing) / 2);
|
||||
long bitlimit = roundup2pow(swing);
|
||||
long wordoffset = rounddown2pow((bitlimit - swing) / 2);
|
||||
long chromaswing = swing + 2 * (bitlimit / 2. - swing / 2. - wordoffset);
|
||||
long lumamin = wordoffset;
|
||||
long lumamax = wordoffset + swing;
|
||||
|
|
|
@ -258,6 +258,12 @@ static char16_t statusline16[256];
|
|||
RES = (B11 | r0) & r1 & ~r2; \
|
||||
} while (0)
|
||||
|
||||
static void SwapBoards(void) {
|
||||
uint64_t *t = board;
|
||||
board = board2;
|
||||
board2 = t;
|
||||
}
|
||||
|
||||
static void Step(void) {
|
||||
long y, x, yn, xn;
|
||||
yn = byn >> 3;
|
||||
|
@ -275,7 +281,7 @@ static void Step(void) {
|
|||
board[(y + 1 < yn ? y + 1 : 0) * xn + (x + 1 < xn ? x + 1 : 0)]);
|
||||
}
|
||||
}
|
||||
xchg(&board, &board2);
|
||||
SwapBoards();
|
||||
++generation;
|
||||
}
|
||||
|
||||
|
@ -593,7 +599,7 @@ static int LoadFile(const char *path) {
|
|||
if ((c = ReadChar(f)) == -1) goto ReadError;
|
||||
}
|
||||
if (yn > byn || xn > bxn) goto ReadError;
|
||||
xchg(&board, &board2);
|
||||
SwapBoards();
|
||||
bzero(board, (byn * bxn) >> 3);
|
||||
yo = byn / 2 - yn / 2;
|
||||
xo = bxn / 2 - xn / 2;
|
||||
|
@ -640,7 +646,7 @@ static int LoadFile(const char *path) {
|
|||
return 0;
|
||||
ReadError:
|
||||
fclose(f);
|
||||
xchg(&board, &board2);
|
||||
SwapBoards();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/bsr.h"
|
||||
#include "libc/intrin/hilbert.h"
|
||||
#include "libc/intrin/morton.h"
|
||||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
@ -188,6 +188,10 @@ static void LeaveScreen(void) {
|
|||
Write("\e[H\e[J");
|
||||
}
|
||||
|
||||
static unsigned long rounddown2pow(unsigned long x) {
|
||||
return x ? 1ul << _bsrl(x) : 0;
|
||||
}
|
||||
|
||||
static void GetTtySize(void) {
|
||||
struct winsize wsize;
|
||||
wsize.ws_row = tyn + 1;
|
||||
|
@ -195,8 +199,8 @@ static void GetTtySize(void) {
|
|||
tcgetwinsize(out, &wsize);
|
||||
tyn = MAX(2, wsize.ws_row) - 1;
|
||||
txn = MAX(17, wsize.ws_col) - 16;
|
||||
tyn = _rounddown2pow(tyn);
|
||||
txn = _rounddown2pow(txn);
|
||||
tyn = rounddown2pow(tyn);
|
||||
txn = rounddown2pow(txn);
|
||||
tyn = MIN(tyn, txn);
|
||||
}
|
||||
|
||||
|
@ -278,11 +282,30 @@ static void SetupCanvas(void) {
|
|||
}
|
||||
displaysize = ROUNDUP(ROUNDUP((tyn * txn) << zoom, 16), 1ul << zoom);
|
||||
canvassize = ROUNDUP(displaysize, FRAMESIZE);
|
||||
buffersize = ROUNDUP(tyn * txn * 16 + PAGESIZE, FRAMESIZE);
|
||||
buffersize = ROUNDUP(tyn * txn * 16 + 4096, FRAMESIZE);
|
||||
canvas = Allocate(canvassize);
|
||||
buffer = Allocate(buffersize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interleaves bits.
|
||||
* @see https://en.wikipedia.org/wiki/Z-order_curve
|
||||
* @see unmorton()
|
||||
*/
|
||||
static unsigned long morton(unsigned long y, unsigned long x) {
|
||||
x = (x | x << 020) & 0x0000FFFF0000FFFF;
|
||||
x = (x | x << 010) & 0x00FF00FF00FF00FF;
|
||||
x = (x | x << 004) & 0x0F0F0F0F0F0F0F0F;
|
||||
x = (x | x << 002) & 0x3333333333333333;
|
||||
x = (x | x << 001) & 0x5555555555555555;
|
||||
y = (y | y << 020) & 0x0000FFFF0000FFFF;
|
||||
y = (y | y << 010) & 0x00FF00FF00FF00FF;
|
||||
y = (y | y << 004) & 0x0F0F0F0F0F0F0F0F;
|
||||
y = (y | y << 002) & 0x3333333333333333;
|
||||
y = (y | y << 001) & 0x5555555555555555;
|
||||
return x | y << 1;
|
||||
}
|
||||
|
||||
static long IndexSquare(long y, long x) {
|
||||
switch (order) {
|
||||
case LINEAR:
|
||||
|
|
|
@ -371,7 +371,7 @@ static bool CloseSpeaker(void) {
|
|||
}
|
||||
|
||||
static void ResizeVtFrame(struct VtFrame *f, size_t yn, size_t xn) {
|
||||
BALLOC(&f->b, PAGESIZE, 64 + yn * (xn * 32 + 8), __FUNCTION__);
|
||||
BALLOC(&f->b, 4096, 64 + yn * (xn * 32 + 8), __FUNCTION__);
|
||||
f->i = f->n = 0;
|
||||
}
|
||||
|
||||
|
@ -837,7 +837,8 @@ static void OnVideo(plm_t *mpeg, plm_frame_t *pf, void *user) {
|
|||
} else {
|
||||
TranscodeVideo(pf);
|
||||
if (!f1_->n) {
|
||||
xchg(&f1_, &f2_);
|
||||
struct VtFrame *t = f1_;
|
||||
f1_ = f2_, f2_ = t;
|
||||
f1_start_ = decode_start_;
|
||||
} else {
|
||||
f2_start_ = decode_start_;
|
||||
|
@ -872,7 +873,7 @@ static void OpenVideo(void) {
|
|||
static ssize_t WriteVideoCall(void) {
|
||||
size_t amt;
|
||||
ssize_t rc;
|
||||
amt = min(PAGESIZE * 4, f1_->n - f1_->i);
|
||||
amt = min(4096 * 4, f1_->n - f1_->i);
|
||||
if ((rc = write(outfd_, f1_->bytes + f1_->i, amt)) != -1) {
|
||||
if ((f1_->i += rc) == f1_->n) {
|
||||
if (plm_get_audio_enabled(plm_)) {
|
||||
|
@ -883,7 +884,8 @@ static ssize_t WriteVideoCall(void) {
|
|||
}
|
||||
f1_start_ = f2_start_;
|
||||
f1_->i = f1_->n = 0;
|
||||
xchg(&f1_, &f2_);
|
||||
struct VtFrame *t = f1_;
|
||||
f1_ = f2_, f2_ = t;
|
||||
RecordFactThatFrameWasFullyRendered();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue