Improve signal handling and math

- Polyfill ucontext_t on FreeBSD/OpenBSD/NetBSD
- Add tests confirming signals can edit CPU state
- Work towards supporting ZIP filesystem on bare metal
- Add more tinymath unit tests for POSIX conformance
- Add X87 and SSE status flags to crash report
- Fix some bugs in blinkenlights
- Fix llvm build breakage
This commit is contained in:
Justine Tunney 2021-02-25 18:30:17 -08:00
parent cdc54ea1fd
commit 40291c9db3
109 changed files with 2316 additions and 520 deletions

View file

@ -21,6 +21,11 @@
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#define hypotl(x, y) \
hypotl(VEIL("t", (long double)(x)), VEIL("t", (long double)(y)))
#define hypot(x, y) hypot(VEIL("x", (double)(x)), VEIL("x", (double)(y)))
#define hypotf(x, y) hypotf(VEIL("x", (float)(x)), VEIL("x", (float)(y)))
TEST(hypot, test) {
EXPECT_STREQ("0", gc(xdtoa(hypot(0, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypot(3, 0))));
@ -33,12 +38,12 @@ TEST(hypot, test) {
EXPECT_STREQ("5", gc(xdtoa(hypot(4, -3))));
EXPECT_STREQ("5", gc(xdtoa(hypot(-3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypot(-4, -3))));
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypot(1, 1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypot(1, -1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypot(-1, 1))));
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypot(1.0000001, .99999999))));
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypot(.99999999, 1.0000001))));
EXPECT_STREQ("1.414213562373095e+154", gc(xdtoa(hypot(1e154, 1e154))));
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(1, 1))));
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(1, -1))));
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(-1, 1))));
EXPECT_STREQ("1.41421362601271", gc(xdtoa(hypot(1.0000001, .99999999))));
EXPECT_STREQ("1.41421362601271", gc(xdtoa(hypot(.99999999, 1.0000001))));
EXPECT_STREQ("1.4142135623731e+154", gc(xdtoa(hypot(1e154, 1e154))));
EXPECT_STREQ("NAN", gc(xdtoa(hypot(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoa(hypot(NAN, 0))));
EXPECT_STREQ("NAN", gc(xdtoa(hypot(NAN, NAN))));
@ -61,12 +66,12 @@ TEST(hypotf, test) {
EXPECT_STREQ("5", gc(xdtoa(hypotf(4, -3))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(-3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(-4, -3))));
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(1, 1))));
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(1, -1))));
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(-1, 1))));
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(1.000001, 0.999999))));
EXPECT_STREQ("1.414214", gc(xdtoaf(hypotf(0.999999, 1.000001))));
EXPECT_STREQ("1.414214e+38", gc(xdtoaf(hypotf(1e38, 1e38))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1, 1))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1, -1))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(-1, 1))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1.000001, 0.999999))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(0.999999, 1.000001))));
EXPECT_STREQ("1.41421e+38", gc(xdtoaf(hypotf(1e38, 1e38))));
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(NAN, 0))));
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(NAN, NAN))));
@ -78,31 +83,31 @@ TEST(hypotf, test) {
}
TEST(hypotll, test) {
EXPECT_STREQ("0", gc(xdtoa(hypotl(0, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypotl(3, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypotl(0, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(3, 4))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(4, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(-4, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(-3, 4))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(4, -3))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(-3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypotl(-4, -3))));
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypotl(1, 1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypotl(1, -1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoa(hypotl(-1, 1))));
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypotl(1.0000001, .99999999))));
EXPECT_STREQ("1.414213626012708", gc(xdtoa(hypotl(.99999999, 1.0000001))));
EXPECT_STREQ("1.414213562373095e+4931", gc(xdtoa(hypotl(1e4931L, 1e4931L))));
EXPECT_STREQ("NAN", gc(xdtoa(hypotl(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoa(hypotl(NAN, 0))));
EXPECT_STREQ("NAN", gc(xdtoa(hypotl(NAN, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(INFINITY, 0))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(0, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(INFINITY, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(NAN, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypotl(INFINITY, INFINITY))));
EXPECT_STREQ("0", gc(xdtoal(hypotl(0, 0))));
EXPECT_STREQ("3", gc(xdtoal(hypotl(3, 0))));
EXPECT_STREQ("3", gc(xdtoal(hypotl(0, 3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(3, 4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(4, 3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(3, -4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-4, 3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-3, 4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(4, -3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-3, -4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-4, -3))));
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(1, 1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(1, -1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(-1, 1))));
EXPECT_STREQ("1.414213626012708", gc(xdtoal(hypotl(1.0000001, .99999999))));
EXPECT_STREQ("1.414213626012708", gc(xdtoal(hypotl(.99999999, 1.0000001))));
EXPECT_STREQ("1.414213562373095e+4931", gc(xdtoal(hypotl(1e4931L, 1e4931L))));
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(NAN, 0))));
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(NAN, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, 0))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(0, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(NAN, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, INFINITY))));
}
BENCH(hypot, bench) {