mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Port a lot more code to AARCH64
- Introduce epoll_pwait() - Rewrite -ftrapv and ffs() libraries in C code - Use more FreeBSD code in math function library - Get significantly more tests passing on qemu-aarch64 - Fix many Musl long double functions that were broken on AARCH64
This commit is contained in:
parent
91791e9f38
commit
550b52abf6
158 changed files with 6018 additions and 3499 deletions
|
@ -16,10 +16,11 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/machine.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/build/lib/abp.h"
|
||||
#include "tool/build/lib/address.h"
|
||||
|
@ -35,7 +36,6 @@
|
|||
#include "tool/build/lib/flags.h"
|
||||
#include "tool/build/lib/fpu.h"
|
||||
#include "tool/build/lib/ioports.h"
|
||||
#include "tool/build/lib/machine.h"
|
||||
#include "tool/build/lib/memory.h"
|
||||
#include "tool/build/lib/modrm.h"
|
||||
#include "tool/build/lib/op101.h"
|
||||
|
@ -600,11 +600,11 @@ static void OpSax(struct Machine *m, uint32_t rde) {
|
|||
|
||||
static void OpConvert(struct Machine *m, uint32_t rde) {
|
||||
if (Rexw(rde)) {
|
||||
Write64(m->dx, Read64(m->ax) & 0x8000000000000000 ? 0xffffffffffffffff : 0);
|
||||
Write64(m->dx, (uint64_t)((int64_t)Read64(m->ax) >> 63));
|
||||
} else if (!Osz(rde)) {
|
||||
Write64(m->dx, Read32(m->ax) & 0x80000000 ? 0xffffffff : 0);
|
||||
Write64(m->dx, (uint32_t)((int32_t)Read32(m->ax) >> 31));
|
||||
} else {
|
||||
Write16(m->dx, Read16(m->ax) & 0x8000 ? 0xffff : 0);
|
||||
Write16(m->dx, (uint16_t)((int16_t)Read16(m->ax) >> 15));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 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/math.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/x/x.h"
|
||||
#include "third_party/gdtoa/gdtoa.h"
|
||||
|
||||
const char kConfig[] = "\
|
||||
/* FPU Control Word (x87) Exception Masks\n\
|
||||
@see Intel Manual V1 §8.1.5\n\
|
||||
IM: Invalid Operation ───────────────┐\n\
|
||||
DM: Denormal Operand ───────────────┐│\n\
|
||||
ZM: Zero Divide ───────────────────┐││\n\
|
||||
OM: Overflow ─────────────────────┐│││\n\
|
||||
UM: Underflow ───────────────────┐││││\n\
|
||||
PM: Precision ──────────────────┐│││││\n\
|
||||
PC: Precision Control ────────┐ ││││││\n\
|
||||
{float,∅,double,long double} │ ││││││\n\
|
||||
RC: Rounding Control ───────┐ │ ││││││\n\
|
||||
{even, →-∞, →+∞, →0} │┌┤ ││││││\n\
|
||||
┌┤││ ││││││\n\
|
||||
d││││rr││││││*/\n\
|
||||
";
|
||||
|
||||
const char kStatus[] = "\
|
||||
/* FPU Status Word (x87)\n\
|
||||
@see Intel Manual V1 §8.1.3\n\
|
||||
IE: Invalid Operation ────────────────┐\n\
|
||||
DE: Denormalized Operand ────────────┐│\n\
|
||||
ZE: Zero Divide ────────────────────┐││\n\
|
||||
OE: Overflow Flag ─────────────────┐│││\n\
|
||||
UE: Underflow Flag ───────────────┐││││\n\
|
||||
PE: Precision Flag ──────────────┐│││││\n\
|
||||
SF: Stack Fault ────────────────┐││││││\n\
|
||||
ES: Exception Summary Status ──┐│││││││\n\
|
||||
C0-3: Condition Codes ──┬────┐ ││││││││\n\
|
||||
TOP of Stack Pointer ─────┐ │ ││││││││\n\
|
||||
B: FPU Busy ───────────┐│ │ │ ││││││││\n\
|
||||
││┌┴┐┌┼┐││││││││\n\
|
||||
│↓│ │↓↓↓││││││││*/\n\
|
||||
";
|
||||
|
||||
const char kRegister[] = "\
|
||||
/\t┌sign\n\
|
||||
/\t│ ┌exponent\n\
|
||||
/\t│ │ ┌intpart\n\
|
||||
/\t│ │ │ ┌fraction\n\
|
||||
/\t│ │ │ │\n\
|
||||
/\t│┌┴────────────┐│┌┴────────────────────────────────────────────────────────────┐\n";
|
||||
|
||||
void PrintRegister(long double x) {
|
||||
char buf[32];
|
||||
uint16_t lo, hi;
|
||||
memcpy(buf, &x, sizeof(x));
|
||||
memcpy(&lo, &buf[0], sizeof(lo));
|
||||
memcpy(&hi, &buf[8], sizeof(hi));
|
||||
g_xfmt_p(buf, &x, 15, 32, 0);
|
||||
printf("/\t%016lb%064lb %s\n", hi, lo, buf);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
double d;
|
||||
unsigned short sw;
|
||||
long double st0, st1;
|
||||
|
||||
#define ST0 1
|
||||
#define ST1 2
|
||||
d = 0;
|
||||
st0 = ST0;
|
||||
st1 = ST1;
|
||||
asm("fstl\t%1\n\t"
|
||||
"fstsw"
|
||||
: "=a"(sw), "=m"(d) /*, "+t"(st0), "+u"(st1) */);
|
||||
printf("\n%s%016b\n\n%s", kStatus, sw, kRegister);
|
||||
PrintRegister(st0);
|
||||
PrintRegister(st1);
|
||||
printf("/\t%-80s %s\n", "d", gc(xdtoa(d)));
|
||||
|
||||
#if 0
|
||||
#define ST0 2e18L
|
||||
#define ST1 0.0000000000000123L
|
||||
st0 = ST0;
|
||||
st1 = ST1;
|
||||
asm("fldpi\n\t"
|
||||
"fadd\t%%st\n\t"
|
||||
"fxch\n2:\t"
|
||||
"fprem1\n\t"
|
||||
"fnstsw\n\t"
|
||||
"test\t$4,%%ah\n\t"
|
||||
"jnz\t2b\n\t"
|
||||
"fstp\t%%st(1)\n\t"
|
||||
"fsin\n\t"
|
||||
"fstsw"
|
||||
: "=a"(sw), "+t"(st0), "+u"(st1));
|
||||
printf("\n%s%016b\n\n%s", kStatus, sw, kRegister);
|
||||
PrintRegister(st0);
|
||||
PrintRegister(st1);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
st0 = ST0;
|
||||
st1 = ST1;
|
||||
asm("fsin\n\t"
|
||||
"fstsw"
|
||||
: "=a"(sw), "+t"(st0), "+u"(st1));
|
||||
printf("\n%s%016b\n\n%s", kStatus, sw, kRegister);
|
||||
PrintRegister(st0);
|
||||
PrintRegister(st1);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
printf("\n");
|
||||
PrintRegister(sinl(remainderl(2e40L, M_PI * 2)));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -54,6 +54,7 @@ TOOL_NET_DIRECTDEPS = \
|
|||
NET_HTTP \
|
||||
NET_HTTPS \
|
||||
THIRD_PARTY_ARGON2 \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
THIRD_PARTY_LINENOISE \
|
||||
|
|
|
@ -139,8 +139,10 @@
|
|||
STATIC_STACK_SIZE(0x40000);
|
||||
STATIC_YOINK("zip_uri_support");
|
||||
#if !IsTiny()
|
||||
#ifdef __x86_64__
|
||||
STATIC_YOINK("ShowCrashReportsEarly");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @fileoverview redbean - single-file distributable web server
|
||||
|
@ -171,8 +173,8 @@ STATIC_YOINK("ShowCrashReportsEarly");
|
|||
#define MONITOR_MICROS 150000
|
||||
#define READ(F, P, N) readv(F, &(struct iovec){P, N}, 1)
|
||||
#define WRITE(F, P, N) writev(F, &(struct iovec){P, N}, 1)
|
||||
#define LockInc(P) asm volatile("lock incq\t%0" : "=m"(*(P)))
|
||||
#define LockDec(P) asm volatile("lock decq\t%0" : "=m"(*(P)))
|
||||
#define LockInc(P) (*(_Atomic(typeof(*(P))) *)(P))++
|
||||
#define LockDec(P) (*(_Atomic(typeof(*(P))) *)(P))--
|
||||
#define AppendCrlf(P) mempcpy(P, "\r\n", 2)
|
||||
#define HasHeader(H) (!!cpm.msg.headers[H].a)
|
||||
#define HeaderData(H) (inbuf.p + cpm.msg.headers[H].a)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
ifeq ($(ARCH), x86_64)
|
||||
|
||||
PKGS += TOOL_PLINKO_LIB
|
||||
|
||||
TOOL_PLINKO_LIB_ARTIFACTS += TOOL_PLINKO_LIB_A
|
||||
|
@ -68,5 +70,7 @@ TOOL_PLINKO_LIB_CHECKS = $(foreach x,$(TOOL_PLINKO_LIB_ARTIFACTS),$($(x)_CHECKS)
|
|||
TOOL_PLINKO_LIB_OBJS = $(foreach x,$(TOOL_PLINKO_LIB_ARTIFACTS),$($(x)_OBJS))
|
||||
TOOL_PLINKO_LIB_TESTS = $(foreach x,$(TOOL_PLINKO_LIB_ARTIFACTS),$($(x)_TESTS))
|
||||
|
||||
endif
|
||||
|
||||
.PHONY: o/$(MODE)/tool/plinko/lib
|
||||
o/$(MODE)/tool/plinko/lib: $(TOOL_PLINKO_LIB_CHECKS)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
ifeq ($(ARCH), x86_64)
|
||||
|
||||
PKGS += TOOL_PLINKO
|
||||
|
||||
TOOL_PLINKO_SRCS := $(wildcard tool/plinko/*.c)
|
||||
|
@ -65,6 +67,7 @@ o/$(MODE)/tool/plinko/lib/ok.lisp.zip.o: \
|
|||
ZIPOBJ_FLAGS += \
|
||||
-B
|
||||
|
||||
endif
|
||||
|
||||
.PHONY: o/$(MODE)/tool/plinko
|
||||
o/$(MODE)/tool/plinko: $(TOOL_PLINKO_BINS) $(TOOL_PLINKO_CHECKS)
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "libc/x/xasprintf.h"
|
||||
#include "tool/decode/lib/idname.h"
|
||||
#include "tool/decode/lib/x86idnames.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
#define CANIUSE(FEATURE) caniuse(#FEATURE, X86_HAVE(FEATURE))
|
||||
#define SHOW(CONSTANT) show(#CONSTANT, CONSTANT)
|
||||
|
@ -333,3 +334,5 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "third_party/getopt/getopt.h"
|
||||
#include "third_party/stb/stb_image.h"
|
||||
#include "third_party/stb/stb_image_resize.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
#define HELPTEXT \
|
||||
"\n\
|
||||
|
@ -616,3 +617,5 @@ int main(int argc, char *argv[]) {
|
|||
munmap(rgb, ROUNDUP(size, FRAMESIZE));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "libc/time/time.h"
|
||||
#include "tool/decode/lib/flagger.h"
|
||||
#include "tool/decode/lib/idname.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
char *GetString(struct NtUnicodeString *s) {
|
||||
static char buf[1024];
|
||||
|
@ -537,3 +538,5 @@ int main(int argc, char *argv[]) {
|
|||
PrintModulesMemoryOrder();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -1409,7 +1409,9 @@ static void OnExit(void) {
|
|||
}
|
||||
|
||||
static void MakeLatencyLittleLessBad(void) {
|
||||
#ifdef __x86_64__
|
||||
_peekall();
|
||||
#endif
|
||||
LOGIFNEG1(sys_mlockall(MCL_CURRENT));
|
||||
LOGIFNEG1(nice(-5));
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "third_party/xed/x86.h"
|
||||
#ifdef __x86_64__
|
||||
|
||||
#define OUTPATH "vdso.elf"
|
||||
|
||||
|
@ -80,3 +81,5 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __x86_64__ */
|
||||
|
|
|
@ -43,6 +43,7 @@ TOOL_VIZ_DIRECTDEPS = \
|
|||
LIBC_X \
|
||||
LIBC_ZIPOS \
|
||||
NET_HTTP \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_DLMALLOC \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_GETOPT \
|
||||
|
@ -81,7 +82,8 @@ o/$(MODE)/tool/viz/printimage.com.dbg: \
|
|||
o/$(MODE)/tool/viz/printimage.com: \
|
||||
o/$(MODE)/tool/viz/printimage.com.dbg \
|
||||
o/$(MODE)/third_party/zip/zip.com \
|
||||
o/$(MODE)/tool/build/symtab.com
|
||||
o/$(MODE)/tool/build/symtab.com \
|
||||
$(VM)
|
||||
@$(MAKE_OBJCOPY)
|
||||
@$(MAKE_SYMTAB_CREATE)
|
||||
@$(MAKE_SYMTAB_ZIP)
|
||||
|
@ -89,7 +91,8 @@ o/$(MODE)/tool/viz/printimage.com: \
|
|||
o/$(MODE)/tool/viz/printvideo.com: \
|
||||
o/$(MODE)/tool/viz/printvideo.com.dbg \
|
||||
o/$(MODE)/third_party/zip/zip.com \
|
||||
o/$(MODE)/tool/build/symtab.com
|
||||
o/$(MODE)/tool/build/symtab.com \
|
||||
$(VM)
|
||||
@$(MAKE_OBJCOPY)
|
||||
@$(MAKE_SYMTAB_CREATE)
|
||||
@$(MAKE_SYMTAB_ZIP)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue