mirror of
https://github.com/jart/cosmopolitan.git
synced 2026-11-08 17:19:47 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8383f25b4 | ||
|
|
64a9e6fe56 | ||
|
|
0ef36489c8 | ||
|
|
7c7bf4bb90 | ||
|
|
592f6ebc20 | ||
|
|
af8f2bd19f | ||
|
|
38bceaeb8f | ||
|
|
99f0491f04 | ||
|
|
e72a88ea70 | ||
|
|
9b4701b3bc | ||
|
|
f7ff515961 | ||
|
|
3afe3a3646 | ||
|
|
b4faaa7c57 | ||
|
|
c4991e53ac | ||
|
|
ad3944a3b6 | ||
|
|
29eac8e2a2 | ||
|
|
a5a3e78fcf | ||
|
|
e9a756e78b | ||
|
|
38af54a2dd | ||
|
|
77a92f517b | ||
|
|
3eb405e0e2 | ||
|
|
68b9479f0c | ||
|
|
d9df41c4d5 | ||
|
|
fc3c536ec2 | ||
|
|
77ddf4cb07 | ||
|
|
4d018306b3 | ||
|
|
b3bb93d1d9 | ||
|
|
980af27bbf |
No files matched your search
+41
-35
@@ -16,10 +16,25 @@ contributors who prefer to remain anonymous to the public.
|
||||
|
||||
The first time you send a pull request, you need to send an email to
|
||||
Justine Tunney <jtunney@gmail.com> stating that you intend to assign her
|
||||
the copyright to the changes you contribute to Cosmopolitan. This only
|
||||
applies to the code you *choose* to contribute. It only has to happen
|
||||
once. The email should be sent from an email address associated with
|
||||
your identity. Your email should link to your pull request.
|
||||
the copyright to the changes you contribute to Cosmopolitan. It only
|
||||
needs to happen once. This only applies to the code you *choose* to
|
||||
contribute. The email should be sent from an email address associated
|
||||
with your identity. Your email should link to your pull request.
|
||||
|
||||
To make things easy, here's an example of a good email you can use:
|
||||
|
||||
> **From**: YOUR NAME ([email protected])
|
||||
> **To**: Justine Tunney ([email protected])
|
||||
> **Subject**: Cosmopolitan Copyright Assignment for YOUR NAME
|
||||
>
|
||||
> Hi Justine,
|
||||
>
|
||||
> I made my first contribution to Cosmopolitan in
|
||||
> https://github.com/jart/cosmopolitan/pull/XXXX could you please take a
|
||||
> look? I intend to assign you the copyright to the changes I contribute
|
||||
> to Cosmopolitan.
|
||||
>
|
||||
> Thanks!
|
||||
|
||||
Please note that in order to give Justine the copyright, it has to be
|
||||
yours to give in the first place. If you're employed, then you should
|
||||
@@ -38,6 +53,27 @@ owners and the code should go in the `third_party/` folder. Every third
|
||||
party project should have a `README.cosmo` file that documents its
|
||||
provenance as well as any local changes you've made.
|
||||
|
||||
## Copyright Policy Exceptions
|
||||
|
||||
### Tests
|
||||
|
||||
You're encoraged to claim ownership of your test code. If you add a new
|
||||
file under the `test/` directory, then you should put your name in the
|
||||
ISC license header at the top of the file. If you add new test cases to
|
||||
an existing unit test file, then you're encouraged to append a line with
|
||||
your name to the existing copyright header of that file.
|
||||
|
||||
### Exceptional Features
|
||||
|
||||
Let's say you discovered a faster better way to implement `log10()` and
|
||||
you want to give it to Cosmopolitan. In cases like this, it really isn't
|
||||
appropriate for Justine to own your code. What you could do instead, is
|
||||
write your own new and improved `log10.c` from scratch, put your name on
|
||||
the top with the ISC license, and then add a `__notice()` directive so
|
||||
that your name will be embedded inside every executable that links the
|
||||
`log10()` function. This will help you get your name out there. Please
|
||||
note you need get approval from Justine each time you want to do this.
|
||||
|
||||
## Style Guide
|
||||
|
||||
You can use clang-format to automatically format your files:
|
||||
@@ -47,34 +83,4 @@ clang-format -i -style=file tool/net/redbean.c
|
||||
```
|
||||
|
||||
If you use Emacs this can be automated on save for Cosmopolitan using
|
||||
[tool/emacs/cosmo-format.el]([tool/emacs/cosmo-format.el]).
|
||||
|
||||
### Source Files
|
||||
|
||||
- Must use include paths relative to the root of the repository
|
||||
- Must have comment at top of file documenting copyright and license
|
||||
- Must have notice embedding if not owned by Justine (exception: tests)
|
||||
- May use language extensions that are supported by both GCC and Clang
|
||||
- Should use Google indentation (otherwise use `/* clang-format off */`)
|
||||
- Should use asm() instead of compiler APIs (exception: ctz, clz, memcpy)
|
||||
|
||||
### Header Files
|
||||
|
||||
- Must not have copyright or license comments
|
||||
- Must have once guards (otherwise change `.h` to `.inc`)
|
||||
- Must be ANSI C89 compatible to be included in the amalgamation header
|
||||
- Must include its dependencies (exception: libc/integral/normalize.inc)
|
||||
- Must not define objects (i.e. `cc -c -xc foo.h` will produce empty `.o`)
|
||||
- Should not use typedefs
|
||||
- Should not use forward declarations
|
||||
- Should not include documentation comments
|
||||
- Should not include parameter names in prototypes
|
||||
- Should not pose problems if included by C++ or Assembly sources
|
||||
- Should not declare non-ANSI code, at all, when the user requests ANSI
|
||||
|
||||
### Build Config
|
||||
|
||||
- Must not write files outside `o/`
|
||||
- Must not communicate with Internet
|
||||
- Must not depend on system libraries
|
||||
- Must not depend on system commands (exception: sh, make, gzip, zip)
|
||||
[tool/emacs/cosmo-format.el](tool/emacs/cosmo-format.el).
|
||||
@@ -149,9 +149,9 @@ export MODE
|
||||
export SOURCE_DATE_EPOCH
|
||||
export TMPDIR
|
||||
|
||||
COSMOCC = .cosmocc/3.3
|
||||
COSMOCC = .cosmocc/3.3.2
|
||||
TOOLCHAIN = $(COSMOCC)/bin/$(ARCH)-linux-cosmo-
|
||||
DOWNLOAD := $(shell build/download-cosmocc.sh $(COSMOCC) 3.3 d26ec8f4e48f6db004fc6a9677c7ff3b50c3b21e936e9393158aa2ed51b0b549)
|
||||
DOWNLOAD := $(shell build/download-cosmocc.sh $(COSMOCC) 3.3.2 a695012ffbeac5e26e3c4a740debc15273f47e9a8bdc55e8b76a623154d5914b)
|
||||
|
||||
AS = $(TOOLCHAIN)as
|
||||
CC = $(TOOLCHAIN)gcc
|
||||
@@ -206,7 +206,7 @@ endif
|
||||
.UNVEIL += \
|
||||
libc/integral \
|
||||
libc/stdbool.h \
|
||||
rwc:/dev/shm \
|
||||
rwc:/dev/shm \
|
||||
rx:.cosmocc \
|
||||
rx:build/bootstrap \
|
||||
r:build/portcosmo.h \
|
||||
@@ -297,6 +297,7 @@ include third_party/nsync/testing/BUILD.mk
|
||||
include libc/testlib/BUILD.mk
|
||||
include tool/viz/lib/BUILD.mk
|
||||
include tool/args/BUILD.mk
|
||||
include test/math/BUILD.mk
|
||||
include test/posix/BUILD.mk
|
||||
include test/libcxx/BUILD.mk
|
||||
include test/tool/args/BUILD.mk
|
||||
@@ -555,9 +556,9 @@ o/cosmopolitan.html: private .UNSANDBOXED = 1
|
||||
o/cosmopolitan.html: \
|
||||
o/$(MODE)/third_party/chibicc/chibicc.com.dbg \
|
||||
$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))) \
|
||||
$(filter-out %.cc,$(SRCS)) \
|
||||
$(filter-out %.cpp,$(filter-out %.cc,$(SRCS))) \
|
||||
$(HDRS)
|
||||
$(file >$(TMPDIR)/$(subst /,_,$@),$(filter-out %.cc,$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS)))))
|
||||
$(file >$(TMPDIR)/$(subst /,_,$@),$(filter-out %.cpp,$(filter-out %.cc,$(filter-out %.s,$(foreach x,$(COSMOPOLITAN_OBJECTS),$($(x)_SRCS))))))
|
||||
o/$(MODE)/third_party/chibicc/chibicc.com.dbg -J \
|
||||
-fno-common -include libc/integral/normalize.inc -o $@ \
|
||||
-DCOSMO @$(TMPDIR)/$(subst /,_,$@)
|
||||
|
||||
@@ -528,6 +528,7 @@ SECTIONS {
|
||||
*(.piro.data.sort.iat.*)
|
||||
#endif
|
||||
*(__patchable_function_entries)
|
||||
*(.note.gnu.property)
|
||||
*(__mcount_loc)
|
||||
*(.rela.dyn)
|
||||
*(.discard)
|
||||
|
||||
Binary file not shown.
@@ -95,7 +95,6 @@ DEFAULT_CCFLAGS += \
|
||||
DEFAULT_COPTS ?= \
|
||||
-fno-ident \
|
||||
-fno-common \
|
||||
-fno-math-errno \
|
||||
-fno-gnu-unique \
|
||||
-fstrict-aliasing \
|
||||
-fstrict-overflow \
|
||||
|
||||
+8
-8
@@ -6,14 +6,14 @@ if [ -n "$OBJDUMP" ]; then
|
||||
fi
|
||||
|
||||
find_objdump() {
|
||||
if [ -x .cosmocc/3.3/bin/$1-linux-cosmo-objdump ]; then
|
||||
OBJDUMP=.cosmocc/3.3/bin/$1-linux-cosmo-objdump
|
||||
elif [ -x .cosmocc/3.3/bin/$1-linux-musl-objdump ]; then
|
||||
OBJDUMP=.cosmocc/3.3/bin/$1-linux-musl-objdump
|
||||
elif [ -x "$COSMO/.cosmocc/3.3/bin/$1-linux-cosmo-objdump" ]; then
|
||||
OBJDUMP="$COSMO/.cosmocc/3.3/bin/$1-linux-cosmo-objdump"
|
||||
elif [ -x "$COSMO/.cosmocc/3.3/bin/$1-linux-musl-objdump" ]; then
|
||||
OBJDUMP="$COSMO/.cosmocc/3.3/bin/$1-linux-musl-objdump"
|
||||
if [ -x .cosmocc/3.3.2/bin/$1-linux-cosmo-objdump ]; then
|
||||
OBJDUMP=.cosmocc/3.3.2/bin/$1-linux-cosmo-objdump
|
||||
elif [ -x .cosmocc/3.3.2/bin/$1-linux-musl-objdump ]; then
|
||||
OBJDUMP=.cosmocc/3.3.2/bin/$1-linux-musl-objdump
|
||||
elif [ -x "$COSMO/.cosmocc/3.3.2/bin/$1-linux-cosmo-objdump" ]; then
|
||||
OBJDUMP="$COSMO/.cosmocc/3.3.2/bin/$1-linux-cosmo-objdump"
|
||||
elif [ -x "$COSMO/.cosmocc/3.3.2/bin/$1-linux-musl-objdump" ]; then
|
||||
OBJDUMP="$COSMO/.cosmocc/3.3.2/bin/$1-linux-musl-objdump"
|
||||
else
|
||||
echo "error: toolchain not found (try running 'cosmocc --update' or 'make' in the cosmo monorepo)" >&2
|
||||
exit 1
|
||||
|
||||
@@ -208,6 +208,7 @@ int execvpe(const char *, char *const[], char *const[]) libcesque;
|
||||
int euidaccess(const char *, int) libcesque;
|
||||
int eaccess(const char *, int) libcesque;
|
||||
int madvise(void *, uint64_t, int) libcesque;
|
||||
int getcpu(unsigned *, unsigned *) libcesque;
|
||||
#endif
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 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/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/timer.h"
|
||||
|
||||
/**
|
||||
* Sleeps with higher accuracy at the cost of cpu.
|
||||
*/
|
||||
int cosmo_clock_nanosleep(int clock, int flags, const struct timespec *req,
|
||||
struct timespec *rem) {
|
||||
|
||||
// pick clocks
|
||||
int time_clock;
|
||||
int sleep_clock;
|
||||
if (clock == CLOCK_REALTIME || //
|
||||
clock == CLOCK_REALTIME_PRECISE) {
|
||||
time_clock = clock;
|
||||
sleep_clock = CLOCK_REALTIME;
|
||||
} else if (clock == CLOCK_MONOTONIC || //
|
||||
clock == CLOCK_MONOTONIC_PRECISE) {
|
||||
time_clock = clock;
|
||||
sleep_clock = CLOCK_MONOTONIC;
|
||||
} else if (clock == CLOCK_REALTIME_COARSE || //
|
||||
clock == CLOCK_REALTIME_FAST) {
|
||||
return sys_clock_nanosleep(CLOCK_REALTIME, flags, req, rem);
|
||||
} else if (clock == CLOCK_MONOTONIC_COARSE || //
|
||||
clock == CLOCK_MONOTONIC_FAST) {
|
||||
return sys_clock_nanosleep(CLOCK_MONOTONIC, flags, req, rem);
|
||||
} else {
|
||||
return sys_clock_nanosleep(clock, flags, req, rem);
|
||||
}
|
||||
|
||||
// sleep bulk of time in kernel
|
||||
struct timespec start, deadline, remain, waitfor, now;
|
||||
struct timespec quantum = timespec_fromnanos(1000000000 / CLK_TCK);
|
||||
clock_gettime(time_clock, &start);
|
||||
deadline = flags & TIMER_ABSTIME ? *req : timespec_add(start, *req);
|
||||
if (timespec_cmp(start, deadline) >= 0) return 0;
|
||||
remain = timespec_sub(deadline, start);
|
||||
if (timespec_cmp(remain, quantum) > 0) {
|
||||
waitfor = timespec_sub(remain, quantum);
|
||||
if (sys_clock_nanosleep(sleep_clock, 0, &waitfor, rem) == -1) {
|
||||
if (!flags && rem && errno == EINTR) {
|
||||
*rem = timespec_add(*rem, quantum);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// spin through final scheduling quantum
|
||||
int rc = 0;
|
||||
ftrace_enabled(-1);
|
||||
do {
|
||||
if (_check_cancel()) {
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
clock_gettime(time_clock, &now);
|
||||
} while (timespec_cmp(now, deadline) < 0);
|
||||
ftrace_enabled(+1);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 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/calls/calls.h"
|
||||
#include "libc/calls/cp.internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timespec.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
int sys_clock_nanosleep(int clock, int flags, //
|
||||
const struct timespec *req, struct timespec *rem) {
|
||||
int rc;
|
||||
BEGIN_CANCELATION_POINT;
|
||||
if (IsLinux() || IsFreebsd() || IsNetbsd()) {
|
||||
rc = __sys_clock_nanosleep(clock, flags, req, rem);
|
||||
} else if (IsXnu()) {
|
||||
rc = sys_clock_nanosleep_xnu(clock, flags, req, rem);
|
||||
} else if (IsOpenbsd()) {
|
||||
rc = sys_clock_nanosleep_openbsd(clock, flags, req, rem);
|
||||
} else if (IsWindows()) {
|
||||
rc = sys_clock_nanosleep_nt(clock, flags, req, rem);
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
if (rc > 0) {
|
||||
errno = rc;
|
||||
rc = -1;
|
||||
}
|
||||
// system call support might not detect cancelation on bsds
|
||||
if (rc == -1 && errno == EINTR && //
|
||||
_weaken(pthread_testcancel_np) && //
|
||||
_weaken(pthread_testcancel_np)()) {
|
||||
rc = ecanceled();
|
||||
}
|
||||
END_CANCELATION_POINT;
|
||||
STRACE("sys_clock_nanosleep(%s, %s, %s, [%s]) → %d% m",
|
||||
DescribeClockName(clock), DescribeSleepFlags(flags),
|
||||
DescribeTimespec(0, req), DescribeTimespec(rc, rem), rc);
|
||||
return rc;
|
||||
}
|
||||
@@ -16,112 +16,10 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/cp.internal.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/struct/timespec.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/describeflags.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/runtime/clktck.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/timer.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
static int sys_clock_nanosleep(int clock, int flags, //
|
||||
const struct timespec *req,
|
||||
struct timespec *rem) {
|
||||
int rc;
|
||||
BEGIN_CANCELATION_POINT;
|
||||
if (IsLinux() || IsFreebsd() || IsNetbsd()) {
|
||||
rc = __sys_clock_nanosleep(clock, flags, req, rem);
|
||||
} else if (IsXnu()) {
|
||||
rc = sys_clock_nanosleep_xnu(clock, flags, req, rem);
|
||||
} else if (IsOpenbsd()) {
|
||||
rc = sys_clock_nanosleep_openbsd(clock, flags, req, rem);
|
||||
} else if (IsWindows()) {
|
||||
rc = sys_clock_nanosleep_nt(clock, flags, req, rem);
|
||||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
if (rc > 0) {
|
||||
errno = rc;
|
||||
rc = -1;
|
||||
}
|
||||
// system call support might not detect cancelation on bsds
|
||||
if (rc == -1 && errno == EINTR && //
|
||||
_weaken(pthread_testcancel_np) && //
|
||||
_weaken(pthread_testcancel_np)()) {
|
||||
rc = ecanceled();
|
||||
}
|
||||
END_CANCELATION_POINT;
|
||||
STRACE("sys_clock_nanosleep(%s, %s, %s, [%s]) → %d% m",
|
||||
DescribeClockName(clock), DescribeSleepFlags(flags),
|
||||
DescribeTimespec(0, req), DescribeTimespec(rc, rem), rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int cosmo_clock_nanosleep(int clock, int flags,
|
||||
const struct timespec *req,
|
||||
struct timespec *rem) {
|
||||
|
||||
// pick clocks
|
||||
int time_clock;
|
||||
int sleep_clock;
|
||||
if (clock == CLOCK_REALTIME || //
|
||||
clock == CLOCK_REALTIME_PRECISE) {
|
||||
time_clock = clock;
|
||||
sleep_clock = CLOCK_REALTIME;
|
||||
} else if (clock == CLOCK_MONOTONIC || //
|
||||
clock == CLOCK_MONOTONIC_PRECISE) {
|
||||
time_clock = clock;
|
||||
sleep_clock = CLOCK_MONOTONIC;
|
||||
} else if (clock == CLOCK_REALTIME_COARSE || //
|
||||
clock == CLOCK_REALTIME_FAST) {
|
||||
return sys_clock_nanosleep(CLOCK_REALTIME, flags, req, rem);
|
||||
} else if (clock == CLOCK_MONOTONIC_COARSE || //
|
||||
clock == CLOCK_MONOTONIC_FAST) {
|
||||
return sys_clock_nanosleep(CLOCK_MONOTONIC, flags, req, rem);
|
||||
} else {
|
||||
return sys_clock_nanosleep(clock, flags, req, rem);
|
||||
}
|
||||
|
||||
// sleep bulk of time in kernel
|
||||
struct timespec start, deadline, remain, waitfor, now;
|
||||
struct timespec quantum = timespec_fromnanos(1000000000 / CLK_TCK);
|
||||
unassert(!clock_gettime(time_clock, &start));
|
||||
deadline = flags & TIMER_ABSTIME ? *req : timespec_add(start, *req);
|
||||
if (timespec_cmp(start, deadline) >= 0) return 0;
|
||||
remain = timespec_sub(deadline, start);
|
||||
if (timespec_cmp(remain, quantum) > 0) {
|
||||
waitfor = timespec_sub(remain, quantum);
|
||||
if (sys_clock_nanosleep(sleep_clock, 0, &waitfor, rem) == -1) {
|
||||
if (!flags && rem && errno == EINTR) {
|
||||
*rem = timespec_add(*rem, quantum);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// spin through final scheduling quantum
|
||||
int rc = 0;
|
||||
ftrace_enabled(-1);
|
||||
do {
|
||||
if (_check_cancel()) {
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
unassert(!clock_gettime(time_clock, &now));
|
||||
} while (timespec_cmp(now, deadline) < 0);
|
||||
ftrace_enabled(+1);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleeps for particular amount of time.
|
||||
@@ -157,10 +55,8 @@ static int cosmo_clock_nanosleep(int clock, int flags,
|
||||
* on OpenBSD it's good; on XNU it's bad; and on Windows it's ugly.
|
||||
*
|
||||
* @param clock may be
|
||||
* - `CLOCK_REALTIME` to have nanosecond-accurate wall time sleeps
|
||||
* - `CLOCK_REALTIME_COARSE` to not spin through scheduler quantum
|
||||
* - `CLOCK_MONOTONIC` to base the sleep off the monotinic clock
|
||||
* - `CLOCK_MONOTONIC_COARSE` to once again not do userspace spin
|
||||
* - `CLOCK_REALTIME`
|
||||
* - `CLOCK_MONOTONIC`
|
||||
* @param flags can be 0 for relative and `TIMER_ABSTIME` for absolute
|
||||
* @param req can be a relative or absolute time, depending on `flags`
|
||||
* @param rem shall be updated with the remainder of unslept time when
|
||||
@@ -193,7 +89,7 @@ errno_t clock_nanosleep(int clock, int flags, //
|
||||
return EINVAL;
|
||||
}
|
||||
errno_t old = errno;
|
||||
int rc = cosmo_clock_nanosleep(clock, flags, req, rem);
|
||||
int rc = sys_clock_nanosleep(clock, flags, req, rem);
|
||||
errno_t err = !rc ? 0 : errno;
|
||||
errno = old;
|
||||
return err;
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2024 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/calls/calls.h"
|
||||
#include "libc/calls/struct/cpuset.h"
|
||||
#include "libc/calls/syscall_support-nt.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/nexgen32e/rdtscp.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/nt/struct/processornumber.h"
|
||||
#include "libc/nt/synchronization.h"
|
||||
#include "libc/runtime/syslib.internal.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int sys_getcpu(unsigned *opt_cpu, unsigned *opt_node, void *tcache);
|
||||
|
||||
int getcpu(unsigned *out_opt_cpu, unsigned *out_opt_node) {
|
||||
unsigned cpu;
|
||||
unsigned node;
|
||||
if (X86_HAVE(RDTSCP)) {
|
||||
unsigned tsc_aux;
|
||||
rdtscp(&tsc_aux);
|
||||
cpu = TSC_AUX_CORE(tsc_aux);
|
||||
node = TSC_AUX_NODE(tsc_aux);
|
||||
} else if (IsWindows()) {
|
||||
struct NtProcessorNumber pn;
|
||||
GetCurrentProcessorNumberEx(&pn);
|
||||
cpu = 64 * pn.Group + pn.Number;
|
||||
unsigned short node16;
|
||||
if (GetNumaProcessorNodeEx(&pn, &node16)) {
|
||||
node = node16;
|
||||
} else {
|
||||
return __winerr();
|
||||
}
|
||||
} else if (IsXnuSilicon()) {
|
||||
if (__syslib->__version >= 9) {
|
||||
size_t cpu64;
|
||||
errno_t err = __syslib->__pthread_cpu_number_np(&cpu64);
|
||||
if (!err) {
|
||||
cpu = cpu64;
|
||||
node = 0;
|
||||
} else {
|
||||
errno = err;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return enosys();
|
||||
}
|
||||
} else {
|
||||
int rc = sys_getcpu(&cpu, &node, 0);
|
||||
if (rc == -1) return -1;
|
||||
}
|
||||
if (out_opt_cpu) {
|
||||
*out_opt_cpu = cpu;
|
||||
}
|
||||
if (out_opt_node) {
|
||||
*out_opt_node = node;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -19,8 +19,8 @@ int timespec_getres(struct timespec *, int) libcesque;
|
||||
int timespec_get(struct timespec *, int) libcesque;
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
/* cosmopolitan libc's non-posix timespec library
|
||||
removed by default due to emacs codebase clash */
|
||||
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
|
||||
int cosmo_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
|
||||
#define timespec_zero ((struct timespec){0})
|
||||
#define timespec_max ((struct timespec){0x7fffffffffffffff, 999999999})
|
||||
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_DCE_H_
|
||||
#define COSMOPOLITAN_LIBC_DCE_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
/*─────────────────────────────────────────────────────────────────────────────╗
|
||||
│ cosmopolitan § autotune » dead code elimination │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
@@ -125,5 +125,5 @@ int IsQemuUser(void);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
@@ -16,13 +16,11 @@ void *dlopen(const char *, int) libcesque;
|
||||
void *dlsym(void *, const char *) libcesque;
|
||||
int dlclose(void *) libcesque;
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
char *cosmo_dlerror(void) libcesque;
|
||||
void *cosmo_dlopen(const char *, int) libcesque;
|
||||
void *cosmo_dlsym(void *, const char *) libcesque;
|
||||
void *cosmo_dltramp(void *) libcesque;
|
||||
int cosmo_dlclose(void *) libcesque;
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_DLFCN_H_ */
|
||||
+6
-7
@@ -22,16 +22,15 @@ COSMOPOLITAN_C_START_
|
||||
* @see libc/sysv/dos2errno.sh for multimapped numbers
|
||||
*/
|
||||
|
||||
#if defined(__GNUC__) && defined(__aarch64__) && !defined(__STRICT_ANSI__) && \
|
||||
!defined(__cplusplus)
|
||||
#if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
|
||||
/* this header is included by 700+ files; therefore we */
|
||||
/* hand-roll &__get_tls()->tib_errno to avoid #include */
|
||||
/* cosmopolitan uses x28 as the tls register b/c apple */
|
||||
#define errno \
|
||||
(*({ \
|
||||
errno_t *__ep; \
|
||||
asm("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
|
||||
__ep; \
|
||||
#define errno \
|
||||
(*__extension__({ \
|
||||
errno_t *__ep; \
|
||||
__asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
|
||||
__ep; \
|
||||
}))
|
||||
#else
|
||||
#define errno (*__errno_location())
|
||||
|
||||
+12
-28
@@ -16,44 +16,28 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Decodes decimal integer from ASCII string.
|
||||
* Turns string into int.
|
||||
*
|
||||
* atoi 10⁸ 22𝑐 7𝑛𝑠
|
||||
* strtol 10⁸ 37𝑐 12𝑛𝑠
|
||||
* strtoul 10⁸ 35𝑐 11𝑛𝑠
|
||||
* wcstol 10⁸ 30𝑐 10𝑛𝑠
|
||||
* wcstoul 10⁸ 30𝑐 10𝑛𝑠
|
||||
* strtoimax 10⁸ 80𝑐 26𝑛𝑠
|
||||
* strtoumax 10⁸ 78𝑐 25𝑛𝑠
|
||||
* wcstoimax 10⁸ 77𝑐 25𝑛𝑠
|
||||
* wcstoumax 10⁸ 76𝑐 25𝑛𝑠
|
||||
* Decimal is the only radix supported. Leading whitespace (as specified
|
||||
* by the isspace() function) is skipped over. Unlike strtol(), the atoi
|
||||
* function has undefined behavior on error and it never changes `errno`
|
||||
*
|
||||
* @param s is a non-null nul-terminated string
|
||||
* @param nptr is a non-null nul-terminated string
|
||||
* @return the decoded signed saturated integer
|
||||
* @raise ERANGE on overflow
|
||||
*/
|
||||
int atoi(const char *s) {
|
||||
int atoi(const char *nptr) {
|
||||
int x, c, d;
|
||||
do c = *s++;
|
||||
while (c == ' ' || c == '\t');
|
||||
do c = *nptr++;
|
||||
while (isspace(c));
|
||||
d = c == '-' ? -1 : 1;
|
||||
if (c == '-' || c == '+') c = *s++;
|
||||
for (x = 0; isdigit(c); c = *s++) {
|
||||
if (ckd_mul(&x, x, 10) || ckd_add(&x, x, (c - '0') * d)) {
|
||||
errno = ERANGE;
|
||||
if (d > 0) {
|
||||
return INT_MAX;
|
||||
} else {
|
||||
return INT_MIN;
|
||||
}
|
||||
}
|
||||
if (c == '-' || c == '+') c = *nptr++;
|
||||
for (x = 0; isdigit(c); c = *nptr++) {
|
||||
x *= 10;
|
||||
x += (c - '0') * d;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
+13
-18
@@ -16,34 +16,29 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/stdckdint.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Decodes decimal integer from ASCII string.
|
||||
* Turns string into long.
|
||||
*
|
||||
* @param s is a non-null nul-terminated string
|
||||
* Decimal is the only radix supported. Leading whitespace (as specified
|
||||
* by the isspace() function) is skipped over. Unlike strtol(), the atoi
|
||||
* function has undefined behavior on error and it never changes `errno`
|
||||
*
|
||||
* @param nptr is a non-null nul-terminated string
|
||||
* @return the decoded signed saturated integer
|
||||
*/
|
||||
long atol(const char *s) {
|
||||
long atol(const char *nptr) {
|
||||
long x;
|
||||
int c, d;
|
||||
do c = *s++;
|
||||
while (c == ' ' || c == '\t');
|
||||
do c = *nptr++;
|
||||
while (isspace(c));
|
||||
d = c == '-' ? -1 : 1;
|
||||
if (c == '-' || c == '+') c = *s++;
|
||||
for (x = 0; isdigit(c); c = *s++) {
|
||||
if (ckd_mul(&x, x, 10) || ckd_add(&x, x, (c - '0') * d)) {
|
||||
errno = ERANGE;
|
||||
if (d > 0) {
|
||||
return LONG_MAX;
|
||||
} else {
|
||||
return LONG_MIN;
|
||||
}
|
||||
}
|
||||
if (c == '-' || c == '+') c = *nptr++;
|
||||
for (x = 0; isdigit(c); c = *nptr++) {
|
||||
x *= 10;
|
||||
x += (c - '0') * d;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define COSMOPOLITAN_LIBC_FMT_DIVMOD10_H_
|
||||
|
||||
forceinline uint64_t __divmod10(uint64_t __x, unsigned *__r) {
|
||||
#if defined(__STRICT_ANSI__) || !defined(__GNUC__) || \
|
||||
(defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__))
|
||||
#if !defined(__GNUC__) || (defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__))
|
||||
*__r = __x % 10;
|
||||
return __x / 10;
|
||||
#else
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
|
||||
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define LengthInt64 __LengthInt64
|
||||
@@ -42,5 +42,5 @@ libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
|
||||
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
|
||||
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define sleb64 __sleb64
|
||||
@@ -16,5 +16,5 @@ int unzleb64(const char *, size_t, int64_t *) libcesque;
|
||||
int unuleb64(const char *, size_t, uint64_t *) libcesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
+66
-146
@@ -16,8 +16,7 @@
|
||||
|
||||
#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
|
||||
#define typeof(x) decltype(x)
|
||||
#elif (defined(__STRICT_ANSI__) || !defined(__GNUC__)) && \
|
||||
__STDC_VERSION__ + 0 < 201112
|
||||
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
|
||||
#define typeof(x) __typeof(x)
|
||||
#endif
|
||||
|
||||
@@ -27,7 +26,7 @@
|
||||
#endif /* C++11 */
|
||||
#else /* __cplusplus */
|
||||
#if __STDC_VERSION__ + 0 < 201112
|
||||
#if __GNUC__ + _MSC_VER + 0 && !defined(__STRICT_ANSI__)
|
||||
#if __GNUC__ + _MSC_VER + 0
|
||||
#define _Alignof(x) __alignof(x)
|
||||
#else
|
||||
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
|
||||
@@ -36,7 +35,7 @@
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
|
||||
#if !defined(__STRICT_ANSI__) && (defined(__GNUC__) || defined(_MSC_VER))
|
||||
#if defined(__GNUC__) || defined(_MSC_VER)
|
||||
#define inline __inline
|
||||
#else
|
||||
#define inline
|
||||
@@ -49,7 +48,7 @@
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ + 0 < 201112
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#ifdef __GNUC__
|
||||
#define _Alignas(x) __attribute__((__aligned__(x)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define _Alignas(x) __declspec(align(x))
|
||||
@@ -58,17 +57,15 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define __builtin_unreachable() __assume(false)
|
||||
#elif defined(__STRICT_ANSI__) || \
|
||||
!((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
|
||||
defined(__clang__) || defined(__INTEL_COMPILER) || \
|
||||
__has_builtin(__builtin_unreachable))
|
||||
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
|
||||
defined(__clang__) || defined(__INTEL_COMPILER) || \
|
||||
__has_builtin(__builtin_unreachable))
|
||||
#define __builtin_unreachable() \
|
||||
for (;;) { \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__STRICT_ANSI__) || \
|
||||
(!defined(__llvm__) && !__has_builtin(__builtin_assume))
|
||||
#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
|
||||
#define __builtin_assume(x) \
|
||||
do { \
|
||||
if (!(x)) __builtin_unreachable(); \
|
||||
@@ -134,9 +131,7 @@ typedef __UINTMAX_TYPE__ uintmax_t;
|
||||
typedef long double max_align_t;
|
||||
|
||||
#ifdef _COSMO_SOURCE
|
||||
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || \
|
||||
defined(__llvm__)) && \
|
||||
!defined(__STRICT_ANSI__)
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
|
||||
typedef signed __int128 int128_t;
|
||||
typedef unsigned __int128 uint128_t;
|
||||
#endif
|
||||
@@ -169,11 +164,7 @@ typedef struct {
|
||||
#define interruptfn nocallersavedregisters forcealignargpointer
|
||||
|
||||
#ifndef pureconst
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define pureconst __attribute__((__const__))
|
||||
#else
|
||||
#define pureconst
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef forcealign
|
||||
@@ -181,15 +172,9 @@ typedef struct {
|
||||
#endif
|
||||
#define thatispacked __attribute__((__packed__))
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define printfesque(n) __attribute__((__format__(__gnu_printf__, n, n + 1)))
|
||||
#define scanfesque(n) __attribute__((__format__(__gnu_scanf__, n, n + 1)))
|
||||
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))
|
||||
#else
|
||||
#define printfesque(n)
|
||||
#define scanfesque(n)
|
||||
#define strftimeesque(n)
|
||||
#endif
|
||||
|
||||
#ifndef privileged
|
||||
#define privileged \
|
||||
@@ -197,8 +182,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef wontreturn
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__noreturn__) || \
|
||||
#if (__has_attribute(__noreturn__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
|
||||
#define wontreturn __attribute__((__noreturn__))
|
||||
#else
|
||||
@@ -207,8 +191,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef nosideeffect
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__pure__) || \
|
||||
#if (__has_attribute(__pure__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
|
||||
#define nosideeffect __attribute__((__pure__))
|
||||
#else
|
||||
@@ -219,9 +202,8 @@ typedef struct {
|
||||
#ifndef dontinline
|
||||
#ifdef _MSC_VER
|
||||
#define dontinline __declspec(noinline)
|
||||
#elif !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__noinline__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
|
||||
#elif (__has_attribute(__noinline__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
|
||||
#define dontinline __attribute__((__noinline__))
|
||||
#else
|
||||
#define dontinline
|
||||
@@ -229,8 +211,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef dontclone
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__noclone__) || \
|
||||
#if (__has_attribute(__noclone__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
|
||||
#define dontclone __attribute__((__noclone__))
|
||||
#else
|
||||
@@ -242,8 +223,7 @@ typedef struct {
|
||||
#ifdef __cplusplus
|
||||
#define forceinline inline
|
||||
#else
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
|
||||
!defined(__cplusplus) || \
|
||||
(defined(__clang__) && \
|
||||
@@ -267,8 +247,7 @@ typedef struct {
|
||||
#endif /* forceinline */
|
||||
|
||||
#ifndef __wur
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
|
||||
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
|
||||
__has_attribute(__warn_unused_result__))
|
||||
#define __wur __attribute__((__warn_unused_result__))
|
||||
#else
|
||||
@@ -277,8 +256,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef nullterminated
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__sentinel__) || __GNUC__ + 0 >= 4)
|
||||
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
|
||||
#define nullterminated(x) __attribute__((__sentinel__ x))
|
||||
#else
|
||||
#define nullterminated(x)
|
||||
@@ -295,8 +273,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef externinline
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(!defined(__cplusplus) || \
|
||||
#if (!defined(__cplusplus) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
|
||||
(defined(__clang__) && \
|
||||
(defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
|
||||
@@ -311,8 +288,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef relegated
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__cold__) || \
|
||||
#if (__has_attribute(__cold__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
|
||||
#define relegated __attribute__((__cold__))
|
||||
#else
|
||||
@@ -320,8 +296,7 @@ typedef struct {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__warning__) || \
|
||||
#if (__has_attribute(__warning__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
|
||||
#define warnifused(s) __attribute__((__warning__(s)))
|
||||
#else
|
||||
@@ -329,8 +304,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef firstclass
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__hot__) || \
|
||||
#if (__has_attribute(__hot__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
|
||||
#define firstclass __attribute__((__hot__))
|
||||
#else
|
||||
@@ -339,8 +313,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef paramsnonnull
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__nonnull__) || \
|
||||
#if (__has_attribute(__nonnull__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
|
||||
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
|
||||
#else
|
||||
@@ -355,7 +328,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__cplusplus) && \
|
||||
#if !defined(__cplusplus) && \
|
||||
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
|
||||
#define restrict __restrict__
|
||||
#else
|
||||
@@ -365,8 +338,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef dontcallback
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__leaf__) || \
|
||||
#if (__has_attribute(__leaf__) || \
|
||||
(!defined(__llvm__) && \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
|
||||
#define dontcallback __attribute__((__leaf__))
|
||||
@@ -376,8 +348,8 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef dontthrow
|
||||
#if defined(__cplusplus) && !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(dontthrow) || \
|
||||
#if defined(__cplusplus) && \
|
||||
(__has_attribute(dontthrow) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
|
||||
#define dontthrow __attribute__((__nothrow__))
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -388,8 +360,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef returnstwice
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__returns_twice__) || \
|
||||
#if (__has_attribute(__returns_twice__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
|
||||
#define returnstwice __attribute__((__returns_twice__))
|
||||
#else
|
||||
@@ -398,8 +369,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef nodebuginfo
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__nodebug__) || defined(__llvm__))
|
||||
#if __has_attribute(__nodebug__) || defined(__llvm__)
|
||||
#define nodebuginfo __attribute__((__nodebug__))
|
||||
#else
|
||||
#define nodebuginfo
|
||||
@@ -414,8 +384,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef returnsnonnull
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__returns_nonnull__) || \
|
||||
#if (__has_attribute(__returns_nonnull__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
|
||||
#define returnsnonnull __attribute__((__returns_nonnull__))
|
||||
#else
|
||||
@@ -423,8 +392,7 @@ typedef struct {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__assume_aligned__) || \
|
||||
#if (__has_attribute(__assume_aligned__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
|
||||
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
|
||||
#else
|
||||
@@ -432,8 +400,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef returnspointerwithnoaliases
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__malloc__) || \
|
||||
#if (__has_attribute(__malloc__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
|
||||
#define returnspointerwithnoaliases __attribute__((__malloc__))
|
||||
#elif defined(_MSC_VER)
|
||||
@@ -444,8 +411,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef attributeallocsize
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__alloc_size__) || \
|
||||
#if (__has_attribute(__alloc_size__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
|
||||
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
|
||||
#else
|
||||
@@ -454,8 +420,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef attributeallocalign
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__alloc_align__) || \
|
||||
#if (__has_attribute(__alloc_align__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
|
||||
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
|
||||
#else
|
||||
@@ -478,8 +443,7 @@ typedef struct {
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
#ifndef dontinstrument
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__no_instrument_function__) || \
|
||||
#if (__has_attribute(__no_instrument_function__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
|
||||
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
|
||||
__has_attribute(__patchable_function_entry__)
|
||||
@@ -495,8 +459,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef mayalias
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__may_alias__) || \
|
||||
#if (__has_attribute(__may_alias__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
|
||||
#define mayalias __attribute__((__may_alias__))
|
||||
#else
|
||||
@@ -505,35 +468,26 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef dontoptimize
|
||||
#ifndef __STRICT_ANSI__
|
||||
#if defined(__llvm__) || __has_attribute(__optnone__)
|
||||
#define dontoptimize __attribute__((__optnone__))
|
||||
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
|
||||
__has_attribute(__optimize__)
|
||||
#define dontoptimize __attribute__((__optimize__(0)))
|
||||
#endif
|
||||
#else
|
||||
#define dontoptimize
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef optimizesize
|
||||
#ifndef __STRICT_ANSI__
|
||||
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
|
||||
__has_attribute(__optimize__)
|
||||
#define optimizesize __attribute__((__optimize__("s")))
|
||||
#elif defined(__llvm__) || __has_attribute(__optnone__)
|
||||
#define optimizesize __attribute__((__optnone__))
|
||||
#endif
|
||||
#else
|
||||
#define optimizesize
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef optimizespeed
|
||||
/* warning: corrupts frame pointer; only use on leaf functions */
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
|
||||
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
|
||||
__has_attribute(__optimize__))
|
||||
#define optimizespeed __attribute__((__optimize__(3)))
|
||||
#else
|
||||
@@ -542,8 +496,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef unrollloops
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
|
||||
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
|
||||
__has_attribute(__optimize__))
|
||||
#define unrollloops __attribute__((__optimize__("unroll-loops")))
|
||||
#else
|
||||
@@ -552,8 +505,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#ifndef _Microarchitecture
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__has_attribute(__target__) || \
|
||||
#if (__has_attribute(__target__) || \
|
||||
(__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
|
||||
#define _Microarchitecture(march) __attribute__((__target__(march)))
|
||||
#else
|
||||
@@ -572,64 +524,48 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
|
||||
__has_attribute(__no_sanitize_address__)) && \
|
||||
!defined(__STRICT_ANSI__)
|
||||
__has_attribute(__no_sanitize_address__))
|
||||
#define dontasan __attribute__((__no_sanitize_address__))
|
||||
#else
|
||||
#define dontasan
|
||||
#endif
|
||||
|
||||
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
|
||||
__has_attribute(__no_sanitize_undefined__)) && \
|
||||
!defined(__STRICT_ANSI__)
|
||||
__has_attribute(__no_sanitize_undefined__))
|
||||
#define dontubsan __attribute__((__no_sanitize_undefined__))
|
||||
#else
|
||||
#define dontubsan
|
||||
#endif
|
||||
|
||||
#ifdef __STRICT_ANSI__
|
||||
void abort(void) wontreturn;
|
||||
#define notpossible abort()
|
||||
#else
|
||||
#ifdef __x86_64__
|
||||
#define notpossible \
|
||||
do { \
|
||||
asm("nop\n\t" \
|
||||
"ud2\n\t" \
|
||||
"nop"); \
|
||||
__asm__("nop\n\t" \
|
||||
"ud2\n\t" \
|
||||
"nop"); \
|
||||
__builtin_unreachable(); \
|
||||
} while (0)
|
||||
#elif defined(__aarch64__)
|
||||
#define notpossible \
|
||||
do { \
|
||||
asm("udf\t#0\n\t" \
|
||||
"nop"); \
|
||||
__asm__("udf\t#0\n\t" \
|
||||
"nop"); \
|
||||
__builtin_unreachable(); \
|
||||
} while (0)
|
||||
#else
|
||||
#define notpossible __builtin_trap()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define donothing \
|
||||
do { \
|
||||
} while (0)
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define textstartup _Section(".text.startup")
|
||||
#define textexit _Section(".text.exit")
|
||||
#define textreal _Section(".text.real")
|
||||
#define texthead _Section(".text.head")
|
||||
#define textwindows _Section(".text.windows")
|
||||
#define antiquity _Section(".text.antiquity")
|
||||
#else
|
||||
#define textstartup
|
||||
#define textexit
|
||||
#define textreal
|
||||
#define texthead
|
||||
#define textwindows
|
||||
#define antiquity
|
||||
#endif
|
||||
|
||||
#ifdef __llvm__
|
||||
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
|
||||
@@ -660,66 +596,50 @@ void abort(void) wontreturn;
|
||||
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
|
||||
#endif
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#ifdef __x86_64__
|
||||
#define DebugBreak() asm("int3")
|
||||
#define DebugBreak() __asm__("int3")
|
||||
#else
|
||||
#define DebugBreak() __builtin_trap()
|
||||
#endif
|
||||
#else
|
||||
#define DebugBreak() (void)0
|
||||
#endif
|
||||
|
||||
#endif /* _COSMO_SOURCE */
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define __veil(CONSTRAINT, EXPRESSION) \
|
||||
({ \
|
||||
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
|
||||
asm("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
|
||||
VeiledValue; \
|
||||
#define __veil(CONSTRAINT, EXPRESSION) \
|
||||
__extension__({ \
|
||||
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
|
||||
__asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
|
||||
VeiledValue; \
|
||||
})
|
||||
#else
|
||||
#define __veil(CONSTRAINT, EXPRESSION) (EXPRESSION)
|
||||
#endif
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define __conceal(CONSTRAINT, EXPRESSION) \
|
||||
({ \
|
||||
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
|
||||
asm volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
|
||||
VeiledValue; \
|
||||
#define __conceal(CONSTRAINT, EXPRESSION) \
|
||||
__extension__({ \
|
||||
autotype(EXPRESSION) VeiledValue = (EXPRESSION); \
|
||||
__asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
|
||||
VeiledValue; \
|
||||
})
|
||||
#else
|
||||
#define __conceal(CONSTRAINT, EXPRESSION) (EXPRESSION)
|
||||
#endif
|
||||
|
||||
#ifndef __STRICT_ANSI__
|
||||
#define __expropriate(EXPRESSION) \
|
||||
({ \
|
||||
asm volatile("" ::"g"(EXPRESSION) : "memory"); \
|
||||
0; \
|
||||
#define __expropriate(EXPRESSION) \
|
||||
__extension__({ \
|
||||
__asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
|
||||
0; \
|
||||
})
|
||||
#else
|
||||
#define __expropriate(EXPRESSION) (EXPRESSION)
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
|
||||
#if !defined(__APPLE__) && defined(__x86_64__)
|
||||
#define __yoink(SYMBOL) \
|
||||
asm(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
|
||||
__asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
|
||||
#elif defined(__aarch64__)
|
||||
#define __yoink(SYMBOL) \
|
||||
asm(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
|
||||
__asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
|
||||
#else
|
||||
#define __yoink(SYMBOL) (void)0
|
||||
#endif
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && !defined(__APPLE__) && defined(__x86_64__)
|
||||
#if !defined(__APPLE__) && defined(__x86_64__)
|
||||
#define __static_yoink(SYMBOLSTR) \
|
||||
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||
__asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||
#elif defined(__aarch64__)
|
||||
#define __static_yoink(SYMBOLSTR) \
|
||||
asm(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||
__asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||
#else
|
||||
#define __static_yoink(SYMBOLSTR)
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#define __COSMOPOLITAN_MAJOR__ 3
|
||||
#define __COSMOPOLITAN_MINOR__ 3
|
||||
#define __COSMOPOLITAN_PATCH__ 0
|
||||
#define __COSMOPOLITAN_PATCH__ 2
|
||||
#define __COSMOPOLITAN__ \
|
||||
(100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
|
||||
__COSMOPOLITAN_PATCH__)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
@@ -80,11 +80,12 @@ ENTRY (__memcpy_aarch64_simd)
|
||||
PTR_ARG (1)
|
||||
SIZE_ARG (2)
|
||||
add srcend, src, count
|
||||
add dstend, dstin, count
|
||||
cmp count, 128
|
||||
b.hi L(copy_long)
|
||||
add dstend, dstin, count
|
||||
cmp count, 32
|
||||
b.hi L(copy32_128)
|
||||
nop
|
||||
|
||||
/* Small copies: 0..32 bytes. */
|
||||
cmp count, 16
|
||||
@@ -95,6 +96,18 @@ ENTRY (__memcpy_aarch64_simd)
|
||||
str B_q, [dstend, -16]
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
/* Medium copies: 33..128 bytes. */
|
||||
L(copy32_128):
|
||||
ldp A_q, B_q, [src]
|
||||
ldp C_q, D_q, [srcend, -32]
|
||||
cmp count, 64
|
||||
b.hi L(copy128)
|
||||
stp A_q, B_q, [dstin]
|
||||
stp C_q, D_q, [dstend, -32]
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
/* Copy 8-15 bytes. */
|
||||
L(copy16):
|
||||
tbz count, 3, L(copy8)
|
||||
@@ -104,7 +117,6 @@ L(copy16):
|
||||
str A_h, [dstend, -8]
|
||||
ret
|
||||
|
||||
.p2align 3
|
||||
/* Copy 4-7 bytes. */
|
||||
L(copy8):
|
||||
tbz count, 2, L(copy4)
|
||||
@@ -114,6 +126,19 @@ L(copy8):
|
||||
str B_lw, [dstend, -4]
|
||||
ret
|
||||
|
||||
/* Copy 65..128 bytes. */
|
||||
L(copy128):
|
||||
ldp E_q, F_q, [src, 32]
|
||||
cmp count, 96
|
||||
b.ls L(copy96)
|
||||
ldp G_q, H_q, [srcend, -64]
|
||||
stp G_q, H_q, [dstend, -64]
|
||||
L(copy96):
|
||||
stp A_q, B_q, [dstin]
|
||||
stp E_q, F_q, [dstin, 32]
|
||||
stp C_q, D_q, [dstend, -32]
|
||||
ret
|
||||
|
||||
/* Copy 0..3 bytes using a branchless sequence. */
|
||||
L(copy4):
|
||||
cbz count, L(copy0)
|
||||
@@ -127,33 +152,11 @@ L(copy4):
|
||||
L(copy0):
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
/* Medium copies: 33..128 bytes. */
|
||||
L(copy32_128):
|
||||
ldp A_q, B_q, [src]
|
||||
ldp C_q, D_q, [srcend, -32]
|
||||
cmp count, 64
|
||||
b.hi L(copy128)
|
||||
stp A_q, B_q, [dstin]
|
||||
stp C_q, D_q, [dstend, -32]
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
/* Copy 65..128 bytes. */
|
||||
L(copy128):
|
||||
ldp E_q, F_q, [src, 32]
|
||||
cmp count, 96
|
||||
b.ls L(copy96)
|
||||
ldp G_q, H_q, [srcend, -64]
|
||||
stp G_q, H_q, [dstend, -64]
|
||||
L(copy96):
|
||||
stp A_q, B_q, [dstin]
|
||||
stp E_q, F_q, [dstin, 32]
|
||||
stp C_q, D_q, [dstend, -32]
|
||||
ret
|
||||
|
||||
.p2align 3
|
||||
/* Copy more than 128 bytes. */
|
||||
L(copy_long):
|
||||
add dstend, dstin, count
|
||||
|
||||
/* Use backwards copy if there is an overlap. */
|
||||
sub tmp1, dstin, src
|
||||
cmp tmp1, count
|
||||
@@ -190,6 +193,9 @@ L(copy64_from_end):
|
||||
stp A_q, B_q, [dstend, -32]
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
nop
|
||||
|
||||
/* Large backwards copy for overlapping copies.
|
||||
Copy 16 bytes and then align srcend to 16-byte alignment. */
|
||||
L(copy_long_backwards):
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ Copyright (c) 2018-2024, Arm Limited. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/describebacktrace.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
|
||||
@@ -28,6 +30,9 @@ dontinstrument const char *(DescribeBacktrace)(char buf[N],
|
||||
char *pe = p + N;
|
||||
bool gotsome = false;
|
||||
while (fr) {
|
||||
if (_weaken(kisdangerous) && _weaken(kisdangerous)(fr)) {
|
||||
break;
|
||||
}
|
||||
if (p + 16 + 1 + 1 <= pe) {
|
||||
if (gotsome) {
|
||||
*p++ = ' ';
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
#define dll_make_first __dll_make_first
|
||||
#define dll_make_last __dll_make_last
|
||||
#define dll_remove __dll_remove
|
||||
@@ -55,5 +55,5 @@ void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
|
||||
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
@@ -0,0 +1,2 @@
|
||||
__notice(freebsd_complex_notice, "FreeBSD Complex Math (BSD-2 License)\n\
|
||||
Copyright (c) 2012 Stephen Montgomery-Smith <[email protected]>");
|
||||
@@ -1,7 +1,7 @@
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2024 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 │
|
||||
@@ -16,25 +16,27 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "net/http/http.h"
|
||||
|
||||
const char kHttpMethod[18][8] = {
|
||||
"WUT", //
|
||||
"GET", //
|
||||
"HEAD", //
|
||||
"POST", //
|
||||
"PUT", //
|
||||
"DELETE", //
|
||||
"OPTIONS", //
|
||||
"CONNECT", //
|
||||
"TRACE", //
|
||||
"COPY", //
|
||||
"LOCK", //
|
||||
"MERGE", //
|
||||
"MKCOL", //
|
||||
"MOVE", //
|
||||
"NOTIFY", //
|
||||
"PATCH", //
|
||||
"REPORT", //
|
||||
"UNLOCK", //
|
||||
/**
|
||||
* @fileoverview fp16 compiler runtime
|
||||
*/
|
||||
|
||||
#define asint(x) ((union pun){x}).i
|
||||
#define isnan(x) (((x) & 0x7fff) > 0x7c00)
|
||||
|
||||
union pun {
|
||||
_Float16 f;
|
||||
unsigned short i;
|
||||
};
|
||||
|
||||
int __eqhf2(_Float16 fx, _Float16 fy) {
|
||||
int x = asint(fx);
|
||||
int y = asint(fy);
|
||||
return (x == y) & !isnan(x) & !isnan(y);
|
||||
}
|
||||
|
||||
int __nehf2(_Float16 fx, _Float16 fy) {
|
||||
int x = asint(fx);
|
||||
int y = asint(fy);
|
||||
return (x != y) & !isnan(x) & !isnan(y);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
|
||||
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
#define klog __klog
|
||||
#define kprintf __kprintf
|
||||
@@ -54,5 +54,5 @@ void uvprintf(const char *, va_list) libcesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
@@ -10,8 +10,7 @@
|
||||
#endif
|
||||
|
||||
#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && \
|
||||
!defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && \
|
||||
!defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__)
|
||||
!defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && !defined(_BSD_SOURCE)
|
||||
#define _BSD_SOURCE 1
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
@@ -14,6 +14,5 @@
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/temp.h"
|
||||
#include "third_party/musl/crypt.h"
|
||||
#include "third_party/musl/rand48.h"
|
||||
#endif /* _STDLIB_H */
|
||||
@@ -10,12 +10,8 @@
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/ok.h"
|
||||
#include "libc/time/time.h"
|
||||
#include "libc/unistd.h"
|
||||
#include "third_party/getopt/long1.h"
|
||||
#include "third_party/musl/crypt.h"
|
||||
#include "third_party/musl/lockf.h"
|
||||
|
||||
#ifndef _CS_PATH
|
||||
#define _CS_PATH 0
|
||||
#endif
|
||||
|
||||
#endif /* _UNISTD_H */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -25,33 +25,33 @@ forceinline char *__stpcpy(char *d, const char *s) {
|
||||
}
|
||||
|
||||
forceinline void *__repstosb(void *di, char al, size_t cx) {
|
||||
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
asm("rep stosb"
|
||||
: "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di)
|
||||
: "0"(di), "1"(cx), "a"(al));
|
||||
#if defined(__x86__) && defined(__GNUC__)
|
||||
__asm__("rep stosb"
|
||||
: "=D"(di), "=c"(cx), "=m"(*(char(*)[cx])di)
|
||||
: "0"(di), "1"(cx), "a"(al));
|
||||
return di;
|
||||
#else
|
||||
char *d = di;
|
||||
while (cx--) {
|
||||
*d++ = al;
|
||||
asm volatile("" ::: "memory");
|
||||
__asm__ volatile("" ::: "memory");
|
||||
}
|
||||
return (void *)d;
|
||||
#endif
|
||||
}
|
||||
|
||||
forceinline void *__repmovsb(void *di, const void *si, size_t cx) {
|
||||
#if defined(__x86__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
asm("rep movsb"
|
||||
: "=D"(di), "=S"(si), "=c"(cx), "=m"(*(char(*)[cx])di)
|
||||
: "0"(di), "1"(si), "2"(cx), "m"(*(char(*)[cx])si));
|
||||
#if defined(__x86__) && defined(__GNUC__)
|
||||
__asm__("rep movsb"
|
||||
: "=D"(di), "=S"(si), "=c"(cx), "=m"(*(char(*)[cx])di)
|
||||
: "0"(di), "1"(si), "2"(cx), "m"(*(char(*)[cx])si));
|
||||
return di;
|
||||
#else
|
||||
char *d = di;
|
||||
const char *s = si;
|
||||
while (cx--) {
|
||||
*d++ = *s++;
|
||||
asm volatile("" ::: "memory");
|
||||
__asm__ volatile("" ::: "memory");
|
||||
}
|
||||
return (void *)d;
|
||||
#endif
|
||||
@@ -61,7 +61,7 @@ forceinline void *__mempcpy(void *d, const void *s, size_t n) {
|
||||
size_t i;
|
||||
for (i = 0; i < n; ++i) {
|
||||
((char *)d)[i] = ((const char *)s)[i];
|
||||
asm volatile("" ::: "memory");
|
||||
__asm__ volatile("" ::: "memory");
|
||||
}
|
||||
return (char *)d + n;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#define COSMOPOLITAN_LIBC_LOG_LOG_H_
|
||||
#include "libc/stdio/stdio.h"
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
#define kLogFatal 0
|
||||
#define kLogError 1
|
||||
@@ -224,5 +224,5 @@ void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
|
||||
|
||||
#endif /* __STRICT_ANSI__ */
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
+1
-1
@@ -21,6 +21,6 @@
|
||||
|
||||
FILE *__log_file;
|
||||
|
||||
__attribute__((__constructor__(60))) static void loginit(void) {
|
||||
__attribute__((__constructor__(61))) static void loginit(void) {
|
||||
__log_file = stderr;
|
||||
}
|
||||
+63
-10
@@ -9,15 +9,47 @@
|
||||
#define M_LOG10E 0.43429448190325182765 /* log₁₀𝑒 */
|
||||
#define M_LN2 0.69314718055994530942 /* logₑ2 */
|
||||
#define M_LN10 2.30258509299404568402 /* logₑ10 */
|
||||
#define M_PI 3.14159265358979323846 /* pi */
|
||||
#define M_PI_2 1.57079632679489661923 /* pi/2 */
|
||||
#define M_PI_4 0.78539816339744830962 /* pi/4 */
|
||||
#define M_1_PI 0.31830988618379067154 /* 1/pi */
|
||||
#define M_2_PI 0.63661977236758134308 /* 2/pi */
|
||||
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
|
||||
#define M_PI 3.14159265358979323846 /* 𝜋 */
|
||||
#define M_PI_2 1.57079632679489661923 /* 𝜋/2 */
|
||||
#define M_PI_4 0.78539816339744830962 /* 𝜋/4 */
|
||||
#define M_1_PI 0.31830988618379067154 /* 1/𝜋 */
|
||||
#define M_2_PI 0.63661977236758134308 /* 2/𝜋 */
|
||||
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(𝜋) */
|
||||
#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
|
||||
#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
|
||||
#define M_Ef 2.7182818284590452354f /* 𝑒 */
|
||||
#define M_LOG2Ef 1.4426950408889634074f /* log₂𝑒 */
|
||||
#define M_LOG10Ef 0.43429448190325182765f /* log₁₀𝑒 */
|
||||
#define M_LN2f 0.69314718055994530942f /* logₑ2 */
|
||||
#define M_LN10f 2.30258509299404568402f /* logₑ10 */
|
||||
#define M_PIf 3.14159265358979323846f /* 𝜋 */
|
||||
#define M_PI_2f 1.57079632679489661923f /* 𝜋/2 */
|
||||
#define M_PI_4f 0.78539816339744830962f /* 𝜋/4 */
|
||||
#define M_1_PIf 0.31830988618379067154f /* 1/𝜋 */
|
||||
#define M_2_PIf 0.63661977236758134308f /* 2/𝜋 */
|
||||
#define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(𝜋) */
|
||||
#define M_SQRT2f 1.41421356237309504880f /* sqrt(2) */
|
||||
#define M_SQRT1_2f 0.70710678118654752440f /* 1/sqrt(2) */
|
||||
#endif
|
||||
|
||||
#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
|
||||
#define M_El 2.718281828459045235360287471352662498L /* 𝑒 */
|
||||
#define M_LOG2El 1.442695040888963407359924681001892137L /* log₂𝑒 */
|
||||
#define M_LOG10El 0.434294481903251827651128918916605082L /* log₁₀𝑒 */
|
||||
#define M_LN2l 0.693147180559945309417232121458176568L /* logₑ2 */
|
||||
#define M_LN10l 2.302585092994045684017991454684364208L /* logₑ10 */
|
||||
#define M_PIl 3.141592653589793238462643383279502884L /* 𝜋 */
|
||||
#define M_PI_2l 1.570796326794896619231321691639751442L /* 𝜋/2 */
|
||||
#define M_PI_4l 0.785398163397448309615660845819875721L /* 𝜋/4 */
|
||||
#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/𝜋 */
|
||||
#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/𝜋 */
|
||||
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(𝜋) */
|
||||
#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
|
||||
#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
|
||||
#endif
|
||||
|
||||
#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
|
||||
#define DBL_DIG __DBL_DIG__
|
||||
#define DBL_EPSILON __DBL_EPSILON__
|
||||
@@ -76,6 +108,27 @@
|
||||
#define FP_ILOGB0 (-2147483647 - 1)
|
||||
#define FP_ILOGBNAN (-2147483647 - 1)
|
||||
|
||||
#define MATH_ERRNO 1
|
||||
#define MATH_ERREXCEPT 2
|
||||
|
||||
#ifdef __FAST_MATH__
|
||||
#define math_errhandling 0
|
||||
#elif defined(__NO_MATH_ERRNO__)
|
||||
#define math_errhandling (MATH_ERREXCEPT)
|
||||
#else
|
||||
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
|
||||
#endif
|
||||
|
||||
#ifdef __FP_FAST_FMA
|
||||
#define FP_FAST_FMA 1
|
||||
#endif
|
||||
#ifdef __FP_FAST_FMAF
|
||||
#define FP_FAST_FMAF 1
|
||||
#endif
|
||||
#ifdef __FP_FAST_FMAL
|
||||
#define FP_FAST_FMAL 1
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define NAN __builtin_nanf("")
|
||||
@@ -106,10 +159,10 @@ typedef double double_t;
|
||||
#define fpclassify(x) \
|
||||
__builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
|
||||
|
||||
#define signbit(x) \
|
||||
(sizeof(x) == sizeof(double) ? __builtin_signbit(x) \
|
||||
: sizeof(x) == sizeof(float) ? __builtin_signbitf(x) \
|
||||
: __builtin_signbitl(x))
|
||||
#define signbit(x) \
|
||||
(sizeof(x) == sizeof(long double) ? __builtin_signbitl(x) \
|
||||
: sizeof(x) == sizeof(float) ? __builtin_signbitf(x) \
|
||||
: __builtin_signbit(x))
|
||||
|
||||
extern int signgam;
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
|
||||
#define COSMOPOLITAN_LIBC_MEM_GC_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
libcesque void _gc_free(void *);
|
||||
@@ -19,5 +19,5 @@ libcesque void gclongjmp(void *, int) wontreturn;
|
||||
})
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct StackFrame {
|
||||
@@ -9,5 +9,5 @@ struct StackFrame {
|
||||
};
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
@@ -27,6 +27,7 @@ COSMOPOLITAN_C_START_
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
|
||||
int64_t LoadLibrary(const char16_t *lpLibFileName);
|
||||
int64_t LoadLibraryA(const char *lpLibFileName);
|
||||
int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile,
|
||||
uint32_t dwFlags);
|
||||
uint32_t GetModuleFileNameA(int64_t hModule, char *lpFilename, uint32_t nSize);
|
||||
|
||||
@@ -57,6 +57,9 @@ int32_t DeregisterEventSource(uint64_t handle);
|
||||
int64_t CreateEvent(const struct NtSecurityAttributes *opt_lpEventAttributes,
|
||||
bool32 bManualReset, bool32 bInitialState,
|
||||
const char16_t *opt_lpName);
|
||||
int64_t CreateEventA(const struct NtSecurityAttributes *opt_lpEventAttributes,
|
||||
bool32 bManualReset, bool32 bInitialState,
|
||||
const char *opt_lpName);
|
||||
int64_t CreateEventEx(const struct NtSecurityAttributes *lpEventAttributes,
|
||||
const char16_t *lpName, uint32_t dwFlags,
|
||||
uint32_t dwDesiredAccess);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_CreateEventA,CreateEventA
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
CreateEventA:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov __imp_CreateEventA(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
ret
|
||||
#endif
|
||||
.endfn CreateEventA,globl
|
||||
.previous
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_GetNumaProcessorNodeEx,GetNumaProcessorNodeEx
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
GetNumaProcessorNodeEx:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov __imp_GetNumaProcessorNodeEx(%rip),%rax
|
||||
jmp __sysv2nt
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
ret
|
||||
#endif
|
||||
.endfn GetNumaProcessorNodeEx,globl
|
||||
.previous
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "libc/nt/codegen.h"
|
||||
.imp kernel32,__imp_LoadLibraryA,LoadLibraryA
|
||||
|
||||
.text.windows
|
||||
.ftrace1
|
||||
LoadLibraryA:
|
||||
.ftrace2
|
||||
#ifdef __x86_64__
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
mov %rdi,%rcx
|
||||
sub $32,%rsp
|
||||
call *__imp_LoadLibraryA(%rip)
|
||||
leave
|
||||
#elif defined(__aarch64__)
|
||||
mov x0,#0
|
||||
#endif
|
||||
ret
|
||||
.endfn LoadLibraryA,globl
|
||||
.previous
|
||||
@@ -63,6 +63,7 @@ imp 'ConnectNamedPipe' ConnectNamedPipe kernel32 2
|
||||
imp 'ContinueDebugEvent' ContinueDebugEvent kernel32 3
|
||||
imp 'CopyFile' CopyFileW kernel32 3
|
||||
imp 'CreateEvent' CreateEventW kernel32 4
|
||||
imp 'CreateEventA' CreateEventA kernel32 4
|
||||
imp 'CreateEventEx' CreateEventExW kernel32 4
|
||||
imp 'CreateHardLink' CreateHardLinkW kernel32 3
|
||||
imp 'CreateIoCompletionPort' CreateIoCompletionPort kernel32 4
|
||||
@@ -134,6 +135,7 @@ imp 'GetModuleHandle' GetModuleHandleA kernel32 1
|
||||
imp 'GetModuleHandleEx' GetModuleHandleExW kernel32 3
|
||||
imp 'GetModuleHandleW' GetModuleHandleW kernel32 1
|
||||
imp 'GetNamedPipeInfo' GetNamedPipeInfo kernel32 5
|
||||
imp 'GetNumaProcessorNodeEx' GetNumaProcessorNodeEx kernel32 2
|
||||
imp 'GetNumberOfConsoleInputEvents' GetNumberOfConsoleInputEvents kernel32 2
|
||||
imp 'GetNumberOfConsoleMouseButtons' GetNumberOfConsoleMouseButtons kernel32 1
|
||||
imp 'GetOverlappedResult' GetOverlappedResult kernel32 4
|
||||
@@ -195,6 +197,7 @@ imp 'InitializeProcThreadAttributeList' InitializeProcThreadAttributeList ke
|
||||
imp 'InitializeSRWLock' InitializeSRWLock kernel32 1
|
||||
imp 'LeaveCriticalSection' LeaveCriticalSection kernel32 1
|
||||
imp 'LoadLibrary' LoadLibraryW kernel32 1
|
||||
imp 'LoadLibraryA' LoadLibraryA kernel32 1
|
||||
imp 'LoadLibraryEx' LoadLibraryExW kernel32 3
|
||||
imp 'LoadResource' LoadResource kernel32 2
|
||||
imp 'LocalFree' LocalFree kernel32 1
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_NT_TEB_H_
|
||||
#define COSMOPOLITAN_LIBC_NT_TEB_H_
|
||||
#include "libc/nt/struct/peb.h"
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
||||
#ifdef __GNUC__
|
||||
|
||||
/*
|
||||
* These macros address directly into NT's TEB a.k.a. TIB
|
||||
@@ -21,5 +21,5 @@
|
||||
#define _NtGetRpc() ((void *)*(__seg_gs uintptr_t *)0x50)
|
||||
#define _NtGetTls() ((void *)*(__seg_gs uintptr_t *)0x58)
|
||||
|
||||
#endif /* __GNUC__ && !__STRICT_ANSI__ */
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* COSMOPOLITAN_LIBC_NT_TEB_H_ */
|
||||
@@ -118,6 +118,9 @@ bool32 GetSystemTimeAdjustment(uint32_t *lpTimeAdjustment,
|
||||
|
||||
void GetCurrentProcessorNumberEx(struct NtProcessorNumber *out_ProcNumber);
|
||||
|
||||
bool32 GetNumaProcessorNodeEx(const struct NtProcessorNumber *Processor,
|
||||
unsigned short *out_NodeNumber);
|
||||
|
||||
#if ShouldUseMsabiAttribute()
|
||||
#include "libc/nt/thunk/synchronization.inc"
|
||||
#endif /* ShouldUseMsabiAttribute() */
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
|
||||
#ifdef __x86_64__
|
||||
|
||||
#if !defined(__STRICT_ANSI__) && \
|
||||
(__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
|
||||
#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
|
||||
(__has_attribute(__ms_abi__) || defined(__llvm__)))
|
||||
/**
|
||||
* Defines function as using Microsoft x64 calling convention.
|
||||
|
||||
+7
-7
@@ -8,13 +8,13 @@ bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
|
||||
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
|
||||
#define GetNtMajorVersion() \
|
||||
({ \
|
||||
uintptr_t __x; \
|
||||
asm("mov\t%%gs:96,%q0\r\n" \
|
||||
"mov\t280(%q0),%b0" \
|
||||
: "=q"(__x)); \
|
||||
(unsigned char)__x; \
|
||||
#define GetNtMajorVersion() \
|
||||
__extension__({ \
|
||||
uintptr_t __x; \
|
||||
__asm__("mov\t%%gs:96,%q0\r\n" \
|
||||
"mov\t280(%q0),%b0" \
|
||||
: "=q"(__x)); \
|
||||
(unsigned char)__x; \
|
||||
})
|
||||
#endif
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ static struct CosmoFtrace g_ftrace;
|
||||
|
||||
__funline int GetNestingLevelImpl(struct StackFrame *frame) {
|
||||
int nesting = -2;
|
||||
while (frame) {
|
||||
while (frame && !kisdangerous(frame)) {
|
||||
++nesting;
|
||||
frame = frame->next;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
||||
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
/**
|
||||
* Returns preferred size and alignment of thread stack.
|
||||
@@ -56,7 +56,7 @@
|
||||
#define _STACK_EXTRA ""
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && defined(__ELF__) && !defined(__STRICT_ANSI__)
|
||||
#if defined(__GNUC__) && defined(__ELF__)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
extern char ape_stack_prot[] __attribute__((__weak__));
|
||||
@@ -156,5 +156,5 @@ int FreeCosmoStack(void *) libcesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* GNU ELF */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#ifdef _COSMO_SOURCE
|
||||
#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
||||
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_
|
||||
#ifdef _COSMO_SOURCE
|
||||
|
||||
#define APPEND_COOKIE 21578
|
||||
|
||||
@@ -32,5 +32,5 @@ ssize_t kappendf(char **, const char *, ...) libcesque;
|
||||
ssize_t kvappendf(char **, const char *, va_list) libcesque;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* _COSMO_SOURCE */
|
||||
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */
|
||||
#endif /* _COSMO_SOURCE */
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/unistd.h"
|
||||
|
||||
size_t confstr(int name, char *buf, size_t len) {
|
||||
if (name == _CS_PATH) {
|
||||
|
||||
+5
-6
@@ -1,12 +1,11 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_STDIO_H_
|
||||
#define COSMOPOLITAN_LIBC_STDIO_H_
|
||||
|
||||
#define EOF -1 /* end of file */
|
||||
#define WEOF -1u /* end of file (multibyte) */
|
||||
#define _IOFBF 0 /* fully buffered */
|
||||
#define _IOLBF 1 /* line buffered */
|
||||
#define _IONBF 2 /* no buffering */
|
||||
#define _CS_PATH 0
|
||||
#define EOF -1 /* end of file */
|
||||
#define WEOF -1u /* end of file (multibyte) */
|
||||
#define _IOFBF 0 /* fully buffered */
|
||||
#define _IOLBF 1 /* line buffered */
|
||||
#define _IONBF 2 /* no buffering */
|
||||
|
||||
#define L_tmpnam 20
|
||||
#define L_ctermid 20
|
||||
|
||||
@@ -43,8 +43,15 @@ long syscall(long number, ...) {
|
||||
size_t buflen = va_arg(va, size_t);
|
||||
unsigned flags = va_arg(va, unsigned);
|
||||
va_end(va);
|
||||
ssize_t rc = getrandom(buf, buflen, flags);
|
||||
return rc;
|
||||
return getrandom(buf, buflen, flags);
|
||||
}
|
||||
case SYS_getcpu: {
|
||||
va_list va;
|
||||
va_start(va, number);
|
||||
unsigned *cpu = va_arg(va, unsigned *);
|
||||
unsigned *node = va_arg(va, unsigned *);
|
||||
va_end(va);
|
||||
return getcpu(cpu, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define SYS_gettid 186
|
||||
#define SYS_getrandom 318
|
||||
#define SYS_gettid 1
|
||||
#define SYS_getrandom 2
|
||||
#define SYS_getcpu 3
|
||||
|
||||
long syscall(long, ...) libcesque;
|
||||
|
||||
|
||||
+29
-11
@@ -50,6 +50,12 @@
|
||||
} \
|
||||
c; \
|
||||
})
|
||||
#define UNBUFFER \
|
||||
({ \
|
||||
if (c != -1) { \
|
||||
fpbuf[--fpbufcur] = '\0'; \
|
||||
} \
|
||||
})
|
||||
|
||||
/**
|
||||
* String / file / stream decoder.
|
||||
@@ -369,10 +375,11 @@ int __vcscanf(int callback(void *), //
|
||||
}
|
||||
} while ((c = BUFFER) != -1 && c != ')');
|
||||
if (c == ')') {
|
||||
c = BUFFER;
|
||||
c = READ;
|
||||
}
|
||||
goto GotFloatingPointNumber;
|
||||
} else {
|
||||
UNBUFFER;
|
||||
goto GotFloatingPointNumber;
|
||||
}
|
||||
} else {
|
||||
@@ -410,9 +417,7 @@ int __vcscanf(int callback(void *), //
|
||||
goto Done;
|
||||
}
|
||||
} else {
|
||||
if (c != -1 && unget) {
|
||||
unget(c, arg);
|
||||
}
|
||||
UNBUFFER;
|
||||
goto GotFloatingPointNumber;
|
||||
}
|
||||
} else {
|
||||
@@ -465,13 +470,24 @@ int __vcscanf(int callback(void *), //
|
||||
Continue:
|
||||
continue;
|
||||
Break:
|
||||
if (c != -1 && unget) {
|
||||
unget(c, arg);
|
||||
}
|
||||
UNBUFFER;
|
||||
break;
|
||||
} while ((c = BUFFER) != -1);
|
||||
GotFloatingPointNumber:
|
||||
fp = strtod((char *)fpbuf, NULL);
|
||||
/* An empty buffer can't be a valid float; don't even bother parsing. */
|
||||
bool valid = fpbufcur > 0;
|
||||
if (valid) {
|
||||
char *ep;
|
||||
fp = strtod((char *)fpbuf, &ep);
|
||||
/* We should have parsed the whole buffer. */
|
||||
valid = ep == (char *)fpbuf + fpbufcur;
|
||||
}
|
||||
free(fpbuf);
|
||||
fpbuf = NULL;
|
||||
fpbufcur = fpbufsize = 0;
|
||||
if (!valid) {
|
||||
goto Done;
|
||||
}
|
||||
if (!discard) {
|
||||
++items;
|
||||
void *out = va_arg(va, void *);
|
||||
@@ -481,9 +497,6 @@ int __vcscanf(int callback(void *), //
|
||||
*(double *)out = (double)fp;
|
||||
}
|
||||
}
|
||||
free(fpbuf);
|
||||
fpbuf = NULL;
|
||||
fpbufcur = fpbufsize = 0;
|
||||
continue;
|
||||
ReportConsumed:
|
||||
n_ptr = va_arg(va, int *);
|
||||
@@ -537,6 +550,11 @@ int __vcscanf(int callback(void *), //
|
||||
if (!j && c == -1 && !items) {
|
||||
items = -1;
|
||||
goto Done;
|
||||
} else if (rawmode && j != width) {
|
||||
/* The C standard says that %c "matches a sequence of characters of
|
||||
* **exactly** the number specified by the field width". If we have
|
||||
* fewer characters, what we've just read is invalid. */
|
||||
goto Done;
|
||||
} else if (!rawmode && j < bufsize) {
|
||||
if (charbytes == sizeof(char)) {
|
||||
buf[j] = '\0';
|
||||
|
||||
@@ -6,5 +6,10 @@ char *fcvt(double, int, int *, int *) libcesque;
|
||||
char *ecvt(double, int, int *, int *) libcesque;
|
||||
char *gcvt(double, int, char *) libcesque;
|
||||
|
||||
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
|
||||
defined(_COSMO_SOURCE)
|
||||
void setkey(const char *) libcesque;
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_STDLIB_H_ */
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "libc/dce.h"
|
||||
#include "libc/thread/tls.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__STRICT_ANSI__)
|
||||
#if defined(__GNUC__) && defined(__x86_64__)
|
||||
|
||||
/**
|
||||
* Returns location of thread information block.
|
||||
@@ -14,9 +14,9 @@ COSMOPOLITAN_C_START_
|
||||
forceinline struct CosmoTib *__get_tls_privileged(void) {
|
||||
char *tib, *lin = (char *)0x30;
|
||||
if (IsNetbsd() || IsOpenbsd()) {
|
||||
asm("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
__asm__("mov\t%%fs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
} else {
|
||||
asm("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
__asm__("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
if (IsWindows()) {
|
||||
tib = *(char **)(tib + 0x1480 + __tls_index * 8);
|
||||
}
|
||||
@@ -26,13 +26,13 @@ forceinline struct CosmoTib *__get_tls_privileged(void) {
|
||||
|
||||
forceinline struct CosmoTib *__get_tls_win32(void) {
|
||||
char *tib, *lin = (char *)0x30;
|
||||
asm("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
__asm__("mov\t%%gs:(%1),%0" : "=a"(tib) : "r"(lin) : "memory");
|
||||
tib = *(char **)(tib + 0x1480 + __tls_index * 8);
|
||||
return (struct CosmoTib *)tib;
|
||||
}
|
||||
|
||||
forceinline void __set_tls_win32(void *tls) {
|
||||
asm("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tls));
|
||||
__asm__("mov\t%1,%%gs:%0" : "=m"(*((long *)0x1480 + __tls_index)) : "r"(tls));
|
||||
}
|
||||
|
||||
#elif defined(__aarch64__)
|
||||
|
||||
@@ -54,6 +54,7 @@ o/$(MODE)/libc/tinymath/loglq.o: private \
|
||||
|
||||
$(LIBC_TINYMATH_A_OBJS): private \
|
||||
CFLAGS += \
|
||||
-fmath-errno \
|
||||
-fsigned-zeros \
|
||||
-ftrapping-math \
|
||||
-frounding-math \
|
||||
|
||||
@@ -5,7 +5,7 @@ MIT OR Apache-2.0 WITH LLVM-exception
|
||||
MIT License
|
||||
-----------
|
||||
|
||||
Copyright (c) 1999-2022, Arm Limited.
|
||||
Copyright (c) 2018-2024, Arm Limited.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
double __math_divzero(uint32_t sign)
|
||||
{
|
||||
return fp_barrier(sign ? -1.0 : 1.0) / 0.0;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
float __math_divzerof(uint32_t sign)
|
||||
{
|
||||
return fp_barrierf(sign ? -1.0f : 1.0f) / 0.0f;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
double __math_invalid(double x)
|
||||
{
|
||||
return (x - x) / (x - x);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
float __math_invalidf(float x)
|
||||
{
|
||||
return (x - x) / (x - x);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
dontinstrument double __math_oflow(uint32_t sign)
|
||||
{
|
||||
return __math_xflow(sign, 0x1p769);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
dontinstrument float __math_oflowf(uint32_t sign)
|
||||
{
|
||||
return __math_xflowf(sign, 0x1p97f);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
dontinstrument double __math_uflow(uint32_t sign)
|
||||
{
|
||||
return __math_xflow(sign, 0x1p-767);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
dontinstrument float __math_uflowf(uint32_t sign)
|
||||
{
|
||||
return __math_xflowf(sign, 0x1p-95f);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
dontinstrument double __math_xflow(uint32_t sign, double y)
|
||||
{
|
||||
return eval_as_double(fp_barrier(sign ? -y : y) * y);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/tinymath/internal.h"
|
||||
|
||||
dontinstrument float __math_xflowf(uint32_t sign, float y)
|
||||
{
|
||||
return eval_as_float(fp_barrierf(sign ? -y : y) * y);
|
||||
}
|
||||
@@ -0,0 +1,509 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_TINYMATH_ARM_H_
|
||||
#define COSMOPOLITAN_LIBC_TINYMATH_ARM_H_
|
||||
#include "libc/math.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define USE_GLIBC_ABI 1
|
||||
|
||||
/* If defined to 1, return correct results for special cases in non-nearest
|
||||
rounding modes (logf (1.0f) returns 0.0f with FE_DOWNWARD rather than -0.0f).
|
||||
This may be set to 0 if there is no fenv support or if math functions only
|
||||
get called in round to nearest mode. */
|
||||
#ifdef __ROUNDING_MATH__
|
||||
#define WANT_ROUNDING 1
|
||||
#else
|
||||
#define WANT_ROUNDING 0
|
||||
#endif
|
||||
|
||||
/* If defined to 1, set errno in math functions according to ISO C. Many math
|
||||
libraries do not set errno, so this is 0 by default. It may need to be
|
||||
set to 1 if math.h has (math_errhandling & MATH_ERRNO) != 0. */
|
||||
#ifdef __NO_MATH_ERRNO__
|
||||
#define WANT_ERRNO 0
|
||||
#else
|
||||
#define WANT_ERRNO 1
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* optimized-routines/math/math_config.h */
|
||||
|
||||
#ifndef WANT_ROUNDING
|
||||
/* If defined to 1, return correct results for special cases in non-nearest
|
||||
rounding modes (logf (1.0f) returns 0.0f with FE_DOWNWARD rather than -0.0f).
|
||||
This may be set to 0 if there is no fenv support or if math functions only
|
||||
get called in round to nearest mode. */
|
||||
# define WANT_ROUNDING 1
|
||||
#endif
|
||||
#ifndef WANT_ERRNO
|
||||
/* If defined to 1, set errno in math functions according to ISO C. Many math
|
||||
libraries do not set errno, so this is 0 by default. It may need to be
|
||||
set to 1 if math.h has (math_errhandling & MATH_ERRNO) != 0. */
|
||||
# define WANT_ERRNO 0
|
||||
#endif
|
||||
#ifndef WANT_ERRNO_UFLOW
|
||||
/* Set errno to ERANGE if result underflows to 0 (in all rounding modes). */
|
||||
# define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
|
||||
#endif
|
||||
|
||||
/* Compiler can inline round as a single instruction. */
|
||||
#ifndef HAVE_FAST_ROUND
|
||||
# if __aarch64__
|
||||
# define HAVE_FAST_ROUND 1
|
||||
# else
|
||||
# define HAVE_FAST_ROUND 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Compiler can inline lround, but not (long)round(x). */
|
||||
#ifndef HAVE_FAST_LROUND
|
||||
# if __aarch64__ && (100*__GNUC__ + __GNUC_MINOR__) >= 408 && __NO_MATH_ERRNO__
|
||||
# define HAVE_FAST_LROUND 1
|
||||
# else
|
||||
# define HAVE_FAST_LROUND 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Compiler can inline fma as a single instruction. */
|
||||
#ifndef HAVE_FAST_FMA
|
||||
# if defined FP_FAST_FMA || __aarch64__
|
||||
# define HAVE_FAST_FMA 1
|
||||
# else
|
||||
# define HAVE_FAST_FMA 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Provide *_finite symbols and some of the glibc hidden symbols
|
||||
so libmathlib can be used with binaries compiled against glibc
|
||||
to interpose math functions with both static and dynamic linking. */
|
||||
#ifndef USE_GLIBC_ABI
|
||||
# if __GNUC__
|
||||
# define USE_GLIBC_ABI 1
|
||||
# else
|
||||
# define USE_GLIBC_ABI 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Optionally used extensions. */
|
||||
#ifdef __GNUC__
|
||||
# define HIDDEN __attribute__ ((__visibility__ ("hidden")))
|
||||
# define NOINLINE __attribute__ ((noinline))
|
||||
# define UNUSED __attribute__ ((unused))
|
||||
# define likely(x) __builtin_expect (!!(x), 1)
|
||||
# define unlikely(x) __builtin_expect (x, 0)
|
||||
# if __GNUC__ >= 9
|
||||
# define attribute_copy(f) __attribute__ ((copy (f)))
|
||||
# else
|
||||
# define attribute_copy(f)
|
||||
# endif
|
||||
# define strong_alias(f, a) \
|
||||
extern __typeof (f) a __attribute__ ((alias (#f))) attribute_copy (f);
|
||||
# define hidden_alias(f, a) \
|
||||
extern __typeof (f) a __attribute__ ((alias (#f), visibility ("hidden"))) \
|
||||
attribute_copy (f);
|
||||
#else
|
||||
# define HIDDEN
|
||||
# define NOINLINE
|
||||
# define UNUSED
|
||||
# define likely(x) (x)
|
||||
# define unlikely(x) (x)
|
||||
#endif
|
||||
|
||||
/* Return ptr but hide its value from the compiler so accesses through it
|
||||
cannot be optimized based on the contents. */
|
||||
#define ptr_barrier(ptr) \
|
||||
({ \
|
||||
__typeof (ptr) __ptr = (ptr); \
|
||||
__asm("" : "+r"(__ptr)); \
|
||||
__ptr; \
|
||||
})
|
||||
|
||||
#if HAVE_FAST_ROUND
|
||||
/* When set, the roundtoint and converttoint functions are provided with
|
||||
the semantics documented below. */
|
||||
# define TOINT_INTRINSICS 1
|
||||
|
||||
/* Round x to nearest int in all rounding modes, ties have to be rounded
|
||||
consistently with converttoint so the results match. If the result
|
||||
would be outside of [-2^31, 2^31-1] then the semantics is unspecified. */
|
||||
static inline double_t
|
||||
roundtoint (double_t x)
|
||||
{
|
||||
return round (x);
|
||||
}
|
||||
|
||||
/* Convert x to nearest int in all rounding modes, ties have to be rounded
|
||||
consistently with roundtoint. If the result is not representible in an
|
||||
int32_t then the semantics is unspecified. */
|
||||
static inline int32_t
|
||||
converttoint (double_t x)
|
||||
{
|
||||
# if HAVE_FAST_LROUND
|
||||
return lround (x);
|
||||
# else
|
||||
return (long) round (x);
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline uint32_t
|
||||
asuint (float f)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u = {f};
|
||||
return u.i;
|
||||
}
|
||||
|
||||
static inline float
|
||||
asfloat (uint32_t i)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t i;
|
||||
float f;
|
||||
} u = {i};
|
||||
return u.f;
|
||||
}
|
||||
|
||||
static inline uint64_t
|
||||
asuint64 (double f)
|
||||
{
|
||||
union
|
||||
{
|
||||
double f;
|
||||
uint64_t i;
|
||||
} u = {f};
|
||||
return u.i;
|
||||
}
|
||||
|
||||
static inline double
|
||||
asdouble (uint64_t i)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint64_t i;
|
||||
double f;
|
||||
} u = {i};
|
||||
return u.f;
|
||||
}
|
||||
|
||||
#ifndef IEEE_754_2008_SNAN
|
||||
# define IEEE_754_2008_SNAN 1
|
||||
#endif
|
||||
static inline int
|
||||
issignalingf_inline (float x)
|
||||
{
|
||||
uint32_t ix = asuint (x);
|
||||
if (!IEEE_754_2008_SNAN)
|
||||
return (ix & 0x7fc00000) == 0x7fc00000;
|
||||
return 2 * (ix ^ 0x00400000) > 2u * 0x7fc00000;
|
||||
}
|
||||
|
||||
static inline int
|
||||
issignaling_inline (double x)
|
||||
{
|
||||
uint64_t ix = asuint64 (x);
|
||||
if (!IEEE_754_2008_SNAN)
|
||||
return (ix & 0x7ff8000000000000) == 0x7ff8000000000000;
|
||||
return 2 * (ix ^ 0x0008000000000000) > 2 * 0x7ff8000000000000ULL;
|
||||
}
|
||||
|
||||
#if __aarch64__ && __GNUC__
|
||||
/* Prevent the optimization of a floating-point expression. */
|
||||
static inline float
|
||||
opt_barrier_float (float x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w" (x));
|
||||
return x;
|
||||
}
|
||||
static inline double
|
||||
opt_barrier_double (double x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w" (x));
|
||||
return x;
|
||||
}
|
||||
/* Force the evaluation of a floating-point expression for its side-effect. */
|
||||
static inline void
|
||||
force_eval_float (float x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w" (x));
|
||||
}
|
||||
static inline void
|
||||
force_eval_double (double x)
|
||||
{
|
||||
__asm__ __volatile__ ("" : "+w" (x));
|
||||
}
|
||||
#else
|
||||
static inline float
|
||||
opt_barrier_float (float x)
|
||||
{
|
||||
volatile float y = x;
|
||||
return y;
|
||||
}
|
||||
static inline double
|
||||
opt_barrier_double (double x)
|
||||
{
|
||||
volatile double y = x;
|
||||
return y;
|
||||
}
|
||||
static inline void
|
||||
force_eval_float (float x)
|
||||
{
|
||||
volatile float y UNUSED = x;
|
||||
}
|
||||
static inline void
|
||||
force_eval_double (double x)
|
||||
{
|
||||
volatile double y UNUSED = x;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Evaluate an expression as the specified type, normally a type
|
||||
cast should be enough, but compilers implement non-standard
|
||||
excess-precision handling, so when FLT_EVAL_METHOD != 0 then
|
||||
these functions may need to be customized. */
|
||||
static inline float
|
||||
eval_as_float (float x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
static inline double
|
||||
eval_as_double (double x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/* Error handling tail calls for special cases, with a sign argument.
|
||||
The sign of the return value is set if the argument is non-zero. */
|
||||
|
||||
/* The result overflows. */
|
||||
HIDDEN float __math_oflowf (uint32_t);
|
||||
/* The result underflows to 0 in nearest rounding mode. */
|
||||
HIDDEN float __math_uflowf (uint32_t);
|
||||
/* The result underflows to 0 in some directed rounding mode only. */
|
||||
HIDDEN float __math_may_uflowf (uint32_t);
|
||||
/* Division by zero. */
|
||||
HIDDEN float __math_divzerof (uint32_t);
|
||||
/* The result overflows. */
|
||||
HIDDEN double __math_oflow (uint32_t);
|
||||
/* The result underflows to 0 in nearest rounding mode. */
|
||||
HIDDEN double __math_uflow (uint32_t);
|
||||
/* The result underflows to 0 in some directed rounding mode only. */
|
||||
HIDDEN double __math_may_uflow (uint32_t);
|
||||
/* Division by zero. */
|
||||
HIDDEN double __math_divzero (uint32_t);
|
||||
|
||||
/* Error handling using input checking. */
|
||||
|
||||
/* Invalid input unless it is a quiet NaN. */
|
||||
HIDDEN float __math_invalidf (float);
|
||||
/* Invalid input unless it is a quiet NaN. */
|
||||
HIDDEN double __math_invalid (double);
|
||||
/* Invalid input unless it is a quiet NaN. */
|
||||
HIDDEN long double __math_invalidl (long double);
|
||||
|
||||
/* Error handling using output checking, only for errno setting. */
|
||||
|
||||
/* Check if the result overflowed to infinity. */
|
||||
HIDDEN double __math_check_oflow (double);
|
||||
/* Check if the result underflowed to 0. */
|
||||
HIDDEN double __math_check_uflow (double);
|
||||
|
||||
/* Check if the result overflowed to infinity. */
|
||||
static inline double
|
||||
check_oflow (double x)
|
||||
{
|
||||
return WANT_ERRNO ? __math_check_oflow (x) : x;
|
||||
}
|
||||
|
||||
/* Check if the result underflowed to 0. */
|
||||
static inline double
|
||||
check_uflow (double x)
|
||||
{
|
||||
return WANT_ERRNO ? __math_check_uflow (x) : x;
|
||||
}
|
||||
|
||||
/* Check if the result overflowed to infinity. */
|
||||
HIDDEN float __math_check_oflowf (float);
|
||||
/* Check if the result underflowed to 0. */
|
||||
HIDDEN float __math_check_uflowf (float);
|
||||
|
||||
/* Check if the result overflowed to infinity. */
|
||||
static inline float
|
||||
check_oflowf (float x)
|
||||
{
|
||||
return WANT_ERRNO ? __math_check_oflowf (x) : x;
|
||||
}
|
||||
|
||||
/* Check if the result underflowed to 0. */
|
||||
static inline float
|
||||
check_uflowf (float x)
|
||||
{
|
||||
return WANT_ERRNO ? __math_check_uflowf (x) : x;
|
||||
}
|
||||
|
||||
/* Shared between expf, exp2f and powf. */
|
||||
#define EXP2F_TABLE_BITS 5
|
||||
#define EXP2F_POLY_ORDER 3
|
||||
extern const struct exp2f_data
|
||||
{
|
||||
uint64_t tab[1 << EXP2F_TABLE_BITS];
|
||||
double shift_scaled;
|
||||
double poly[EXP2F_POLY_ORDER];
|
||||
double shift;
|
||||
double invln2_scaled;
|
||||
double poly_scaled[EXP2F_POLY_ORDER];
|
||||
} __exp2f_data HIDDEN;
|
||||
|
||||
#define LOGF_TABLE_BITS 4
|
||||
#define LOGF_POLY_ORDER 4
|
||||
extern const struct logf_data
|
||||
{
|
||||
struct
|
||||
{
|
||||
double invc, logc;
|
||||
} tab[1 << LOGF_TABLE_BITS];
|
||||
double ln2;
|
||||
double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1. */
|
||||
} __logf_data HIDDEN;
|
||||
|
||||
#define LOG2F_TABLE_BITS 4
|
||||
#define LOG2F_POLY_ORDER 4
|
||||
extern const struct log2f_data
|
||||
{
|
||||
struct
|
||||
{
|
||||
double invc, logc;
|
||||
} tab[1 << LOG2F_TABLE_BITS];
|
||||
double poly[LOG2F_POLY_ORDER];
|
||||
} __log2f_data HIDDEN;
|
||||
|
||||
#define POWF_LOG2_TABLE_BITS 4
|
||||
#define POWF_LOG2_POLY_ORDER 5
|
||||
#if TOINT_INTRINSICS
|
||||
# define POWF_SCALE_BITS EXP2F_TABLE_BITS
|
||||
#else
|
||||
# define POWF_SCALE_BITS 0
|
||||
#endif
|
||||
#define POWF_SCALE ((double) (1 << POWF_SCALE_BITS))
|
||||
extern const struct powf_log2_data
|
||||
{
|
||||
struct
|
||||
{
|
||||
double invc, logc;
|
||||
} tab[1 << POWF_LOG2_TABLE_BITS];
|
||||
double poly[POWF_LOG2_POLY_ORDER];
|
||||
} __powf_log2_data HIDDEN;
|
||||
|
||||
|
||||
#define EXP_TABLE_BITS 7
|
||||
#define EXP_POLY_ORDER 5
|
||||
/* Use polynomial that is optimized for a wider input range. This may be
|
||||
needed for good precision in non-nearest rounding and !TOINT_INTRINSICS. */
|
||||
#define EXP_POLY_WIDE 0
|
||||
/* Use close to nearest rounding toint when !TOINT_INTRINSICS. This may be
|
||||
needed for good precision in non-nearest rouning and !EXP_POLY_WIDE. */
|
||||
#define EXP_USE_TOINT_NARROW 0
|
||||
#define EXP2_POLY_ORDER 5
|
||||
#define EXP2_POLY_WIDE 0
|
||||
/* Wider exp10 polynomial necessary for good precision in non-nearest rounding
|
||||
and !TOINT_INTRINSICS. */
|
||||
#define EXP10_POLY_WIDE 0
|
||||
extern const struct exp_data
|
||||
{
|
||||
double invln2N;
|
||||
double invlog10_2N;
|
||||
double shift;
|
||||
double negln2hiN;
|
||||
double negln2loN;
|
||||
double neglog10_2hiN;
|
||||
double neglog10_2loN;
|
||||
double poly[4]; /* Last four coefficients. */
|
||||
double exp2_shift;
|
||||
double exp2_poly[EXP2_POLY_ORDER];
|
||||
double exp10_poly[5];
|
||||
uint64_t tab[2*(1 << EXP_TABLE_BITS)];
|
||||
} __exp_data HIDDEN;
|
||||
|
||||
#define LOG_TABLE_BITS 7
|
||||
#define LOG_POLY_ORDER 6
|
||||
#define LOG_POLY1_ORDER 12
|
||||
extern const struct log_data
|
||||
{
|
||||
double ln2hi;
|
||||
double ln2lo;
|
||||
double poly[LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
|
||||
double poly1[LOG_POLY1_ORDER - 1];
|
||||
struct {double invc, logc;} tab[1 << LOG_TABLE_BITS];
|
||||
#if !HAVE_FAST_FMA
|
||||
struct {double chi, clo;} tab2[1 << LOG_TABLE_BITS];
|
||||
#endif
|
||||
} __log_data HIDDEN;
|
||||
|
||||
#define LOG2_TABLE_BITS 6
|
||||
#define LOG2_POLY_ORDER 7
|
||||
#define LOG2_POLY1_ORDER 11
|
||||
extern const struct log2_data
|
||||
{
|
||||
double invln2hi;
|
||||
double invln2lo;
|
||||
double poly[LOG2_POLY_ORDER - 1];
|
||||
double poly1[LOG2_POLY1_ORDER - 1];
|
||||
struct {double invc, logc;} tab[1 << LOG2_TABLE_BITS];
|
||||
#if !HAVE_FAST_FMA
|
||||
struct {double chi, clo;} tab2[1 << LOG2_TABLE_BITS];
|
||||
#endif
|
||||
} __log2_data HIDDEN;
|
||||
|
||||
#define POW_LOG_TABLE_BITS 7
|
||||
#define POW_LOG_POLY_ORDER 8
|
||||
extern const struct pow_log_data
|
||||
{
|
||||
double ln2hi;
|
||||
double ln2lo;
|
||||
double poly[POW_LOG_POLY_ORDER - 1]; /* First coefficient is 1. */
|
||||
/* Note: the pad field is unused, but allows slightly faster indexing. */
|
||||
struct {double invc, pad, logc, logctail;} tab[1 << POW_LOG_TABLE_BITS];
|
||||
} __pow_log_data HIDDEN;
|
||||
|
||||
extern const struct erff_data
|
||||
{
|
||||
float erff_poly_A[6];
|
||||
float erff_poly_B[7];
|
||||
} __erff_data HIDDEN;
|
||||
|
||||
#define ERF_POLY_A_ORDER 19
|
||||
#define ERF_POLY_A_NCOEFFS 10
|
||||
#define ERFC_POLY_C_NCOEFFS 16
|
||||
#define ERFC_POLY_D_NCOEFFS 18
|
||||
#define ERFC_POLY_E_NCOEFFS 14
|
||||
#define ERFC_POLY_F_NCOEFFS 17
|
||||
extern const struct erf_data
|
||||
{
|
||||
double erf_poly_A[ERF_POLY_A_NCOEFFS];
|
||||
double erf_ratio_N_A[5];
|
||||
double erf_ratio_D_A[5];
|
||||
double erf_ratio_N_B[7];
|
||||
double erf_ratio_D_B[6];
|
||||
double erfc_poly_C[ERFC_POLY_C_NCOEFFS];
|
||||
double erfc_poly_D[ERFC_POLY_D_NCOEFFS];
|
||||
double erfc_poly_E[ERFC_POLY_E_NCOEFFS];
|
||||
double erfc_poly_F[ERFC_POLY_F_NCOEFFS];
|
||||
} __erf_data HIDDEN;
|
||||
|
||||
#define V_EXP_TABLE_BITS 7
|
||||
extern const uint64_t __v_exp_data[1 << V_EXP_TABLE_BITS] HIDDEN;
|
||||
|
||||
#define V_LOG_TABLE_BITS 7
|
||||
extern const struct v_log_data
|
||||
{
|
||||
struct
|
||||
{
|
||||
double invc, logc;
|
||||
} table[1 << V_LOG_TABLE_BITS];
|
||||
} __v_log_data HIDDEN;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_ARM_H_ */
|
||||
+8
-10
@@ -5,13 +5,6 @@
|
||||
│ FreeBSD lib/msun/src/s_asinhl.c │
|
||||
│ Converted to ldbl by David Schultz <[email protected]> and Bruce D. Evans. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
│ Copyright (c) 1992-2023 The FreeBSD Project. │
|
||||
│ │
|
||||
│ Redistribution and use in source and binary forms, with or without │
|
||||
@@ -35,12 +28,17 @@
|
||||
│ 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/freebsd.internal.h"
|
||||
|
||||
__static_yoink("fdlibm_notice");
|
||||
__static_yoink("freebsd_libm_notice");
|
||||
__static_yoink("fdlibm_notice");
|
||||
|
||||
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
|
||||
|
||||
|
||||
+101
-158
@@ -1,177 +1,120 @@
|
||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=8 sts=2 sw=2 fenc=utf-8 :vi │
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Optimized Routines │
|
||||
│ Copyright (c) 1999-2022, Arm Limited. │
|
||||
│ FreeBSD lib/msun/src/s_asinhl.c │
|
||||
│ Converted to ldbl by David Schultz <[email protected]> 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) 1993 by Sun Microsystems, Inc. All rights reserved. │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ 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. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ Copyright (c) 1992-2023 The FreeBSD Project. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/likely.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/atanf_common.internal.h"
|
||||
#include "libc/tinymath/internal.h"
|
||||
__static_yoink("arm_optimized_routines_notice");
|
||||
#include "libc/tinymath/freebsd.internal.h"
|
||||
__static_yoink("freebsd_libm_notice");
|
||||
__static_yoink("fdlibm_notice");
|
||||
|
||||
#define Pi (0x1.921fb6p+1f)
|
||||
#define PiOver2 (0x1.921fb6p+0f)
|
||||
#define PiOver4 (0x1.921fb6p-1f)
|
||||
#define SignMask (0x80000000)
|
||||
static volatile float
|
||||
tiny = 1.0e-30;
|
||||
static const float
|
||||
zero = 0.0,
|
||||
pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
|
||||
pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
|
||||
pi = 3.1415927410e+00; /* 0x40490fdb */
|
||||
static volatile float
|
||||
pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */
|
||||
|
||||
/* We calculate atan2f by P(n/d), where n and d are similar to the input
|
||||
arguments, and P is a polynomial. The polynomial may underflow.
|
||||
POLY_UFLOW_BOUND is the lower bound of the difference in exponents of n and d
|
||||
for which P underflows, and is used to special-case such inputs. */
|
||||
#define POLY_UFLOW_BOUND 24
|
||||
|
||||
static inline int32_t
|
||||
biased_exponent (float f)
|
||||
{
|
||||
uint32_t fi = asuint (f);
|
||||
int32_t ex = (int32_t) ((fi & 0x7f800000) >> 23);
|
||||
if (UNLIKELY (ex == 0))
|
||||
{
|
||||
/* Subnormal case - we still need to get the exponent right for subnormal
|
||||
numbers as division may take us back inside the normal range. */
|
||||
return ex - __builtin_clz (fi << 9);
|
||||
}
|
||||
return ex;
|
||||
}
|
||||
|
||||
/* Fast implementation of scalar atan2f. Largest observed error is
|
||||
2.88ulps in [99.0, 101.0] x [99.0, 101.0]:
|
||||
atan2f(0x1.9332d8p+6, 0x1.8cb6c4p+6) got 0x1.964646p-1
|
||||
want 0x1.964640p-1. */
|
||||
/**
|
||||
* Returns arc tangent of 𝑦/𝑥.
|
||||
*/
|
||||
float
|
||||
atan2f (float y, float x)
|
||||
atan2f(float y, float x)
|
||||
{
|
||||
uint32_t ix = asuint (x);
|
||||
uint32_t iy = asuint (y);
|
||||
float z;
|
||||
int32_t k,m,hx,hy,ix,iy;
|
||||
|
||||
uint32_t sign_x = ix & SignMask;
|
||||
uint32_t sign_y = iy & SignMask;
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
ix = hx&0x7fffffff;
|
||||
GET_FLOAT_WORD(hy,y);
|
||||
iy = hy&0x7fffffff;
|
||||
if((ix>0x7f800000)||
|
||||
(iy>0x7f800000)) /* x or y is NaN */
|
||||
return nan_mix(x, y);
|
||||
if(hx==0x3f800000) return atanf(y); /* x=1.0 */
|
||||
m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
|
||||
|
||||
uint32_t iax = ix & ~SignMask;
|
||||
uint32_t iay = iy & ~SignMask;
|
||||
|
||||
/* x or y is NaN. */
|
||||
if ((iax > 0x7f800000) || (iay > 0x7f800000))
|
||||
return x + y;
|
||||
|
||||
/* m = 2 * sign(x) + sign(y). */
|
||||
uint32_t m = ((iy >> 31) & 1) | ((ix >> 30) & 2);
|
||||
|
||||
/* The following follows glibc ieee754 implementation, except
|
||||
that we do not use +-tiny shifts (non-nearest rounding mode). */
|
||||
|
||||
int32_t exp_diff = biased_exponent (x) - biased_exponent (y);
|
||||
|
||||
/* Special case for (x, y) either on or very close to the x axis. Either y =
|
||||
0, or y is tiny and x is huge (difference in exponents >=
|
||||
POLY_UFLOW_BOUND). In the second case, we only want to use this special
|
||||
case when x is negative (i.e. quadrants 2 or 3). */
|
||||
if (UNLIKELY (iay == 0 || (exp_diff >= POLY_UFLOW_BOUND && m >= 2)))
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
return y; /* atan(+-0,+anything)=+-0. */
|
||||
case 2:
|
||||
return Pi; /* atan(+0,-anything) = pi. */
|
||||
case 3:
|
||||
return -Pi; /* atan(-0,-anything) =-pi. */
|
||||
}
|
||||
}
|
||||
/* Special case for (x, y) either on or very close to the y axis. Either x =
|
||||
0, or x is tiny and y is huge (difference in exponents >=
|
||||
POLY_UFLOW_BOUND). */
|
||||
if (UNLIKELY (iax == 0 || exp_diff <= -POLY_UFLOW_BOUND))
|
||||
return sign_y ? -PiOver2 : PiOver2;
|
||||
|
||||
/* x is INF. */
|
||||
if (iax == 0x7f800000)
|
||||
{
|
||||
if (iay == 0x7f800000)
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
case 0:
|
||||
return PiOver4; /* atan(+INF,+INF). */
|
||||
case 1:
|
||||
return -PiOver4; /* atan(-INF,+INF). */
|
||||
case 2:
|
||||
return 3.0f * PiOver4; /* atan(+INF,-INF). */
|
||||
case 3:
|
||||
return -3.0f * PiOver4; /* atan(-INF,-INF). */
|
||||
/* when y = 0 */
|
||||
if(iy==0) {
|
||||
switch(m) {
|
||||
case 0:
|
||||
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
||||
case 2: return pi+tiny;/* atan(+0,-anything) = pi */
|
||||
case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m)
|
||||
{
|
||||
case 0:
|
||||
return 0.0f; /* atan(+...,+INF). */
|
||||
case 1:
|
||||
return -0.0f; /* atan(-...,+INF). */
|
||||
case 2:
|
||||
return Pi; /* atan(+...,-INF). */
|
||||
case 3:
|
||||
return -Pi; /* atan(-...,-INF). */
|
||||
/* when x = 0 */
|
||||
if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
||||
|
||||
/* when x is INF */
|
||||
if(ix==0x7f800000) {
|
||||
if(iy==0x7f800000) {
|
||||
switch(m) {
|
||||
case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
|
||||
case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
|
||||
case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
|
||||
case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
|
||||
}
|
||||
} else {
|
||||
switch(m) {
|
||||
case 0: return zero ; /* atan(+...,+INF) */
|
||||
case 1: return -zero ; /* atan(-...,+INF) */
|
||||
case 2: return pi+tiny ; /* atan(+...,-INF) */
|
||||
case 3: return -pi-tiny ; /* atan(-...,-INF) */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* y is INF. */
|
||||
if (iay == 0x7f800000)
|
||||
return sign_y ? -PiOver2 : PiOver2;
|
||||
/* when y is INF */
|
||||
if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
||||
|
||||
uint32_t sign_xy = sign_x ^ sign_y;
|
||||
|
||||
float ax = asfloat (iax);
|
||||
float ay = asfloat (iay);
|
||||
|
||||
bool pred_aygtax = (ay > ax);
|
||||
|
||||
/* Set up z for call to atanf. */
|
||||
float n = pred_aygtax ? -ax : ay;
|
||||
float d = pred_aygtax ? ay : ax;
|
||||
float z = n / d;
|
||||
|
||||
float ret;
|
||||
if (UNLIKELY (m < 2 && exp_diff >= POLY_UFLOW_BOUND))
|
||||
{
|
||||
/* If (x, y) is very close to x axis and x is positive, the polynomial
|
||||
will underflow and evaluate to z. */
|
||||
ret = z;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Work out the correct shift. */
|
||||
float shift = sign_x ? -2.0f : 0.0f;
|
||||
shift = pred_aygtax ? shift + 1.0f : shift;
|
||||
shift *= PiOver2;
|
||||
|
||||
ret = eval_poly (z, z, shift);
|
||||
}
|
||||
|
||||
/* Account for the sign of x and y. */
|
||||
return asfloat (asuint (ret) ^ sign_xy);
|
||||
/* compute y/x */
|
||||
k = (iy-ix)>>23;
|
||||
if(k > 26) { /* |y/x| > 2**26 */
|
||||
z=pi_o_2+(float)0.5*pi_lo;
|
||||
m&=1;
|
||||
}
|
||||
else if(k<-26&&hx<0) z=0.0; /* 0 > |y|/x > -2**-26 */
|
||||
else z=atanf(fabsf(y/x)); /* safe to do y/x */
|
||||
switch (m) {
|
||||
case 0: return z ; /* atan(+,+) */
|
||||
case 1: return -z ; /* atan(-,+) */
|
||||
case 2: return pi-(z-pi_lo);/* atan(+,-) */
|
||||
default: /* case 3 */
|
||||
return (z-pi_lo)-pi;/* atan(-,-) */
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_TINYMATH_ATAN_COMMON_H_
|
||||
#define COSMOPOLITAN_LIBC_TINYMATH_ATAN_COMMON_H_
|
||||
#include "libc/tinymath/atan_data.internal.h"
|
||||
#include "libc/tinymath/estrin_wrap.internal.h"
|
||||
#include "libc/tinymath/horner.internal.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/*
|
||||
* Double-precision polynomial evaluation function for scalar and vector atan(x)
|
||||
* and atan2(y,x).
|
||||
*
|
||||
* Copyright (c) 2021-2023, Arm Limited.
|
||||
* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#if WANT_VMATH
|
||||
|
||||
#define DBL_T float64x2_t
|
||||
#define P(i) v_f64 (__atan_poly_data.poly[i])
|
||||
|
||||
#else
|
||||
|
||||
#define DBL_T double
|
||||
#define P(i) __atan_poly_data.poly[i]
|
||||
|
||||
#endif
|
||||
|
||||
/* Polynomial used in fast atan(x) and atan2(y,x) implementations
|
||||
The order 19 polynomial P approximates (atan(sqrt(x))-sqrt(x))/x^(3/2). */
|
||||
static inline DBL_T
|
||||
eval_poly (DBL_T z, DBL_T az, DBL_T shift)
|
||||
{
|
||||
/* Use split Estrin scheme for P(z^2) with deg(P)=19. Use split instead of
|
||||
full scheme to avoid underflow in x^16. */
|
||||
DBL_T z2 = z * z;
|
||||
DBL_T x2 = z2 * z2;
|
||||
DBL_T x4 = x2 * x2;
|
||||
DBL_T x8 = x4 * x4;
|
||||
DBL_T y
|
||||
= FMA (ESTRIN_11_ (z2, x2, x4, x8, P, 8), x8, ESTRIN_7 (z2, x2, x4, P));
|
||||
|
||||
/* Finalize. y = shift + z + z^3 * P(z^2). */
|
||||
y = FMA (y, z2 * az, az);
|
||||
y = y + shift;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
#undef DBL_T
|
||||
#undef FMA
|
||||
#undef P
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_ATAN_COMMON_H_ */
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_TINYMATH_ATAN_DATA_H_
|
||||
#define COSMOPOLITAN_LIBC_TINYMATH_ATAN_DATA_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define ATAN_POLY_NCOEFFS 20
|
||||
extern const struct atan_poly_data {
|
||||
double poly[ATAN_POLY_NCOEFFS];
|
||||
} __atan_poly_data;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_ATAN_DATA_H_ */
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_TINYMATH_ATANF_COMMON_H_
|
||||
#define COSMOPOLITAN_LIBC_TINYMATH_ATANF_COMMON_H_
|
||||
#include "libc/tinymath/atanf_data.internal.h"
|
||||
#include "libc/tinymath/estrin_wrap.internal.h"
|
||||
#include "libc/tinymath/hornerf.internal.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#if WANT_VMATH
|
||||
|
||||
#define FLT_T float32x4_t
|
||||
#define P(i) v_f32 (__atanf_poly_data.poly[i])
|
||||
|
||||
#else
|
||||
|
||||
#define FLT_T float
|
||||
#define P(i) __atanf_poly_data.poly[i]
|
||||
|
||||
#endif
|
||||
|
||||
/* Polynomial used in fast atanf(x) and atan2f(y,x) implementations
|
||||
The order 7 polynomial P approximates (atan(sqrt(x))-sqrt(x))/x^(3/2). */
|
||||
static inline FLT_T
|
||||
eval_poly (FLT_T z, FLT_T az, FLT_T shift)
|
||||
{
|
||||
/* Use 2-level Estrin scheme for P(z^2) with deg(P)=7. However,
|
||||
a standard implementation using z8 creates spurious underflow
|
||||
in the very last fma (when z^8 is small enough).
|
||||
Therefore, we split the last fma into a mul and and an fma.
|
||||
Horner and single-level Estrin have higher errors that exceed
|
||||
threshold. */
|
||||
FLT_T z2 = z * z;
|
||||
FLT_T z4 = z2 * z2;
|
||||
|
||||
/* Then assemble polynomial. */
|
||||
FLT_T y = FMA (z4, z4 * ESTRIN_3_ (z2, z4, P, 4), ESTRIN_3 (z2, z4, P));
|
||||
|
||||
/* Finalize:
|
||||
y = shift + z * P(z^2). */
|
||||
return FMA (y, z2 * az, az) + shift;
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_ATANF_COMMON_H_ */
|
||||
@@ -1,11 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_TINYMATH_ATANF_DATA_H_
|
||||
#define COSMOPOLITAN_LIBC_TINYMATH_ATANF_DATA_H_
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define ATANF_POLY_NCOEFFS 8
|
||||
extern const struct atanf_poly_data {
|
||||
float poly[ATANF_POLY_NCOEFFS];
|
||||
} __atanf_poly_data;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_LIBC_TINYMATH_ATANF_DATA_H_ */
|
||||
@@ -1,41 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
// FIXME: Hull et al. "Implementing the complex arcsine and arccosine functions using exception handling" 1997
|
||||
|
||||
/* acos(z) = pi/2 - asin(z) */
|
||||
|
||||
double complex cacos(double complex z)
|
||||
{
|
||||
z = casin(z);
|
||||
return CMPLX(M_PI_2 - creal(z), -cimag(z));
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
// FIXME
|
||||
|
||||
float complex cacosf(float complex z)
|
||||
{
|
||||
z = casinf(z);
|
||||
return CMPLXF((float)M_PI_2 - crealf(z), -cimagf(z));
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
/* acosh(z) = i acos(z) */
|
||||
double complex cacosh(double complex z)
|
||||
{
|
||||
int zineg = signbit(cimag(z));
|
||||
z = cacos(z);
|
||||
if (zineg) return CMPLX(cimag(z), -creal(z));
|
||||
else return CMPLX(-cimag(z), creal(z));
|
||||
}
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
__weak_reference(cacosh, cacoshl);
|
||||
#endif
|
||||
@@ -1,39 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
float complex cacoshf(float complex z)
|
||||
{
|
||||
int zineg = signbit(cimagf(z));
|
||||
z = cacosf(z);
|
||||
if (zineg) return CMPLXF(cimagf(z), -crealf(z));
|
||||
else return CMPLXF(-cimagf(z), crealf(z));
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
// FIXME
|
||||
|
||||
float complex casinf(float complex z)
|
||||
{
|
||||
float complex w;
|
||||
float x, y;
|
||||
|
||||
x = crealf(z);
|
||||
y = cimagf(z);
|
||||
w = CMPLXF(1.0 - (x - y)*(x + y), -2.0*x*y);
|
||||
float complex r = clogf(CMPLXF(-y, x) + csqrtf(w));
|
||||
return CMPLXF(cimagf(r), -crealf(r));
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
/* asinh(z) = -i asin(i z) */
|
||||
|
||||
double complex casinh(double complex z)
|
||||
{
|
||||
z = casin(CMPLX(-cimag(z), creal(z)));
|
||||
return CMPLX(cimag(z), -creal(z));
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
float complex casinhf(float complex z)
|
||||
{
|
||||
z = casinf(CMPLXF(-cimagf(z), crealf(z)));
|
||||
return CMPLXF(cimagf(z), -crealf(z));
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
__static_yoink("openbsd_libm_notice");
|
||||
|
||||
/* origin: OpenBSD /usr/src/lib/libm/src/s_catan.c */
|
||||
/*
|
||||
* Copyright (c) 2008 Stephen L. Moshier <[email protected]>
|
||||
*
|
||||
* Permission to use, copy, modify, and 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.
|
||||
*/
|
||||
/*
|
||||
* Complex circular arc tangent
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* double complex catan();
|
||||
* double complex z, w;
|
||||
*
|
||||
* w = catan (z);
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* If
|
||||
* z = x + iy,
|
||||
*
|
||||
* then
|
||||
* 1 ( 2x )
|
||||
* Re w = - arctan(-----------) + k PI
|
||||
* 2 ( 2 2)
|
||||
* (1 - x - y )
|
||||
*
|
||||
* ( 2 2)
|
||||
* 1 (x + (y+1) )
|
||||
* Im w = - log(------------)
|
||||
* 4 ( 2 2)
|
||||
* (x + (y-1) )
|
||||
*
|
||||
* Where k is an arbitrary integer.
|
||||
*
|
||||
* catan(z) = -i catanh(iz).
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* DEC -10,+10 5900 1.3e-16 7.8e-18
|
||||
* IEEE -10,+10 30000 2.3e-15 8.5e-17
|
||||
* The check catan( ctan(z) ) = z, with |x| and |y| < PI/2,
|
||||
* had peak relative error 1.5e-16, rms relative error
|
||||
* 2.9e-17. See also clog().
|
||||
*/
|
||||
|
||||
#define MAXNUM 1.0e308
|
||||
|
||||
static const double DP1 = 3.14159265160560607910E0;
|
||||
static const double DP2 = 1.98418714791870343106E-9;
|
||||
static const double DP3 = 1.14423774522196636802E-17;
|
||||
|
||||
static double _redupi(double x)
|
||||
{
|
||||
double t;
|
||||
long i;
|
||||
|
||||
t = x/M_PI;
|
||||
if (t >= 0.0)
|
||||
t += 0.5;
|
||||
else
|
||||
t -= 0.5;
|
||||
|
||||
i = t; /* the multiple */
|
||||
t = i;
|
||||
t = ((x - t * DP1) - t * DP2) - t * DP3;
|
||||
return t;
|
||||
}
|
||||
|
||||
double complex catan(double complex z)
|
||||
{
|
||||
double complex w;
|
||||
double a, t, x, x2, y;
|
||||
|
||||
x = creal(z);
|
||||
y = cimag(z);
|
||||
|
||||
x2 = x * x;
|
||||
a = 1.0 - x2 - (y * y);
|
||||
|
||||
t = 0.5 * atan2(2.0 * x, a);
|
||||
w = _redupi(t);
|
||||
|
||||
t = y - 1.0;
|
||||
a = x2 + (t * t);
|
||||
|
||||
t = y + 1.0;
|
||||
a = (x2 + t * t)/a;
|
||||
w = CMPLX(w, 0.25 * log(a));
|
||||
return w;
|
||||
}
|
||||
|
||||
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
|
||||
__weak_reference(catan, catanl);
|
||||
#endif
|
||||
@@ -1,135 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
__static_yoink("openbsd_libm_notice");
|
||||
|
||||
/* origin: OpenBSD /usr/src/lib/libm/src/s_catanf.c */
|
||||
/*
|
||||
* Copyright (c) 2008 Stephen L. Moshier <[email protected]>
|
||||
*
|
||||
* Permission to use, copy, modify, and 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.
|
||||
*/
|
||||
/*
|
||||
* Complex circular arc tangent
|
||||
*
|
||||
*
|
||||
* SYNOPSIS:
|
||||
*
|
||||
* float complex catanf();
|
||||
* float complex z, w;
|
||||
*
|
||||
* w = catanf( z );
|
||||
*
|
||||
*
|
||||
* DESCRIPTION:
|
||||
*
|
||||
* If
|
||||
* z = x + iy,
|
||||
*
|
||||
* then
|
||||
* 1 ( 2x )
|
||||
* Re w = - arctan(-----------) + k PI
|
||||
* 2 ( 2 2)
|
||||
* (1 - x - y )
|
||||
*
|
||||
* ( 2 2)
|
||||
* 1 (x + (y+1) )
|
||||
* Im w = - log(------------)
|
||||
* 4 ( 2 2)
|
||||
* (x + (y-1) )
|
||||
*
|
||||
* Where k is an arbitrary integer.
|
||||
*
|
||||
*
|
||||
* ACCURACY:
|
||||
*
|
||||
* Relative error:
|
||||
* arithmetic domain # trials peak rms
|
||||
* IEEE -10,+10 30000 2.3e-6 5.2e-8
|
||||
*/
|
||||
|
||||
|
||||
#define MAXNUMF 1.0e38F
|
||||
|
||||
static const double DP1 = 3.140625;
|
||||
static const double DP2 = 9.67502593994140625E-4;
|
||||
static const double DP3 = 1.509957990978376432E-7;
|
||||
|
||||
static float _redupif(float xx)
|
||||
{
|
||||
float x, t;
|
||||
long i;
|
||||
|
||||
x = xx;
|
||||
t = x/(float)M_PI;
|
||||
if (t >= 0.0f)
|
||||
t += 0.5f;
|
||||
else
|
||||
t -= 0.5f;
|
||||
|
||||
i = t; /* the multiple */
|
||||
t = i;
|
||||
t = ((x - t * DP1) - t * DP2) - t * DP3;
|
||||
return t;
|
||||
}
|
||||
|
||||
float complex catanf(float complex z)
|
||||
{
|
||||
float complex w;
|
||||
float a, t, x, x2, y;
|
||||
|
||||
x = crealf(z);
|
||||
y = cimagf(z);
|
||||
|
||||
x2 = x * x;
|
||||
a = 1.0f - x2 - (y * y);
|
||||
|
||||
t = 0.5f * atan2f(2.0f * x, a);
|
||||
w = _redupif(t);
|
||||
|
||||
t = y - 1.0f;
|
||||
a = x2 + (t * t);
|
||||
|
||||
t = y + 1.0f;
|
||||
a = (x2 + (t * t))/a;
|
||||
w = CMPLXF(w, 0.25f * logf(a));
|
||||
return w;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
/* atanh = -i atan(i z) */
|
||||
|
||||
double complex catanh(double complex z)
|
||||
{
|
||||
z = catan(CMPLX(-cimag(z), creal(z)));
|
||||
return CMPLX(cimag(z), -creal(z));
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ 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: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ 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. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/complex.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/tinymath/complex.internal.h"
|
||||
__static_yoink("musl_libc_notice");
|
||||
|
||||
float complex catanhf(float complex z)
|
||||
{
|
||||
z = catanf(CMPLXF(-cimagf(z), crealf(z)));
|
||||
return CMPLXF(cimagf(z), -crealf(z));
|
||||
}
|
||||
Loaded 100 of 210 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user