mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +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
|
@ -2,74 +2,110 @@
|
|||
│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ FreeBSD lib/msun/src/s_asinhl.c │
|
||||
│ Converted to ldbl by David Schultz <das@FreeBSD.ORG> and Bruce D. Evans. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ Copyright (c) 1992-2023 The FreeBSD Project. │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ Redistribution and use in source and binary forms, with or without │
|
||||
│ modification, are permitted provided that the following conditions │
|
||||
│ are met: │
|
||||
│ 1. Redistributions of source code must retain the above copyright │
|
||||
│ notice, this list of conditions and the following disclaimer. │
|
||||
│ 2. Redistributions in binary form must reproduce the above copyright │
|
||||
│ notice, this list of conditions and the following disclaimer in the │
|
||||
│ documentation and/or other materials provided with the distribution. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND │
|
||||
│ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE │
|
||||
│ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE │
|
||||
│ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE │
|
||||
│ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL │
|
||||
│ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS │
|
||||
│ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) │
|
||||
│ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT │
|
||||
│ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY │
|
||||
│ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF │
|
||||
│ SUCH DAMAGE. │
|
||||
│ │
|
||||
│ Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. │
|
||||
│ Developed at SunPro, a Sun Microsystems, Inc. business. │
|
||||
│ Permission to use, copy, modify, and distribute this │
|
||||
│ software is freely granted, provided that this notice │
|
||||
│ is preserved. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/feval.internal.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
#include "libc/tinymath/ldshape.internal.h"
|
||||
#include "libc/tinymath/freebsd.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
FreeBSD libm (BSD-2 License)\\n\
|
||||
Copyright (c) 2005-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.\"");
|
||||
asm(".ident\t\"\\n\\n\
|
||||
fdlibm (fdlibm license)\\n\
|
||||
Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
// clang-format off
|
||||
|
||||
/* EXP_LARGE is the threshold above which we use asinh(x) ~= log(2x). */
|
||||
/* EXP_TINY is the threshold below which we use asinh(x) ~= x. */
|
||||
#if LDBL_MANT_DIG == 64
|
||||
#define EXP_LARGE 34
|
||||
#define EXP_TINY -34
|
||||
#elif LDBL_MANT_DIG == 113
|
||||
#define EXP_LARGE 58
|
||||
#define EXP_TINY -58
|
||||
#else
|
||||
#error "Unsupported long double format"
|
||||
#endif
|
||||
|
||||
#if LDBL_MAX_EXP != 0x4000
|
||||
/* We also require the usual expsign encoding. */
|
||||
#error "Unsupported long double format"
|
||||
#endif
|
||||
|
||||
#define BIAS (LDBL_MAX_EXP - 1)
|
||||
|
||||
static const double
|
||||
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
|
||||
huge= 1.00000000000000000000e+300;
|
||||
|
||||
#if LDBL_MANT_DIG == 64
|
||||
static const union IEEEl2bits
|
||||
u_ln2 = LD80C(0xb17217f7d1cf79ac, -1, 6.93147180559945309417e-1L);
|
||||
#define ln2 u_ln2.e
|
||||
#elif LDBL_MANT_DIG == 113
|
||||
static const long double
|
||||
ln2 = 6.93147180559945309417232121458176568e-1L; /* 0x162e42fefa39ef35793c7673007e6.0p-113 */
|
||||
#else
|
||||
#error "Unsupported long double format"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns inverse hyperbolic sine of 𝑥.
|
||||
* @define asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5)
|
||||
*/
|
||||
long double asinhl(long double x) {
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
return asinh(x);
|
||||
#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
|
||||
union ldshape u = {x};
|
||||
unsigned e = u.i.se & 0x7fff;
|
||||
unsigned s = u.i.se >> 15;
|
||||
long double
|
||||
asinhl(long double x)
|
||||
{
|
||||
long double t, w;
|
||||
uint16_t hx, ix;
|
||||
|
||||
/* |x| */
|
||||
u.i.se = e;
|
||||
x = u.f;
|
||||
|
||||
if (e >= 0x3fff + 32) {
|
||||
/* |x| >= 0x1p32 or inf or nan */
|
||||
x = logl(x) + 0.693147180559945309417232121458176568L;
|
||||
} else if (e >= 0x3fff + 1) {
|
||||
/* |x| >= 2 */
|
||||
x = logl(2*x + 1/(sqrtl(x*x+1)+x));
|
||||
} else if (e >= 0x3fff - 32) {
|
||||
/* |x| >= 0x1p-32 */
|
||||
x = log1pl(x + x*x/(sqrtl(x*x+1)+1));
|
||||
} else {
|
||||
/* |x| < 0x1p-32, raise inexact if x!=0 */
|
||||
FORCE_EVAL(x + 0x1p120f);
|
||||
ENTERI();
|
||||
GET_LDBL_EXPSIGN(hx, x);
|
||||
ix = hx & 0x7fff;
|
||||
if (ix >= 0x7fff) RETURNI(x+x); /* x is inf, NaN or misnormal */
|
||||
if (ix < BIAS + EXP_TINY) { /* |x| < TINY, or misnormal */
|
||||
if (huge + x > one) RETURNI(x); /* return x inexact except 0 */
|
||||
}
|
||||
return s ? -x : x;
|
||||
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
|
||||
// TODO: broken implementation to make things compile
|
||||
return asinh(x);
|
||||
#else
|
||||
#error "architecture unsupported"
|
||||
#endif
|
||||
if (ix >= BIAS + EXP_LARGE) { /* |x| >= LARGE, or misnormal */
|
||||
w = logl(fabsl(x))+ln2;
|
||||
} else if (ix >= 0x4000) { /* LARGE > |x| >= 2.0, or misnormal */
|
||||
t = fabsl(x);
|
||||
w = logl(2.0*t+one/(sqrtl(x*x+one)+t));
|
||||
} else { /* 2.0 > |x| >= TINY, or misnormal */
|
||||
t = x*x;
|
||||
w =log1pl(fabsl(x)+t/(one+sqrtl(one+t)));
|
||||
}
|
||||
RETURNI((hx & 0x8000) == 0 ? w : -w);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue