Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bend2/comp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3352,6 +3352,7 @@ typedef u32 __attribute__((may_alias)) u32a;
#define RFC_BIT (1ull << 63)
#define RFC_CNT ((1u << 24) - 1)
#define NAT_IMM ((1ull << 48) - 1)
#define ILP32 (sizeof(void*) < 8)

enum { ERR_RING = 1, ERR_TAGS, ERR_HEAP, ERR_FIDS, ERR_NATS, ERR_RFCS,
ERR_DEEP, ERR_ARRS, ERR_CNTS };
Expand Down Expand Up @@ -4695,7 +4696,7 @@ static void* pool_mmap(u64 bytes) {
}

static Term* pool_stack(void) {
u64 len = 1ull << 31;
u64 len = 1ull << (ILP32 ? 26 : 31);
u64 alt = 4 * SIGSTKSZ;
char* p = pool_mmap(len + 16384 + alt);
if (mprotect(p + len, 16384, PROT_NONE)) {
Expand Down Expand Up @@ -5230,7 +5231,8 @@ static void cube_run(u64* H, bool gpu) {
// ======

// The cores map 8 GiB at a high base and double it in place; the banks move
// up past the pages. The GPU maps its whole span once.
// up past the pages. A 32-bit host maps 1 GiB, and 64 MiB per stack. The
// GPU maps its whole span once.

static u64 corpus_size;

Expand Down Expand Up @@ -5286,8 +5288,8 @@ static bool corpus_grow(u64* H, u64 need) {
static u64* corpus_setup(bool gpu, long threads, u64 bytes) {
io_gpu = gpu;
KEEP_WORDS = gpu ? CHUNK : CAP_WORDS;
u64 size = (!gpu ? 1ull << 33 : bytes != 0 ? bytes : gpu_span())
& ~16383ull;
u64 size = (!gpu ? 1ull << (ILP32 ? 30 : 33) : bytes != 0 ? bytes
: gpu_span()) & ~16383ull;
CORPUS = gpu ? gpu_map(size) : corpus_map(size);
u64* H = CORPUS;
corpus_lay(H, size);
Expand Down
25 changes: 20 additions & 5 deletions bend2/effs/file_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ static void file_line_drop(int fd) {

#endif

// A 32-bit host has no room for a buffer of max bytes: there it starts at
// 64 KiB and doubles as it fills. w->size is its length until the answer.
// How many bytes fit past got.
static u64 file_read_room(IoWork* w, u64 got) {
if (got == w->size && got < w->word) {
w->size = w->size < w->word / 2 ? w->size * 2 : w->word;
w->data = io_mem(realloc(w->data, w->size + 1));
}
return w->size - got;
}

// read(2) answers what is there, not what was asked: a pipe, a terminal
// and a short read all stop before max. Fill the buffer or reach EOF, so
// a caller that asked for n bytes gets n unless the file ends first,
Expand All @@ -117,17 +128,19 @@ static void file_read_fill(IoWork* w, int at) {
w->code = 0;
#ifdef CID(File.read_line)
FileLine* b = at ? NULL : file_line_of(fd, false);
got = b != NULL ? file_line_take(b, w->data, w->word, 0, NULL) : 0;
got = b != NULL
? file_line_take(b, w->data, file_read_room(w, 0), 0, NULL) : 0;
if (got > 0 && got == w->word) {
w->size = got;
return;
}
#endif
do {
u64 want = w->word - got;
u64 want = file_read_room(w, got);
ssize_t n;
do {
n = at ? pread(fd, w->data + got, want, (off_t)(w->made + got))
n = at ? pread(fd, w->data + got, want,
(off_t)((uintptr_t)w->made + got))
: read(fd, w->data + got, want);
} while (n < 0 && errno == EINTR);
if (n <= 0) {
Expand All @@ -147,7 +160,8 @@ static Term file_read_start(Term file, u64 max, IoWork* w,
IoCall call, IoPack pack) {
w->hand = (intptr_t)io_hand_v(file);
w->word = max < INT32_MAX ? max : INT32_MAX;
w->data = io_mem(malloc(w->word + 1));
w->size = ILP32 && w->word > 65536 ? 65536 : w->word;
w->data = io_mem(malloc(w->size + 1));
io_sync();
return io_work(w, call, pack);
}
Expand Down Expand Up @@ -203,7 +217,8 @@ static void file_read_line_call(IoWork* w) {
b->head = 0;
b->tail = (u64)n;
}
got += file_line_take(b, w->data + got, w->word - got, 1, &end);
u64 room = file_read_room(w, got);
got += file_line_take(b, w->data + got, room, 1, &end);
}
w->size = got;
}
Expand Down
3 changes: 2 additions & 1 deletion bend2/effs/file_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ static void file_write_fill(IoWork* w, int at_offset) {
#endif
for (uint64_t at = 0; n >= 0 && at < w->size; at += (uint64_t)n) {
do {
n = at_offset ? pwrite(fd, w->data + at, w->size - at, (off_t)(w->made + at))
n = at_offset ? pwrite(fd, w->data + at, w->size - at,
(off_t)((uintptr_t)w->made + at))
: write(fd, w->data + at, w->size - at);
} while (n < 0 && errno == EINTR);
// no progress would retry forever (#1445)
Expand Down
5 changes: 4 additions & 1 deletion bend2/effs/tcp_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ static Term tcp_recv_start(Env e, Term* f, IoWork* w, IoPack more, u64 at) {
return io_tup(e, io_hand(w->hand), io_poll_end(e, w,
term_pak(CID(Unit), 0), io_fail(e, EINVAL, NULL)));
}
w->made = f[1] < INT32_MAX ? (intptr_t)f[1] : INT32_MAX;
// a 32-bit host has no room for a 2 GiB buffer: there a recv fills 16 MiB
// at most, which max allows
u64 cap = ILP32 ? 1 << 24 : INT32_MAX;
w->made = (intptr_t)(f[1] < cap ? f[1] : cap);
w->data = io_mem(malloc((size_t)w->made));
return more(e, w);
}
Expand Down
4 changes: 3 additions & 1 deletion bend2/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ function cli_build(bin: string, file: string): void {
? ["-x", "objective-c", "-fobjc-arc", "-fmodules"] : [];
const libs = [["X11", "X11", "dl"], ["alsa", "asound"]].flatMap(([h, ...ls]) =>
!mac && c.includes("#include <" + h + "/") ? ls.map((l) => "-l" + l) : []);
const cpu = [...objc, "-std=c11", "-O3", file, "-lpthread", "-lm",
// a 32-bit host: 64-bit file offsets and clocks, and no preserve_none
const cpu = [...objc, "-std=c11", "-O3", "-D_FILE_OFFSET_BITS=64",
"-D_TIME_BITS=64", "-Wno-ignored-attributes", file, "-lpthread", "-lm",
...libs, "-o", path.resolve(bin)];
const gpu = mac ? ["-DBEND_METAL=1", ...cpu]
: ["-DBEND_CUDA=1", "-I" + cuda + "/include", "-L" + cuda + "/lib64",
Expand Down
Loading