From 210187cf77227b087e208dac7e964f1e363c8c1b Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 15 May 2023 16:32:10 -0700 Subject: [PATCH] Perform some code cleanup --- libc/calls/mkntenvblock.c | 1 - libc/fmt/vcscanf.c | 1 - libc/integral/c.inc | 6 + libc/intrin/__cxa_pure_virtual.c | 1 - libc/intrin/bsf.c | 42 + libc/intrin/bsfl.c | 40 - libc/intrin/bsfll.c | 40 - libc/intrin/bsr.c | 42 + libc/intrin/bsrl.c | 40 - libc/intrin/bsrll.c | 40 - libc/intrin/describearchprctlcode.c | 6 +- libc/intrin/describebacktrace.c | 6 +- libc/intrin/describecapability.c | 6 +- libc/intrin/describedirfd.c | 6 +- libc/intrin/describefcntlcmd.c | 6 +- libc/intrin/describeflock.c | 6 +- libc/intrin/describeframe.c | 6 +- libc/intrin/describegidlist.c | 8 +- libc/intrin/describehow.c | 6 +- libc/intrin/describemapping.c | 6 +- libc/intrin/describentconsolemodeinputflags.c | 6 +- .../intrin/describentconsolemodeoutputflags.c | 6 +- libc/intrin/describentfileflagattr.c | 6 +- libc/intrin/describentfilemapflags.c | 6 +- libc/intrin/describentfileshareflags.c | 6 +- libc/intrin/describentfiletypeflags.c | 6 +- libc/intrin/describentlockfileflags.c | 6 +- libc/intrin/describentmovfileinpflags.c | 6 +- libc/intrin/describentpageflags.c | 6 +- libc/intrin/describentpipeopenflags.c | 6 +- libc/intrin/describentprocaccessflags.c | 6 +- libc/intrin/describentstartflags.c | 6 +- libc/intrin/describentsymlinkflags.c | 6 +- libc/intrin/describepersonalityflags.c | 6 +- libc/intrin/describepollflags.c | 6 +- libc/intrin/describeprotflags.c | 6 +- libc/intrin/describeptrace.c | 6 +- libc/intrin/describeptraceevent.c | 6 +- libc/intrin/describeremapflags.c | 6 +- libc/intrin/describerlimitname.c | 6 +- libc/intrin/describeschedpolicy.c | 6 +- libc/intrin/describesicode.c | 6 +- libc/intrin/describesigaction.c | 7 +- libc/intrin/describesigaltstack.c | 8 +- libc/intrin/describesocketfamily.c | 6 +- libc/intrin/describesocketprotocol.c | 6 +- libc/intrin/describesockettype.c | 6 +- libc/intrin/describesocklevel.c | 6 +- libc/intrin/describesockoptname.c | 6 +- libc/intrin/describestatfs.c | 6 +- libc/intrin/describestdiostate.c | 6 +- libc/intrin/describestringlist.c | 6 +- libc/intrin/describetimespec.c | 7 +- libc/intrin/fds_lock.c | 12 +- libc/intrin/ffs.c | 1 - libc/intrin/fmax.c | 4 + libc/intrin/fmaxl.c | 3 + libc/intrin/ftrapv.c | 1 - libc/intrin/intrin.h | 0 libc/intrin/ldexp.c | 68 - libc/intrin/ldexpf.c | 66 - libc/intrin/ldexpl.c | 26 - libc/intrin/memmove.c | 3 +- libc/intrin/mmi_lock.c | 12 +- libc/intrin/onarithmeticoverflow.c | 1 - libc/intrin/pthread_spin_destroy.c | 6 +- libc/intrin/pthread_spin_trylock.c | 6 +- libc/intrin/pthread_spin_unlock.c | 6 +- libc/intrin/scalblnl.c | 7 +- libc/intrin/scalbn.c | 82 +- libc/intrin/scalbnf.c | 76 +- libc/intrin/scalbnl.c | 11 +- libc/intrin/sched_yield.S | 18 +- libc/intrin/strlen.c | 6 +- libc/intrin/syscall.S | 14 +- libc/intrin/tpenc2.c | 1 - libc/isystem/thread.h | 0 libc/nexgen32e/gc.S | 24 +- libc/str/oldutf16.internal.h | 0 libc/testlib/benchrunner.c | 1 - libc/testlib/formatint.c | 2 +- libc/tinymath/asin.c | 6 +- libc/tinymath/asinl.c | 24 +- libc/tinymath/atan.c | 4 + libc/tinymath/atan2.c | 4 + libc/tinymath/atan2l.c | 11 +- libc/tinymath/atanh.c | 6 +- libc/tinymath/atanhl.c | 14 +- libc/tinymath/atanl.c | 12 +- libc/tinymath/cabs.c | 4 + libc/tinymath/cabsl.c | 7 +- libc/tinymath/carg.c | 4 + libc/tinymath/cargl.c | 7 +- libc/tinymath/casin.c | 8 +- libc/tinymath/casinl.c | 13 +- libc/tinymath/catan.c | 2 +- libc/tinymath/ccos.c | 55 +- libc/tinymath/cos.c | 6 +- libc/tinymath/cosh.c | 2 +- libc/tinymath/cosl.c | 9 +- libc/tinymath/drem.c | 23 - libc/tinymath/dremf.c | 23 - libc/tinymath/dreml.c | 23 - libc/tinymath/exp.c | 4 + libc/tinymath/exp10.c | 8 + libc/tinymath/exp10f.c | 5 + libc/tinymath/exp10l.c | 17 +- libc/tinymath/exp2.c | 4 + libc/tinymath/exp2l.c | 19 +- libc/tinymath/expl.c | 75 +- libc/tinymath/expm1.c | 4 + libc/tinymath/expm1f.c | 2 +- libc/tinymath/expm1l.c | 20 +- libc/tinymath/expo2.c | 1 + libc/tinymath/fabs.c | 4 + libc/tinymath/fabsl.c | 9 +- libc/tinymath/fdim.c | 4 + libc/tinymath/fdiml.c | 7 +- libc/tinymath/floor.c | 4 + libc/tinymath/floorl.c | 12 +- libc/tinymath/fmin.c | 4 + libc/tinymath/fminl.c | 3 + libc/tinymath/freebsd.internal.h | 207 +-- libc/tinymath/frexp.c | 6 +- libc/tinymath/frexpl.c | 3 + libc/tinymath/hypot.c | 4 + libc/tinymath/hypotl.c | 15 +- libc/tinymath/kexpl.c | 252 ++++ libc/tinymath/lgammaf_r.c | 2 +- libc/tinymath/log.c | 4 + libc/tinymath/log10.c | 4 + libc/tinymath/log10l.c | 16 +- libc/tinymath/log1p.c | 4 + libc/tinymath/log1pl.c | 18 +- libc/tinymath/log2.c | 6 +- libc/tinymath/log2l.c | 16 +- libc/tinymath/logl.c | 16 +- libc/tinymath/loglq.c | 20 +- libc/tinymath/lrint.c | 4 + libc/tinymath/lrintl.c | 10 +- libc/tinymath/lround.c | 4 + libc/tinymath/lroundl.c | 3 + libc/tinymath/magicu.h | 2 +- libc/tinymath/nearbyint.c | 4 + libc/tinymath/nearbyintl.c | 7 +- libc/tinymath/nextafter.c | 4 + libc/tinymath/nextafterl.c | 9 +- libc/tinymath/nexttowardl.c | 50 +- libc/tinymath/pow.c | 5 + libc/tinymath/pow10.c | 23 - libc/tinymath/pow10f.c | 23 - libc/tinymath/pow10l.c | 23 - libc/tinymath/powf.c | 2 + libc/tinymath/powfin.c | 30 - libc/tinymath/powl.c | 20 +- libc/tinymath/remainder.c | 8 + libc/tinymath/remainderf.c | 50 + libc/tinymath/remainderl.c | 10 +- libc/tinymath/remquo.c | 4 + libc/tinymath/remquol.c | 12 +- libc/tinymath/rint.c | 4 + libc/tinymath/rintl.c | 12 +- libc/tinymath/round.c | 4 + libc/tinymath/roundl.c | 15 +- libc/tinymath/scalb.c | 22 +- libc/tinymath/scalbln.c | 6 +- libc/tinymath/scalblnf.c | 2 +- libc/tinymath/significand.c | 7 + libc/tinymath/significandf.c | 3 + libc/tinymath/significandl.c | 6 + libc/tinymath/sin.c | 4 + libc/tinymath/sincos.c | 4 + libc/tinymath/sincosl.c | 16 +- libc/tinymath/sinl.c | 9 +- libc/tinymath/sqrt.c | 4 + libc/tinymath/sqrtl.c | 12 +- libc/tinymath/tan.c | 4 + libc/tinymath/tanl.c | 13 +- libc/tinymath/tgamma.c | 5 +- .../tinymath.h} | 0 libc/tinymath/trunc.c | 4 + libc/tinymath/truncl.c | 12 +- test/libc/bits/test.mk | 0 test/libc/calls/ptrace_test.c | 0 test/libc/calls/sys_ptrace_test.c | 0 test/libc/intrin/pthread_spin_lock_test.c | 1 - test/libc/{str => intrin}/strcmp_test.c | 64 +- test/libc/str/strnlen_test.c | 0 test/libc/tinymath/cosh_test.c | 7 + test/libc/tinymath/exp_test.c | 2 +- test/libc/tinymath/remainder_test.c | 112 ++ test/tool/build/lib/xlaterrno_test.c | 1 - third_party/ggml/common.cc | 2 +- third_party/ggml/fp16.c | 2 +- third_party/ggml/ggml.c | 13 +- third_party/ggml/ggml.mk | 40 +- third_party/ggml/perplexity.cc | 197 +++ third_party/ggml/quantize.cc | 175 +++ third_party/math.h | 0 third_party/nsync/mem/mem.mk | 2 +- third_party/nsync/mem/nsync.mk | 0 tool/build/lib/syscall.c | 3 +- tool/build/lib/xlaterrno.c | 1 - tool/build/lib/xlaterrno.h | 0 tool/emacs/cosmo-c-builtins.el | 1206 +---------------- 205 files changed, 1748 insertions(+), 2595 deletions(-) delete mode 100644 libc/intrin/bsfl.c delete mode 100644 libc/intrin/bsfll.c delete mode 100644 libc/intrin/bsrl.c delete mode 100644 libc/intrin/bsrll.c delete mode 100755 libc/intrin/intrin.h delete mode 100644 libc/intrin/ldexp.c delete mode 100644 libc/intrin/ldexpf.c delete mode 100644 libc/intrin/ldexpl.c delete mode 100644 libc/isystem/thread.h delete mode 100755 libc/str/oldutf16.internal.h delete mode 100644 libc/tinymath/drem.c delete mode 100644 libc/tinymath/dremf.c delete mode 100644 libc/tinymath/dreml.c create mode 100644 libc/tinymath/kexpl.c delete mode 100644 libc/tinymath/pow10.c delete mode 100644 libc/tinymath/pow10f.c delete mode 100644 libc/tinymath/pow10l.c delete mode 100644 libc/tinymath/powfin.c rename libc/{calls/kntprioritycombos.internal.h => tinymath/tinymath.h} (100%) delete mode 100755 test/libc/bits/test.mk delete mode 100644 test/libc/calls/ptrace_test.c delete mode 100644 test/libc/calls/sys_ptrace_test.c rename test/libc/{str => intrin}/strcmp_test.c (86%) delete mode 100644 test/libc/str/strnlen_test.c create mode 100644 test/libc/tinymath/remainder_test.c create mode 100644 third_party/ggml/perplexity.cc create mode 100644 third_party/ggml/quantize.cc delete mode 100755 third_party/math.h delete mode 100755 third_party/nsync/mem/nsync.mk delete mode 100755 tool/build/lib/xlaterrno.h diff --git a/libc/calls/mkntenvblock.c b/libc/calls/mkntenvblock.c index f87a9225a..e3fbefa9d 100644 --- a/libc/calls/mkntenvblock.c +++ b/libc/calls/mkntenvblock.c @@ -23,7 +23,6 @@ #include "libc/mem/alloca.h" #include "libc/mem/arraylist2.internal.h" #include "libc/mem/mem.h" -#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" #include "libc/str/thompike.h" #include "libc/str/utf16.h" diff --git a/libc/fmt/vcscanf.c b/libc/fmt/vcscanf.c index 3002113b9..8f7c479e9 100644 --- a/libc/fmt/vcscanf.c +++ b/libc/fmt/vcscanf.c @@ -21,7 +21,6 @@ #include "libc/intrin/weaken.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" -#include "libc/str/oldutf16.internal.h" #include "libc/str/str.h" #include "libc/str/tab.internal.h" #include "libc/str/tpdecodecb.internal.h" diff --git a/libc/integral/c.inc b/libc/integral/c.inc index 4f7fae80e..bb962797c 100644 --- a/libc/integral/c.inc +++ b/libc/integral/c.inc @@ -848,5 +848,11 @@ typedef struct { #define STATIC_YOINK_SOURCE(PATH) #endif +#define __strong_reference(sym, aliassym) \ + extern typeof(sym) aliassym __attribute__((__alias__(#sym))) +#define __weak_reference(sym, alias) \ + asm(".weak\t" #alias "\n\t" \ + ".equ\t" #alias ", " #sym) + #define MACHINE_CODE_ANALYSIS_BEGIN_ #define MACHINE_CODE_ANALYSIS_END_ diff --git a/libc/intrin/__cxa_pure_virtual.c b/libc/intrin/__cxa_pure_virtual.c index 4edfd5f06..c084bbbaa 100644 --- a/libc/intrin/__cxa_pure_virtual.c +++ b/libc/intrin/__cxa_pure_virtual.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/intrin.h" #include "libc/intrin/kprintf.h" void __cxa_pure_virtual(void) { diff --git a/libc/intrin/bsf.c b/libc/intrin/bsf.c index 983882c8e..bc52e568e 100644 --- a/libc/intrin/bsf.c +++ b/libc/intrin/bsf.c @@ -38,3 +38,45 @@ int(_bsf)(int x) { return _bsf(x); } + +/** + * Returns position of first bit set. + * + * ctz(𝑥) 31^clz(𝑥) clz(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) + * 0x00000000 wut 32 0 wut 32 + * 0x00000001 0 0 1 0 31 + * 0x80000001 0 0 1 31 0 + * 0x80000000 31 31 32 31 0 + * 0x00000010 4 4 5 4 27 + * 0x08000010 4 4 5 27 4 + * 0x08000000 27 27 28 27 4 + * 0xffffffff 0 0 1 31 0 + * + * @param 𝑥 is a 64-bit integer + * @return number in range 0..63 or undefined if 𝑥 is 0 + */ +int(_bsfl)(long x) { + return _bsfl(x); +} + +/** + * Returns position of first bit set. + * + * ctz(𝑥) 31^clz(𝑥) clz(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) + * 0x00000000 wut 32 0 wut 32 + * 0x00000001 0 0 1 0 31 + * 0x80000001 0 0 1 31 0 + * 0x80000000 31 31 32 31 0 + * 0x00000010 4 4 5 4 27 + * 0x08000010 4 4 5 27 4 + * 0x08000000 27 27 28 27 4 + * 0xffffffff 0 0 1 31 0 + * + * @param 𝑥 is a 64-bit integer + * @return number in range 0..63 or undefined if 𝑥 is 0 + */ +int(_bsfll)(long long x) { + return _bsfll(x); +} diff --git a/libc/intrin/bsfl.c b/libc/intrin/bsfl.c deleted file mode 100644 index 6a60f3326..000000000 --- a/libc/intrin/bsfl.c +++ /dev/null @@ -1,40 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bsf.h" - -/** - * Returns position of first bit set. - * - * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) - * 0x00000000 wut 32 0 wut 32 - * 0x00000001 0 0 1 0 31 - * 0x80000001 0 0 1 31 0 - * 0x80000000 31 31 32 31 0 - * 0x00000010 4 4 5 4 27 - * 0x08000010 4 4 5 27 4 - * 0x08000000 27 27 28 27 4 - * 0xffffffff 0 0 1 31 0 - * - * @param 𝑥 is a 64-bit integer - * @return number in range 0..63 or undefined if 𝑥 is 0 - */ -int(_bsfl)(long x) { - return _bsfl(x); -} diff --git a/libc/intrin/bsfll.c b/libc/intrin/bsfll.c deleted file mode 100644 index fa60b9c86..000000000 --- a/libc/intrin/bsfll.c +++ /dev/null @@ -1,40 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bsf.h" - -/** - * Returns position of first bit set. - * - * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) - * 0x00000000 wut 32 0 wut 32 - * 0x00000001 0 0 1 0 31 - * 0x80000001 0 0 1 31 0 - * 0x80000000 31 31 32 31 0 - * 0x00000010 4 4 5 4 27 - * 0x08000010 4 4 5 27 4 - * 0x08000000 27 27 28 27 4 - * 0xffffffff 0 0 1 31 0 - * - * @param 𝑥 is a 64-bit integer - * @return number in range 0..63 or undefined if 𝑥 is 0 - */ -int(_bsfll)(long long x) { - return _bsfll(x); -} diff --git a/libc/intrin/bsr.c b/libc/intrin/bsr.c index babd26925..d8505a3b6 100644 --- a/libc/intrin/bsr.c +++ b/libc/intrin/bsr.c @@ -38,3 +38,45 @@ int(_bsr)(int x) { return _bsr(x); } + +/** + * Returns binary logarithm of 𝑥. + * + * ctz(𝑥) 31^clz(𝑥) clz(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) + * 0x00000000 wut 32 0 wut 32 + * 0x00000001 0 0 1 0 31 + * 0x80000001 0 0 1 31 0 + * 0x80000000 31 31 32 31 0 + * 0x00000010 4 4 5 4 27 + * 0x08000010 4 4 5 27 4 + * 0x08000000 27 27 28 27 4 + * 0xffffffff 0 0 1 31 0 + * + * @param x is a 64-bit integer + * @return number in range 0..63 or undefined if 𝑥 is 0 + */ +int(_bsrl)(long x) { + return _bsrl(x); +} + +/** + * Returns binary logarithm of 𝑥. + * + * ctz(𝑥) 31^clz(𝑥) clz(𝑥) + * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) + * 0x00000000 wut 32 0 wut 32 + * 0x00000001 0 0 1 0 31 + * 0x80000001 0 0 1 31 0 + * 0x80000000 31 31 32 31 0 + * 0x00000010 4 4 5 4 27 + * 0x08000010 4 4 5 27 4 + * 0x08000000 27 27 28 27 4 + * 0xffffffff 0 0 1 31 0 + * + * @param x is a 64-bit integer + * @return number in range 0..63 or undefined if 𝑥 is 0 + */ +int(_bsrll)(long long x) { + return _bsrll(x); +} diff --git a/libc/intrin/bsrl.c b/libc/intrin/bsrl.c deleted file mode 100644 index a21ab29a5..000000000 --- a/libc/intrin/bsrl.c +++ /dev/null @@ -1,40 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bsr.h" - -/** - * Returns binary logarithm of 𝑥. - * - * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) - * 0x00000000 wut 32 0 wut 32 - * 0x00000001 0 0 1 0 31 - * 0x80000001 0 0 1 31 0 - * 0x80000000 31 31 32 31 0 - * 0x00000010 4 4 5 4 27 - * 0x08000010 4 4 5 27 4 - * 0x08000000 27 27 28 27 4 - * 0xffffffff 0 0 1 31 0 - * - * @param x is a 64-bit integer - * @return number in range 0..63 or undefined if 𝑥 is 0 - */ -int(_bsrl)(long x) { - return _bsrl(x); -} diff --git a/libc/intrin/bsrll.c b/libc/intrin/bsrll.c deleted file mode 100644 index ea57f306a..000000000 --- a/libc/intrin/bsrll.c +++ /dev/null @@ -1,40 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bsr.h" - -/** - * Returns binary logarithm of 𝑥. - * - * ctz(𝑥) 31^clz(𝑥) clz(𝑥) - * uint32 𝑥 _bsf(𝑥) tzcnt(𝑥) ffs(𝑥) _bsr(𝑥) lzcnt(𝑥) - * 0x00000000 wut 32 0 wut 32 - * 0x00000001 0 0 1 0 31 - * 0x80000001 0 0 1 31 0 - * 0x80000000 31 31 32 31 0 - * 0x00000010 4 4 5 4 27 - * 0x08000010 4 4 5 27 4 - * 0x08000000 27 27 28 27 4 - * 0xffffffff 0 0 1 31 0 - * - * @param x is a 64-bit integer - * @return number in range 0..63 or undefined if 𝑥 is 0 - */ -int(_bsrll)(long long x) { - return _bsrll(x); -} diff --git a/libc/intrin/describearchprctlcode.c b/libc/intrin/describearchprctlcode.c index e7b19fbe2..6ebcd76a9 100644 --- a/libc/intrin/describearchprctlcode.c +++ b/libc/intrin/describearchprctlcode.c @@ -20,11 +20,7 @@ #include "libc/fmt/itoa.h" #include "libc/intrin/describeflags.internal.h" -#ifdef DescribeArchPrctlCode -#undef DescribeArchPrctlCode -#endif - -const char *DescribeArchPrctlCode(char buf[12], int x) { +const char *(DescribeArchPrctlCode)(char buf[12], int x) { if (x == ARCH_SET_FS) return "ARCH_SET_FS"; if (x == ARCH_GET_FS) return "ARCH_GET_FS"; if (x == ARCH_SET_GS) return "ARCH_SET_GS"; diff --git a/libc/intrin/describebacktrace.c b/libc/intrin/describebacktrace.c index 3edf2ea79..f3b3ee6b1 100644 --- a/libc/intrin/describebacktrace.c +++ b/libc/intrin/describebacktrace.c @@ -20,15 +20,11 @@ #include "libc/intrin/kprintf.h" #include "libc/nexgen32e/stackframe.h" -#ifdef DescribeBacktrace -#undef DescribeBacktrace -#endif - #define N 64 #define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) -const char *DescribeBacktrace(char buf[N], struct StackFrame *fr) { +const char *(DescribeBacktrace)(char buf[N], struct StackFrame *fr) { int o = 0; bool gotsome = false; while (fr) { diff --git a/libc/intrin/describecapability.c b/libc/intrin/describecapability.c index 6bd916aa2..83570565d 100644 --- a/libc/intrin/describecapability.c +++ b/libc/intrin/describecapability.c @@ -22,10 +22,6 @@ #include "libc/str/str.h" #include "libc/sysv/consts/cap.h" -#ifdef DescribeCapability -#undef DescribeCapability -#endif - static const struct thatispacked { unsigned char x; const char *s; @@ -73,7 +69,7 @@ static const struct thatispacked { {CAP_CHECKPOINT_RESTORE, "CHECKPOINT_RESTORE"}, // }; -const char *DescribeCapability(char buf[32], int x) { +const char *(DescribeCapability)(char buf[32], int x) { int i; for (i = 0; i < ARRAYLEN(kCapabilityName); ++i) { if (kCapabilityName[i].x == x) { diff --git a/libc/intrin/describedirfd.c b/libc/intrin/describedirfd.c index e4d251399..04b38c371 100644 --- a/libc/intrin/describedirfd.c +++ b/libc/intrin/describedirfd.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/at.h" -#ifdef DescribeDirfd -#undef DescribeDirfd -#endif - -const char *DescribeDirfd(char buf[12], int dirfd) { +const char *(DescribeDirfd)(char buf[12], int dirfd) { if (dirfd == AT_FDCWD) return "AT_FDCWD"; FormatInt32(buf, dirfd); return buf; diff --git a/libc/intrin/describefcntlcmd.c b/libc/intrin/describefcntlcmd.c index 71f9030b5..da09bae67 100644 --- a/libc/intrin/describefcntlcmd.c +++ b/libc/intrin/describefcntlcmd.c @@ -21,11 +21,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/str/str.h" -#ifdef DescribeFcntlCmd -#undef DescribeFcntlCmd -#endif - -const char *DescribeFcntlCmd(char buf[20], int x) { +const char *(DescribeFcntlCmd)(char buf[20], int x) { const char *s; if (x >= 0 && (s = GetMagnumStr(kFcntlCmds, x))) { buf[0] = 'F'; diff --git a/libc/intrin/describeflock.c b/libc/intrin/describeflock.c index 60fadcb6e..950a68b0b 100644 --- a/libc/intrin/describeflock.c +++ b/libc/intrin/describeflock.c @@ -24,15 +24,11 @@ #include "libc/intrin/kprintf.h" #include "libc/sysv/consts/f.h" -#ifdef DescribeFlock -#undef DescribeFlock -#endif - #define N 300 #define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) -const char *DescribeFlock(char buf[N], int cmd, const struct flock *l) { +const char *(DescribeFlock)(char buf[N], int cmd, const struct flock *l) { int o = 0; if (!l) return "NULL"; diff --git a/libc/intrin/describeframe.c b/libc/intrin/describeframe.c index cedcd0f6c..c8c7fad8a 100644 --- a/libc/intrin/describeframe.c +++ b/libc/intrin/describeframe.c @@ -26,10 +26,6 @@ #include "libc/runtime/runtime.h" #include "libc/runtime/winargs.internal.h" -#ifdef DescribeFrame -#undef DescribeFrame -#endif - #define ADDR(x) ((int64_t)((uint64_t)(x) << 32) >> 16) #define UNSHADOW(x) ((int64_t)(MAX(0, (x)-0x7fff8000)) << 3) #define FRAME(x) ((int)((x) >> 16)) @@ -78,7 +74,7 @@ static const char *GetFrameName(int x) { } } -const char *DescribeFrame(char buf[32], int x) { +const char *(DescribeFrame)(char buf[32], int x) { char *p; if (IsShadowFrame(x)) { ksnprintf(buf, 32, "%s %s %.8x", GetFrameName(x), diff --git a/libc/intrin/describegidlist.c b/libc/intrin/describegidlist.c index 7688b134c..c8408b264 100644 --- a/libc/intrin/describegidlist.c +++ b/libc/intrin/describegidlist.c @@ -24,14 +24,10 @@ #include "libc/macros.internal.h" #include "libc/str/str.h" -#ifdef DescribeGidList -#undef DescribeGidList -#endif - #define N 128 -const char *DescribeGidList(char buf[N], int rc, int size, - const uint32_t list[]) { +const char *(DescribeGidList)(char buf[N], int rc, int size, + const uint32_t list[]) { if ((rc == -1) || (size < 0)) return "n/a"; if (!size) return "{}"; if (!list) return "NULL"; diff --git a/libc/intrin/describehow.c b/libc/intrin/describehow.c index edbf514ec..87777d9d8 100644 --- a/libc/intrin/describehow.c +++ b/libc/intrin/describehow.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/sig.h" -#ifdef DescribeHow -#undef DescribeHow -#endif - -const char *DescribeHow(char buf[12], int how) { +const char *(DescribeHow)(char buf[12], int how) { if (how == SIG_BLOCK) return "SIG_BLOCK"; if (how == SIG_UNBLOCK) return "SIG_UNBLOCK"; if (how == SIG_SETMASK) return "SIG_SETMASK"; diff --git a/libc/intrin/describemapping.c b/libc/intrin/describemapping.c index 6bf1dc8bb..5fa2a206c 100644 --- a/libc/intrin/describemapping.c +++ b/libc/intrin/describemapping.c @@ -21,10 +21,6 @@ #include "libc/sysv/consts/map.h" #include "libc/sysv/consts/prot.h" -#ifdef DescribeMapping -#undef DescribeMapping -#endif - static char DescribeMapType(int flags) { switch (flags & MAP_TYPE) { case MAP_FILE: @@ -48,7 +44,7 @@ char *DescribeProt(char p[4], int prot) { return p; } -const char *DescribeMapping(char p[8], int prot, int flags) { +const char *(DescribeMapping)(char p[8], int prot, int flags) { /* asan runtime depends on this function */ DescribeProt(p, prot); p[3] = DescribeMapType(flags); diff --git a/libc/intrin/describentconsolemodeinputflags.c b/libc/intrin/describentconsolemodeinputflags.c index a22cf1858..8c665030f 100644 --- a/libc/intrin/describentconsolemodeinputflags.c +++ b/libc/intrin/describentconsolemodeinputflags.c @@ -20,10 +20,6 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/consolemodeflags.h" -#ifdef DescribeNtConsoleInFlags -#undef DescribeNtConsoleInFlags -#endif - static const struct DescribeFlags kConsoleModeInputFlags[] = { {kNtEnableProcessedInput, "ProcessedInput"}, // {kNtEnableLineInput, "LineInput"}, // @@ -37,7 +33,7 @@ static const struct DescribeFlags kConsoleModeInputFlags[] = { {kNtEnableVirtualTerminalInput, "VirtualTerminalInput"}, // }; -const char *DescribeNtConsoleInFlags(char buf[256], uint32_t x) { +const char *(DescribeNtConsoleInFlags)(char buf[256], uint32_t x) { return DescribeFlags(buf, 256, kConsoleModeInputFlags, ARRAYLEN(kConsoleModeInputFlags), "kNtEnable", x); } diff --git a/libc/intrin/describentconsolemodeoutputflags.c b/libc/intrin/describentconsolemodeoutputflags.c index a69fb028c..29ef54456 100644 --- a/libc/intrin/describentconsolemodeoutputflags.c +++ b/libc/intrin/describentconsolemodeoutputflags.c @@ -20,10 +20,6 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/consolemodeflags.h" -#ifdef DescribeNtConsoleOutFlags -#undef DescribeNtConsoleOutFlags -#endif - static const struct DescribeFlags kConsoleModeOutputFlags[] = { {kNtEnableProcessedOutput, "EnableProcessedOutput"}, // {kNtEnableWrapAtEolOutput, "EnableWrapAtEolOutput"}, // @@ -32,7 +28,7 @@ static const struct DescribeFlags kConsoleModeOutputFlags[] = { {kNtEnableLvbGridWorldwide, "EnableLvbGridWorldwide"}, // }; -const char *DescribeNtConsoleOutFlags(char buf[128], uint32_t x) { +const char *(DescribeNtConsoleOutFlags)(char buf[128], uint32_t x) { return DescribeFlags(buf, 128, kConsoleModeOutputFlags, ARRAYLEN(kConsoleModeOutputFlags), "kNt", x); } diff --git a/libc/intrin/describentfileflagattr.c b/libc/intrin/describentfileflagattr.c index 2bac07d1c..d86d35ac4 100644 --- a/libc/intrin/describentfileflagattr.c +++ b/libc/intrin/describentfileflagattr.c @@ -21,10 +21,6 @@ #include "libc/nt/enum/fileflagandattributes.h" #include "libc/runtime/runtime.h" -#ifdef DescribeNtFileFlagAttr -#undef DescribeNtFileFlagAttr -#endif - static const struct DescribeFlags kFileFlags[] = { {kNtFileAttributeReadonly, "AttributeReadonly"}, // {kNtFileAttributeHidden, "AttributeHidden"}, // @@ -54,7 +50,7 @@ static const struct DescribeFlags kFileFlags[] = { {kNtFileFlagFirstPipeInstance, "FlagFirstPipeInstance"}, // }; -const char *DescribeNtFileFlagAttr(char buf[256], uint32_t x) { +const char *(DescribeNtFileFlagAttr)(char buf[256], uint32_t x) { if (x == -1u) return "-1u"; return DescribeFlags(buf, 256, kFileFlags, ARRAYLEN(kFileFlags), "kNtFile", x); diff --git a/libc/intrin/describentfilemapflags.c b/libc/intrin/describentfilemapflags.c index 1e133db42..cda7a7f5f 100644 --- a/libc/intrin/describentfilemapflags.c +++ b/libc/intrin/describentfilemapflags.c @@ -20,10 +20,6 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/filemapflags.h" -#ifdef DescribeNtFileMapFlags -#undef DescribeNtFileMapFlags -#endif - static const struct DescribeFlags kFileMapFlags[] = { {kNtFileMapCopy, "Copy"}, // {kNtFileMapWrite, "Write"}, // @@ -34,7 +30,7 @@ static const struct DescribeFlags kFileMapFlags[] = { {kNtFileMapLargePages, "LargePages"}, // }; -const char *DescribeNtFileMapFlags(char buf[64], uint32_t x) { +const char *(DescribeNtFileMapFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kFileMapFlags, ARRAYLEN(kFileMapFlags), "kNtFileMap", x); } diff --git a/libc/intrin/describentfileshareflags.c b/libc/intrin/describentfileshareflags.c index 76c83f0bf..a378bebe8 100644 --- a/libc/intrin/describentfileshareflags.c +++ b/libc/intrin/describentfileshareflags.c @@ -20,17 +20,13 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/filesharemode.h" -#ifdef DescribeNtFileShareFlags -#undef DescribeNtFileShareFlags -#endif - static const struct DescribeFlags kFileShareflags[] = { {kNtFileShareRead, "Read"}, // {kNtFileShareWrite, "Write"}, // {kNtFileShareDelete, "Delete"}, // }; -const char *DescribeNtFileShareFlags(char buf[64], uint32_t x) { +const char *(DescribeNtFileShareFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kFileShareflags, ARRAYLEN(kFileShareflags), "kNtFileShare", x); } diff --git a/libc/intrin/describentfiletypeflags.c b/libc/intrin/describentfiletypeflags.c index 5864f7d33..a9160d08a 100644 --- a/libc/intrin/describentfiletypeflags.c +++ b/libc/intrin/describentfiletypeflags.c @@ -21,10 +21,6 @@ #include "libc/nt/enum/filetype.h" #include "libc/sysv/consts/mremap.h" -#ifdef DescribeNtFiletypeFlags -#undef DescribeNtFiletypeFlags -#endif - static const struct DescribeFlags kFiletypeFlags[] = { {kNtFileTypeRemote, "Remote"}, // {kNtFileTypePipe, "Pipe"}, // order matters @@ -32,7 +28,7 @@ static const struct DescribeFlags kFiletypeFlags[] = { {kNtFileTypeChar, "Char"}, // }; -const char *DescribeNtFiletypeFlags(char buf[64], uint32_t x) { +const char *(DescribeNtFiletypeFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kFiletypeFlags, ARRAYLEN(kFiletypeFlags), "kNtFileType", x); } diff --git a/libc/intrin/describentlockfileflags.c b/libc/intrin/describentlockfileflags.c index 8b8461913..d7afc98c6 100644 --- a/libc/intrin/describentlockfileflags.c +++ b/libc/intrin/describentlockfileflags.c @@ -20,16 +20,12 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/filelockflags.h" -#ifdef DescribeNtLockFileFlags -#undef DescribeNtLockFileFlags -#endif - static const struct DescribeFlags kNtLockFileFlags[] = { {kNtLockfileFailImmediately, "FailImmediately"}, // {kNtLockfileExclusiveLock, "ExclusiveLock"}, // }; -const char *DescribeNtLockFileFlags(char buf[64], uint32_t x) { +const char *(DescribeNtLockFileFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kNtLockFileFlags, ARRAYLEN(kNtLockFileFlags), "kNtLockfile", x); } diff --git a/libc/intrin/describentmovfileinpflags.c b/libc/intrin/describentmovfileinpflags.c index 8d0ad601b..ea3853423 100644 --- a/libc/intrin/describentmovfileinpflags.c +++ b/libc/intrin/describentmovfileinpflags.c @@ -20,10 +20,6 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/movefileexflags.h" -#ifdef DescribeNtMovFileInpFlags -#undef DescribeNtMovFileInpFlags -#endif - static const struct DescribeFlags kMoveFileInputFlags[] = { {kNtMovefileReplaceExisting, "ReplaceExisting"}, // {kNtMovefileCopyAllowed, "CopyAllowed"}, // @@ -33,7 +29,7 @@ static const struct DescribeFlags kMoveFileInputFlags[] = { {kNtMovefileFailIfNotTrackable, "FailIfNotTrackable"}, // }; -const char *DescribeNtMovFileInpFlags(char buf[256], uint32_t x) { +const char *(DescribeNtMovFileInpFlags)(char buf[256], uint32_t x) { return DescribeFlags(buf, 256, kMoveFileInputFlags, ARRAYLEN(kMoveFileInputFlags), "kNtMovefile", x); } diff --git a/libc/intrin/describentpageflags.c b/libc/intrin/describentpageflags.c index 8ca82abb6..3333808f9 100644 --- a/libc/intrin/describentpageflags.c +++ b/libc/intrin/describentpageflags.c @@ -20,10 +20,6 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/pageflags.h" -#ifdef DescribeNtPageFlags -#undef DescribeNtPageFlags -#endif - static const struct DescribeFlags kPageFlags[] = { {kNtPageNoaccess, "PageNoaccess"}, // {kNtPageReadonly, "PageReadonly"}, // @@ -45,6 +41,6 @@ static const struct DescribeFlags kPageFlags[] = { {kNtSecWritecombine, "SecWritecombine"}, // }; -const char *DescribeNtPageFlags(char buf[64], uint32_t x) { +const char *(DescribeNtPageFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kPageFlags, ARRAYLEN(kPageFlags), "kNt", x); } diff --git a/libc/intrin/describentpipeopenflags.c b/libc/intrin/describentpipeopenflags.c index 10b415dc9..ebb81c990 100644 --- a/libc/intrin/describentpipeopenflags.c +++ b/libc/intrin/describentpipeopenflags.c @@ -21,17 +21,13 @@ #include "libc/nt/enum/filemapflags.h" #include "libc/nt/ipc.h" -#ifdef DescribeNtPipeOpenFlags -#undef DescribeNtPipeOpenFlags -#endif - static const struct DescribeFlags kPipeOpenFlags[] = { {kNtPipeAccessDuplex, "Duplex"}, // 0x00000003 {kNtPipeAccessOutbound, "Outbound"}, // 0x00000002 {kNtPipeAccessInbound, "Inbound"}, // 0x00000001 }; -const char *DescribeNtPipeOpenFlags(char buf[64], uint32_t x) { +const char *(DescribeNtPipeOpenFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kPipeOpenFlags, ARRAYLEN(kPipeOpenFlags), "kNtPipeAccess", x); } diff --git a/libc/intrin/describentprocaccessflags.c b/libc/intrin/describentprocaccessflags.c index 7abb0023d..4d2db8d9a 100644 --- a/libc/intrin/describentprocaccessflags.c +++ b/libc/intrin/describentprocaccessflags.c @@ -20,10 +20,6 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/processaccess.h" -#ifdef DescribeNtProcAccessFlags -#undef DescribeNtProcAccessFlags -#endif - static const struct DescribeFlags kProcessAccessflags[] = { {kNtProcessAllAccess, "AllAccess"}, // {kNtProcessCreateProcess, "CreateProcess"}, // @@ -41,7 +37,7 @@ static const struct DescribeFlags kProcessAccessflags[] = { {kNtProcessSynchronize, "Synchronize"}, // }; -const char *DescribeNtProcAccessFlags(char buf[256], uint32_t x) { +const char *(DescribeNtProcAccessFlags)(char buf[256], uint32_t x) { return DescribeFlags(buf, 256, kProcessAccessflags, ARRAYLEN(kProcessAccessflags), "kNtProcess", x); } diff --git a/libc/intrin/describentstartflags.c b/libc/intrin/describentstartflags.c index 0d5e0b8f1..523f4fee2 100644 --- a/libc/intrin/describentstartflags.c +++ b/libc/intrin/describentstartflags.c @@ -21,10 +21,6 @@ #include "libc/nt/enum/startf.h" #include "libc/sysv/consts/prot.h" -#ifdef DescribeNtStartFlags -#undef DescribeNtStartFlags -#endif - static const struct DescribeFlags kNtStartFlags[] = { {kNtStartfUseshowwindow, "Useshowwindow"}, // {kNtStartfUsesize, "Usesize"}, // @@ -42,7 +38,7 @@ static const struct DescribeFlags kNtStartFlags[] = { {kNtStartfUntrustedsource, "Untrustedsource"}, // }; -const char *DescribeNtStartFlags(char buf[128], uint32_t x) { +const char *(DescribeNtStartFlags)(char buf[128], uint32_t x) { return DescribeFlags(buf, 128, kNtStartFlags, ARRAYLEN(kNtStartFlags), "kNtStartf", x); } diff --git a/libc/intrin/describentsymlinkflags.c b/libc/intrin/describentsymlinkflags.c index 330de10f1..f0ed54b47 100644 --- a/libc/intrin/describentsymlinkflags.c +++ b/libc/intrin/describentsymlinkflags.c @@ -20,16 +20,12 @@ #include "libc/macros.internal.h" #include "libc/nt/enum/symboliclink.h" -#ifdef DescribeNtSymlinkFlags -#undef DescribeNtSymlinkFlags -#endif - static const struct DescribeFlags kSymbolicLinkflags[] = { {kNtSymbolicLinkFlagDirectory, "Directory"}, // {kNtSymbolicLinkFlagAllowUnprivilegedCreate, "AllowUnprivilegedCreate"}, // }; -const char *DescribeNtSymlinkFlags(char buf[64], uint32_t x) { +const char *(DescribeNtSymlinkFlags)(char buf[64], uint32_t x) { return DescribeFlags(buf, 64, kSymbolicLinkflags, ARRAYLEN(kSymbolicLinkflags), "kNtSymbolicLinkFlag", x); } diff --git a/libc/intrin/describepersonalityflags.c b/libc/intrin/describepersonalityflags.c index 7e6cb39bf..6e3a859f2 100644 --- a/libc/intrin/describepersonalityflags.c +++ b/libc/intrin/describepersonalityflags.c @@ -22,10 +22,6 @@ #include "libc/nt/enum/filesharemode.h" #include "libc/sysv/consts/personality.h" -#ifdef DescribePersonalityFlags -#undef DescribePersonalityFlags -#endif - static const struct DescribeFlags kPersonalityFlags[] = { {ADDR_COMPAT_LAYOUT, "ADDR_COMPAT_LAYOUT"}, // {READ_IMPLIES_EXEC, "READ_IMPLIES_EXEC"}, // @@ -40,7 +36,7 @@ static const struct DescribeFlags kPersonalityFlags[] = { {UNAME26, "UNAME26"}, // }; -const char *DescribePersonalityFlags(char buf[128], int x) { +const char *(DescribePersonalityFlags)(char buf[128], int x) { return DescribeFlags(buf, 128, kPersonalityFlags, ARRAYLEN(kPersonalityFlags), "", x); } diff --git a/libc/intrin/describepollflags.c b/libc/intrin/describepollflags.c index df9514541..fdff13f6d 100644 --- a/libc/intrin/describepollflags.c +++ b/libc/intrin/describepollflags.c @@ -21,11 +21,7 @@ #include "libc/nt/enum/filemapflags.h" #include "libc/sysv/consts/poll.h" -#ifdef DescribePollFlags -#undef DescribePollFlags -#endif - -const char *DescribePollFlags(char buf[64], int x) { +const char *(DescribePollFlags)(char buf[64], int x) { const struct DescribeFlags kPollFlags[] = { {POLLIN, "IN"}, // order matters {POLLOUT, "OUT"}, // order matters diff --git a/libc/intrin/describeprotflags.c b/libc/intrin/describeprotflags.c index 5e62c4c95..a2cca029f 100644 --- a/libc/intrin/describeprotflags.c +++ b/libc/intrin/describeprotflags.c @@ -20,16 +20,12 @@ #include "libc/macros.internal.h" #include "libc/sysv/consts/prot.h" -#ifdef DescribeProtFlags -#undef DescribeProtFlags -#endif - static const struct DescribeFlags kProtFlags[] = { {PROT_READ, "READ"}, // {PROT_WRITE, "WRITE"}, // {PROT_EXEC, "EXEC"}, // }; -const char *DescribeProtFlags(char buf[48], int x) { +const char *(DescribeProtFlags)(char buf[48], int x) { return DescribeFlags(buf, 48, kProtFlags, ARRAYLEN(kProtFlags), "PROT_", x); } diff --git a/libc/intrin/describeptrace.c b/libc/intrin/describeptrace.c index bcf72221f..f266599fe 100644 --- a/libc/intrin/describeptrace.c +++ b/libc/intrin/describeptrace.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/ptrace.h" -#ifdef DescribePtrace -#undef DescribePtrace -#endif - -const char *DescribePtrace(char buf[12], int x) { +const char *(DescribePtrace)(char buf[12], int x) { if (x == -1) return "-1"; if (x == PTRACE_TRACEME) return "PTRACE_TRACEME"; if (x == PTRACE_PEEKDATA) return "PTRACE_PEEKDATA"; diff --git a/libc/intrin/describeptraceevent.c b/libc/intrin/describeptraceevent.c index a9dd358fd..b9b003f03 100644 --- a/libc/intrin/describeptraceevent.c +++ b/libc/intrin/describeptraceevent.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/ptrace.h" -#ifdef DescribePtraceEvent -#undef DescribePtraceEvent -#endif - -const char *DescribePtraceEvent(char buf[32], int x) { +const char *(DescribePtraceEvent)(char buf[32], int x) { if (x == PTRACE_EVENT_FORK) return "PTRACE_EVENT_FORK"; if (x == PTRACE_EVENT_VFORK) return "PTRACE_EVENT_VFORK"; if (x == PTRACE_EVENT_CLONE) return "PTRACE_EVENT_CLONE"; diff --git a/libc/intrin/describeremapflags.c b/libc/intrin/describeremapflags.c index 1b2256ba5..9c1684a6d 100644 --- a/libc/intrin/describeremapflags.c +++ b/libc/intrin/describeremapflags.c @@ -20,16 +20,12 @@ #include "libc/macros.internal.h" #include "libc/sysv/consts/mremap.h" -#ifdef DescribeRemapFlags -#undef DescribeRemapFlags -#endif - static const struct DescribeFlags kRemapFlags[] = { {MREMAP_MAYMOVE, "MAYMOVE"}, // {MREMAP_FIXED, "FIXED"}, // }; -const char *DescribeRemapFlags(char buf[48], int x) { +const char *(DescribeRemapFlags)(char buf[48], int x) { return DescribeFlags(buf, 48, kRemapFlags, ARRAYLEN(kRemapFlags), "MREMAP_", x); } diff --git a/libc/intrin/describerlimitname.c b/libc/intrin/describerlimitname.c index 47589bd83..1c2d9e5ac 100644 --- a/libc/intrin/describerlimitname.c +++ b/libc/intrin/describerlimitname.c @@ -19,14 +19,10 @@ #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" -#ifdef DescribeRlimitName -#undef DescribeRlimitName -#endif - /** * Describes setrlimit() / getrlimit() argument. */ -const char *DescribeRlimitName(char buf[20], int x) { +const char *(DescribeRlimitName)(char buf[20], int x) { if (x == 127) return "n/a"; return DescribeMagnum(buf, kRlimitNames, "RLIMIT_", x); } diff --git a/libc/intrin/describeschedpolicy.c b/libc/intrin/describeschedpolicy.c index 71828eff5..f1348a66f 100644 --- a/libc/intrin/describeschedpolicy.c +++ b/libc/intrin/describeschedpolicy.c @@ -23,14 +23,10 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sched.h" -#ifdef DescribeSchedPolicy -#undef DescribeSchedPolicy -#endif - /** * Describes clock_gettime() clock argument. */ -const char *DescribeSchedPolicy(char buf[48], int x) { +const char *(DescribeSchedPolicy)(char buf[48], int x) { char *p = buf; if (x == -1) { goto DoNumber; diff --git a/libc/intrin/describesicode.c b/libc/intrin/describesicode.c index e83654ecb..d7df1ec8e 100644 --- a/libc/intrin/describesicode.c +++ b/libc/intrin/describesicode.c @@ -22,10 +22,6 @@ #include "libc/sysv/consts/sicode.h" #include "libc/sysv/consts/sig.h" -#ifdef DescribeSiCode -#undef DescribeSiCode -#endif - static bool IsSiUser(int si_code) { if (!IsOpenbsd()) { return si_code == SI_USER; @@ -42,7 +38,7 @@ static void NameIt(char p[17], const char *s, int si_code) { /** * Returns symbolic name for siginfo::si_code value. */ -const char *DescribeSiCode(char b[17], int sig, int si_code) { +const char *(DescribeSiCode)(char b[17], int sig, int si_code) { NameIt(b, "SI_", si_code); if (si_code == SI_QUEUE) { strcpy(b + 3, "QUEUE"); /* sent by sigqueue(2) */ diff --git a/libc/intrin/describesigaction.c b/libc/intrin/describesigaction.c index 3b0b77654..d5ca35f19 100644 --- a/libc/intrin/describesigaction.c +++ b/libc/intrin/describesigaction.c @@ -27,10 +27,6 @@ #include "libc/mem/alloca.h" #include "libc/sysv/consts/sa.h" -#ifdef DescribeSigaction -#undef DescribeSigaction -#endif - static const char *DescribeSigHandler(char buf[64], void f(int)) { if (f == SIG_ERR) return "SIG_ERR"; if (f == SIG_DFL) return "SIG_DFL"; @@ -58,7 +54,8 @@ static const char *DescribeSigFlags(char buf[64], int x) { #define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) -const char *DescribeSigaction(char buf[N], int rc, const struct sigaction *sa) { +const char *(DescribeSigaction)(char buf[N], int rc, + const struct sigaction *sa) { int o = 0; char b64[64]; diff --git a/libc/intrin/describesigaltstack.c b/libc/intrin/describesigaltstack.c index ed7d9469a..be8c04026 100644 --- a/libc/intrin/describesigaltstack.c +++ b/libc/intrin/describesigaltstack.c @@ -22,12 +22,8 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" -#ifdef DescribeSigaltstk -#undef DescribeSigaltstk -#endif - -const char *DescribeSigaltstk(char buf[128], int rc, - const struct sigaltstack *ss) { +const char *(DescribeSigaltstk)(char buf[128], int rc, + const struct sigaltstack *ss) { if (rc == -1) return "n/a"; if (!ss) return "NULL"; if ((!IsAsan() && kisdangerous(ss)) || diff --git a/libc/intrin/describesocketfamily.c b/libc/intrin/describesocketfamily.c index a3b1f200a..cf330facc 100644 --- a/libc/intrin/describesocketfamily.c +++ b/libc/intrin/describesocketfamily.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/af.h" -#ifdef DescribeSocketFamily -#undef DescribeSocketFamily -#endif - -const char *DescribeSocketFamily(char buf[12], int family) { +const char *(DescribeSocketFamily)(char buf[12], int family) { if (family == AF_UNIX) return "AF_UNIX"; if (family == AF_INET) return "AF_INET"; if (family == AF_INET6) return "AF_INET6"; diff --git a/libc/intrin/describesocketprotocol.c b/libc/intrin/describesocketprotocol.c index 04c41ccff..a2ae09142 100644 --- a/libc/intrin/describesocketprotocol.c +++ b/libc/intrin/describesocketprotocol.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/ipproto.h" -#ifdef DescribeSocketProtocol -#undef DescribeSocketProtocol -#endif - -const char *DescribeSocketProtocol(char buf[12], int family) { +const char *(DescribeSocketProtocol)(char buf[12], int family) { if (family == IPPROTO_IP) return "IPPROTO_IP"; if (family == IPPROTO_ICMP) return "IPPROTO_ICMP"; if (family == IPPROTO_TCP) return "IPPROTO_TCP"; diff --git a/libc/intrin/describesockettype.c b/libc/intrin/describesockettype.c index 326de5289..0a4a05a0d 100644 --- a/libc/intrin/describesockettype.c +++ b/libc/intrin/describesockettype.c @@ -21,11 +21,7 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sock.h" -#ifdef DescribeSocketType -#undef DescribeSocketType -#endif - -const char *DescribeSocketType(char buf[64], int type) { +const char *(DescribeSocketType)(char buf[64], int type) { int x; char *p; p = buf; diff --git a/libc/intrin/describesocklevel.c b/libc/intrin/describesocklevel.c index 66addf989..c009ae249 100644 --- a/libc/intrin/describesocklevel.c +++ b/libc/intrin/describesocklevel.c @@ -20,14 +20,10 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/sysv/consts/sol.h" -#ifdef DescribeSockLevel -#undef DescribeSockLevel -#endif - /** * Describes setsockopt() level arguments. */ -const char *DescribeSockLevel(char buf[12], int x) { +const char *(DescribeSockLevel)(char buf[12], int x) { if (x == SOL_IP) return "SOL_IP"; if (x == SOL_TCP) return "SOL_TCP"; if (x == SOL_UDP) return "SOL_UDP"; diff --git a/libc/intrin/describesockoptname.c b/libc/intrin/describesockoptname.c index 71446a0e7..8215fb0c3 100644 --- a/libc/intrin/describesockoptname.c +++ b/libc/intrin/describesockoptname.c @@ -22,14 +22,10 @@ #include "libc/str/str.h" #include "libc/sysv/consts/sol.h" -#ifdef DescribeSockOptname -#undef DescribeSockOptname -#endif - /** * Describes setsockopt() optname arguments. */ -const char *DescribeSockOptname(char buf[32], int l, int x) { +const char *(DescribeSockOptname)(char buf[32], int l, int x) { int i; char *s, *p; const struct MagnumStr *ms; diff --git a/libc/intrin/describestatfs.c b/libc/intrin/describestatfs.c index efefe8d8f..aa0d40c97 100644 --- a/libc/intrin/describestatfs.c +++ b/libc/intrin/describestatfs.c @@ -24,15 +24,11 @@ #include "libc/intrin/kprintf.h" #include "libc/sysv/consts/st.h" -#ifdef DescribeStatfs -#undef DescribeStatfs -#endif - #define N 300 #define append(...) i += ksnprintf(buf + i, N - i, __VA_ARGS__) -const char *DescribeStatfs(char buf[N], int rc, const struct statfs *f) { +const char *(DescribeStatfs)(char buf[N], int rc, const struct statfs *f) { int i = 0; char ibuf[21]; int64_t flags; diff --git a/libc/intrin/describestdiostate.c b/libc/intrin/describestdiostate.c index 491ebb532..25013047a 100644 --- a/libc/intrin/describestdiostate.c +++ b/libc/intrin/describestdiostate.c @@ -20,11 +20,7 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/str/str.h" -#ifdef DescribeStdioState -#undef DescribeStdioState -#endif - -const char *DescribeStdioState(char buf[12], int x) { +const char *(DescribeStdioState)(char buf[12], int x) { if (!x) return ""; if (x == -1) return "EOF"; if (x > 0) return _strerrno(x); diff --git a/libc/intrin/describestringlist.c b/libc/intrin/describestringlist.c index c1a9f0fc5..707889e53 100644 --- a/libc/intrin/describestringlist.c +++ b/libc/intrin/describestringlist.c @@ -21,15 +21,11 @@ #include "libc/intrin/describeflags.internal.h" #include "libc/intrin/kprintf.h" -#ifdef DescribeStringList -#undef DescribeStringList -#endif - #define N 300 #define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__) -const char *DescribeStringList(char buf[N], char *const list[]) { +const char *(DescribeStringList)(char buf[N], char *const list[]) { int i, o = 0; if (!list) return "NULL"; diff --git a/libc/intrin/describetimespec.c b/libc/intrin/describetimespec.c index 32cee885e..73cb887d0 100644 --- a/libc/intrin/describetimespec.c +++ b/libc/intrin/describetimespec.c @@ -23,11 +23,8 @@ #include "libc/intrin/kprintf.h" #include "libc/str/str.h" -#ifdef DescribeTimespec -#undef DescribeTimespec -#endif - -const char *DescribeTimespec(char buf[45], int rc, const struct timespec *ts) { +const char *(DescribeTimespec)(char buf[45], int rc, + const struct timespec *ts) { if (rc == -1) return "n/a"; if (!ts) return "NULL"; if ((!IsAsan() && kisdangerous(ts)) || diff --git a/libc/intrin/fds_lock.c b/libc/intrin/fds_lock.c index 580e85a3b..dedbabc99 100644 --- a/libc/intrin/fds_lock.c +++ b/libc/intrin/fds_lock.c @@ -20,19 +20,11 @@ #include "libc/str/str.h" #include "libc/thread/thread.h" -#ifdef __fds_lock -#undef __fds_lock -#endif - -#ifdef __fds_unlock -#undef __fds_unlock -#endif - -void __fds_lock(void) { +void(__fds_lock)(void) { pthread_mutex_lock(&__fds_lock_obj); } -void __fds_unlock(void) { +void(__fds_unlock)(void) { pthread_mutex_unlock(&__fds_lock_obj); } diff --git a/libc/intrin/ffs.c b/libc/intrin/ffs.c index 5e185e62a..e5ecae566 100644 --- a/libc/intrin/ffs.c +++ b/libc/intrin/ffs.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/intrin.h" /** * Finds lowest set bit in word. diff --git a/libc/intrin/fmax.c b/libc/intrin/fmax.c index 872694500..d4ebd3bd1 100644 --- a/libc/intrin/fmax.c +++ b/libc/intrin/fmax.c @@ -33,3 +33,7 @@ double fmax(double x, double y) { } return x < y ? y : x; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(fmax, fmaxl); +#endif diff --git a/libc/intrin/fmaxl.c b/libc/intrin/fmaxl.c index 826805978..ef4ee057a 100644 --- a/libc/intrin/fmaxl.c +++ b/libc/intrin/fmaxl.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Returns maximum of two long doubles. @@ -33,3 +34,5 @@ long double fmaxl(long double x, long double y) { } return x < y ? y : x; } + +#endif /* long double is long */ diff --git a/libc/intrin/ftrapv.c b/libc/intrin/ftrapv.c index 0c637f5ad..8d8c49984 100644 --- a/libc/intrin/ftrapv.c +++ b/libc/intrin/ftrapv.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/intrin.h" #include "libc/limits.h" #include "libc/runtime/internal.h" diff --git a/libc/intrin/intrin.h b/libc/intrin/intrin.h deleted file mode 100755 index e69de29bb..000000000 diff --git a/libc/intrin/ldexp.c b/libc/intrin/ldexp.c deleted file mode 100644 index 6f400a06f..000000000 --- a/libc/intrin/ldexp.c +++ /dev/null @@ -1,68 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ -│vi: set et ft=c ts=8 tw=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/math.h" - -asm(".ident\t\"\\n\\n\ -Musl libc (MIT License)\\n\ -Copyright 2005-2014 Rich Felker, et. al.\""); -asm(".include \"libc/disclaimer.inc\""); -// clang-format off - -/** - * Returns 𝑥 × 2ʸ. - */ -double ldexp(double x, int n) -{ - union {double f; uint64_t i;} u; - double_t y = x; - - if (n > 1023) { - y *= 0x1p1023; - n -= 1023; - if (n > 1023) { - y *= 0x1p1023; - n -= 1023; - if (n > 1023) - n = 1023; - } - } else if (n < -1022) { - /* make sure final n < -53 to avoid double - rounding in the subnormal range */ - y *= 0x1p-1022 * 0x1p53; - n += 1022 - 53; - if (n < -1022) { - y *= 0x1p-1022 * 0x1p53; - n += 1022 - 53; - if (n < -1022) - n = -1022; - } - } - u.i = (uint64_t)(0x3ff+n)<<52; - x = y * u.f; - return x; -} diff --git a/libc/intrin/ldexpf.c b/libc/intrin/ldexpf.c deleted file mode 100644 index f75914489..000000000 --- a/libc/intrin/ldexpf.c +++ /dev/null @@ -1,66 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ -│vi: set et ft=c ts=8 tw=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/math.h" - -asm(".ident\t\"\\n\\n\ -Musl libc (MIT License)\\n\ -Copyright 2005-2014 Rich Felker, et. al.\""); -asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ - -/** - * Returns 𝑥 × 2ʸ. - */ -float ldexpf(float x, int n) -{ - union {float f; uint32_t i;} u; - float_t y = x; - - if (n > 127) { - y *= 0x1p127f; - n -= 127; - if (n > 127) { - y *= 0x1p127f; - n -= 127; - if (n > 127) - n = 127; - } - } else if (n < -126) { - y *= 0x1p-126f * 0x1p24f; - n += 126 - 24; - if (n < -126) { - y *= 0x1p-126f * 0x1p24f; - n += 126 - 24; - if (n < -126) - n = -126; - } - } - u.i = (uint32_t)(0x7f+n)<<23; - x = y * u.f; - return x; -} diff --git a/libc/intrin/ldexpl.c b/libc/intrin/ldexpl.c deleted file mode 100644 index 9ca255762..000000000 --- a/libc/intrin/ldexpl.c +++ /dev/null @@ -1,26 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -/** - * Returns 𝑥 × 2ʸ. - */ -long double ldexpl(long double x, int n) { - return scalbnl(x, n); -} diff --git a/libc/intrin/memmove.c b/libc/intrin/memmove.c index 004ba4abf..357058d38 100644 --- a/libc/intrin/memmove.c +++ b/libc/intrin/memmove.c @@ -342,7 +342,6 @@ void *memmove(void *dst, const void *src, size_t n) { } } -asm("memcpy = memmove\n\t" - ".globl\tmemcpy"); +__strong_reference(memmove, memcpy); #endif /* __aarch64__ */ diff --git a/libc/intrin/mmi_lock.c b/libc/intrin/mmi_lock.c index 5694b2252..c77359bd8 100644 --- a/libc/intrin/mmi_lock.c +++ b/libc/intrin/mmi_lock.c @@ -20,22 +20,14 @@ #include "libc/str/str.h" #include "libc/thread/thread.h" -#ifdef __mmi_lock -#undef __mmi_lock -#endif - -#ifdef __mmi_unlock -#undef __mmi_unlock -#endif - // this lock currently needs to be (1) recursive and (2) not nsync extern pthread_mutex_t __mmi_lock_obj; -void __mmi_lock(void) { +void(__mmi_lock)(void) { pthread_mutex_lock(&__mmi_lock_obj); } -void __mmi_unlock(void) { +void(__mmi_unlock)(void) { pthread_mutex_unlock(&__mmi_lock_obj); } diff --git a/libc/intrin/onarithmeticoverflow.c b/libc/intrin/onarithmeticoverflow.c index 65d572bed..843bd42b4 100644 --- a/libc/intrin/onarithmeticoverflow.c +++ b/libc/intrin/onarithmeticoverflow.c @@ -16,7 +16,6 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/intrin.h" #include "libc/intrin/kprintf.h" /** diff --git a/libc/intrin/pthread_spin_destroy.c b/libc/intrin/pthread_spin_destroy.c index f7b7c51e8..d6583fae7 100644 --- a/libc/intrin/pthread_spin_destroy.c +++ b/libc/intrin/pthread_spin_destroy.c @@ -19,16 +19,12 @@ #include "libc/intrin/atomic.h" #include "libc/thread/thread.h" -#ifdef pthread_spin_destroy -#undef pthread_spin_destroy -#endif - /** * Destroys spin lock. * * @return 0 on success, or errno on error */ -errno_t pthread_spin_destroy(pthread_spinlock_t *spin) { +errno_t(pthread_spin_destroy)(pthread_spinlock_t *spin) { atomic_store_explicit(&spin->_lock, -1, memory_order_relaxed); return 0; } diff --git a/libc/intrin/pthread_spin_trylock.c b/libc/intrin/pthread_spin_trylock.c index 784a9b0bf..34376fabb 100644 --- a/libc/intrin/pthread_spin_trylock.c +++ b/libc/intrin/pthread_spin_trylock.c @@ -21,10 +21,6 @@ #include "libc/intrin/atomic.h" #include "libc/thread/thread.h" -#ifdef pthread_spin_trylock -#undef pthread_spin_trylock -#endif - /** * Acquires spin lock if available. * @@ -34,7 +30,7 @@ * @return 0 on success, or errno on error * @raise EBUSY if lock is already held */ -errno_t pthread_spin_trylock(pthread_spinlock_t *spin) { +errno_t(pthread_spin_trylock)(pthread_spinlock_t *spin) { int x; x = atomic_exchange_explicit(&spin->_lock, 1, memory_order_acquire); if (!x) return 0; diff --git a/libc/intrin/pthread_spin_unlock.c b/libc/intrin/pthread_spin_unlock.c index 8da6c6ebb..d2c6c41d1 100644 --- a/libc/intrin/pthread_spin_unlock.c +++ b/libc/intrin/pthread_spin_unlock.c @@ -20,10 +20,6 @@ #include "libc/intrin/strace.internal.h" #include "libc/thread/thread.h" -#ifdef pthread_spin_unlock -#undef pthread_spin_unlock -#endif - /** * Releases spin lock. * @@ -33,7 +29,7 @@ * @return 0 on success, or errno on error * @see pthread_spin_lock */ -errno_t pthread_spin_unlock(pthread_spinlock_t *spin) { +errno_t(pthread_spin_unlock)(pthread_spinlock_t *spin) { LOCKTRACE("pthread_spin_unlock(%t)", spin); atomic_store_explicit(&spin->_lock, 0, memory_order_release); return 0; diff --git a/libc/intrin/scalblnl.c b/libc/intrin/scalblnl.c index 18052435a..ecf9ee3c1 100644 --- a/libc/intrin/scalblnl.c +++ b/libc/intrin/scalblnl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/limits.h" #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -35,13 +36,11 @@ asm(".include \"libc/disclaimer.inc\""); // clang-format off long double scalblnl(long double x, long n) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return scalbln(x, n); -#else if (n > INT_MAX) n = INT_MAX; else if (n < INT_MIN) n = INT_MIN; return scalbnl(x, n); -#endif } + +#endif /* long double is long */ diff --git a/libc/intrin/scalbn.c b/libc/intrin/scalbn.c index 0e28095d5..1ad7640a1 100644 --- a/libc/intrin/scalbn.c +++ b/libc/intrin/scalbn.c @@ -1,26 +1,74 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2022 Justine Alexandra Roberts Tunney │ +/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ +│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ +╚──────────────────────────────────────────────────────────────────────────────╝ │ │ -│ 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. │ +│ 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. │ │ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +asm(".ident\t\"\\n\\n\ +Musl libc (MIT License)\\n\ +Copyright 2005-2014 Rich Felker, et. al.\""); +asm(".include \"libc/disclaimer.inc\""); +// clang-format off + /** * Returns 𝑥 × 2ʸ. */ -double scalbn(double x, int n) { - return ldexp(x, n); +double scalbn(double x, int n) +{ + union {double f; uint64_t i;} u; + double_t y = x; + + if (n > 1023) { + y *= 0x1p1023; + n -= 1023; + if (n > 1023) { + y *= 0x1p1023; + n -= 1023; + if (n > 1023) + n = 1023; + } + } else if (n < -1022) { + /* make sure final n < -53 to avoid double + rounding in the subnormal range */ + y *= 0x1p-1022 * 0x1p53; + n += 1022 - 53; + if (n < -1022) { + y *= 0x1p-1022 * 0x1p53; + n += 1022 - 53; + if (n < -1022) + n = -1022; + } + } + u.i = (uint64_t)(0x3ff+n)<<52; + x = y * u.f; + return x; } + +__strong_reference(scalbn, ldexp); +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(scalbn, ldexpl); +__strong_reference(scalbn, scalbnl); +#endif diff --git a/libc/intrin/scalbnf.c b/libc/intrin/scalbnf.c index 86e627507..a78e512c1 100644 --- a/libc/intrin/scalbnf.c +++ b/libc/intrin/scalbnf.c @@ -1,26 +1,68 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2022 Justine Alexandra Roberts Tunney │ +/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ +│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ +╚──────────────────────────────────────────────────────────────────────────────╝ │ │ -│ 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. │ +│ 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. │ │ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +asm(".ident\t\"\\n\\n\ +Musl libc (MIT License)\\n\ +Copyright 2005-2014 Rich Felker, et. al.\""); +asm(".include \"libc/disclaimer.inc\""); +// clang-format off + /** * Returns 𝑥 × 2ʸ. */ -float scalbnf(float x, int n) { - return ldexpf(x, n); +float scalbnf(float x, int n) +{ + union {float f; uint32_t i;} u; + float_t y = x; + + if (n > 127) { + y *= 0x1p127f; + n -= 127; + if (n > 127) { + y *= 0x1p127f; + n -= 127; + if (n > 127) + n = 127; + } + } else if (n < -126) { + y *= 0x1p-126f * 0x1p24f; + n += 126 - 24; + if (n < -126) { + y *= 0x1p-126f * 0x1p24f; + n += 126 - 24; + if (n < -126) + n = -126; + } + } + u.i = (uint32_t)(0x7f+n)<<23; + x = y * u.f; + return x; } + +__strong_reference(scalbnf, ldexpf); diff --git a/libc/intrin/scalbnl.c b/libc/intrin/scalbnl.c index 4990173c5..a56460878 100644 --- a/libc/intrin/scalbnl.c +++ b/libc/intrin/scalbnl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -38,9 +39,6 @@ asm(".include \"libc/disclaimer.inc\""); * Returns 𝑥 × 2ʸ. */ long double scalbnl(long double x, int n) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return scalbn(x, n); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 union ldshape u; if (n > 16383) { x *= 0x1p16383L; @@ -64,7 +62,8 @@ long double scalbnl(long double x, int n) { u.f = 1.0; u.i.se = 0x3fff + n; return x * u.f; -#else -#error "architecture unsupported" -#endif } + +__strong_reference(scalbnl, ldexpl); + +#endif /* long double is long */ diff --git a/libc/intrin/sched_yield.S b/libc/intrin/sched_yield.S index ee6996841..556c45c25 100644 --- a/libc/intrin/sched_yield.S +++ b/libc/intrin/sched_yield.S @@ -70,15 +70,15 @@ sched_yield: // a signal." ──Quoth IEEE 1003.1-2017 §functions/select // // On other platforms, sched_yield() takes no arguments. - push $0 # timeout.tv_usec - push $0 # timeout.tv_sec - xor %edi,%edi # nfds - xor %esi,%esi # readfds - xor %edx,%edx # writefds - xor %r10d,%r10d # exceptfds - mov %rsp,%r8 # timeout - mov __NR_sched_yield,%eax # ordinal - clc # linux + push $0 // timeout.tv_usec + push $0 // timeout.tv_sec + xor %edi,%edi // nfds + xor %esi,%esi // readfds + xor %edx,%edx // writefds + xor %r10d,%r10d // exceptfds + mov %rsp,%r8 // timeout + mov __NR_sched_yield,%eax // ordinal + clc // linux syscall // It should not be possible for this to fail so we don't // bother going through the errno ritual. If this somehow diff --git a/libc/intrin/strlen.c b/libc/intrin/strlen.c index 6fe20d751..30d2a4db4 100644 --- a/libc/intrin/strlen.c +++ b/libc/intrin/strlen.c @@ -38,7 +38,7 @@ noasan size_t strlen(const char *s) { m = __builtin_ia32_pmovmskb128(*p == z) >> k << k; while (!m) m = __builtin_ia32_pmovmskb128(*++p == z); return (const char *)p + __builtin_ctzl(m) - s; -#elif defined(__GNUC__) || defined(__llvm__) +#else #define ONES ((word)-1 / 255) #define BANE (ONES * (255 / 2 + 1)) typedef unsigned long mayalias word; @@ -56,10 +56,6 @@ noasan size_t strlen(const char *s) { w = ~w & (w - ONES) & BANE; } return (const char *)p + (__builtin_ctzl(w) >> 3) - s; -#else - size_t n = 0; - while (*s++) ++n; - return n; #endif } diff --git a/libc/intrin/syscall.S b/libc/intrin/syscall.S index 406f65087..e94eb339a 100644 --- a/libc/intrin/syscall.S +++ b/libc/intrin/syscall.S @@ -56,10 +56,10 @@ __syscall__: .bss .balign 8 -.Lrcx: .quad 0 # clobbered by syscall -.Lrdi: .quad 0 # just in case -.Lrsi: .quad 0 # just in case -.Lr8: .quad 0 # freebsd bug? -.Lr9: .quad 0 # just in case -.Lr10: .quad 0 # just in case -.Lr11: .quad 0 # clobbered by syscall +.Lrcx: .quad 0 // clobbered by syscall +.Lrdi: .quad 0 // just in case +.Lrsi: .quad 0 // just in case +.Lr8: .quad 0 // freebsd bug? +.Lr9: .quad 0 // just in case +.Lr10: .quad 0 // just in case +.Lr11: .quad 0 // clobbered by syscall diff --git a/libc/intrin/tpenc2.c b/libc/intrin/tpenc2.c index e7f020fff..381a31090 100644 --- a/libc/intrin/tpenc2.c +++ b/libc/intrin/tpenc2.c @@ -17,7 +17,6 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bsr.h" -#include "libc/intrin/intrin.h" #ifndef __x86_64__ static const uint16_t kTpEnc[32 - 7] = { diff --git a/libc/isystem/thread.h b/libc/isystem/thread.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/libc/nexgen32e/gc.S b/libc/nexgen32e/gc.S index ef0c165c0..24fe588ae 100644 --- a/libc/nexgen32e/gc.S +++ b/libc/nexgen32e/gc.S @@ -33,7 +33,11 @@ // @param rax,rdx,xmm0,xmm1,st0,st1 is return value // @see test/libc/runtime/gc_test.c // @threadsafe -__gc: mov %fs:0,%rcx // __get_tls() +__gc: + +#ifdef __x86_64__ + + mov %fs:0,%rcx // __get_tls() mov 0x18(%rcx),%rcx // tls::garbages decl (%rcx) // ++g->i mov (%rcx),%r8d // r8 = g->i @@ -58,4 +62,22 @@ __gc: mov %fs:0,%rcx // __get_tls() ret 9: ud2 nop + +#elif defined(__aarch64__) + + stp x29,x30,[sp,-80]! + mov x29,sp + stp x0,x1,[sp,16] + stp x2,x3,[sp,32] + stp x4,x5,[sp,48] + stp x6,x7,[sp,64] +// todo jart + ldp x0,x1,[sp,16] + ldp x2,x3,[sp,32] + ldp x4,x5,[sp,48] + ldp x6,x7,[sp,64] + ldp x29,x30,[sp],80 + +#endif /* __x86_64__ */ + .endfn __gc,globl,hidden diff --git a/libc/str/oldutf16.internal.h b/libc/str/oldutf16.internal.h deleted file mode 100755 index e69de29bb..000000000 diff --git a/libc/testlib/benchrunner.c b/libc/testlib/benchrunner.c index f5a6c171f..056d533f8 100644 --- a/libc/testlib/benchrunner.c +++ b/libc/testlib/benchrunner.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "ape/sections.internal.h" #include "libc/calls/calls.h" -#include "libc/calls/kntprioritycombos.internal.h" #include "libc/errno.h" #include "libc/log/log.h" #include "libc/nexgen32e/x86feature.h" diff --git a/libc/testlib/formatint.c b/libc/testlib/formatint.c index 5aca7d16f..89be23135 100644 --- a/libc/testlib/formatint.c +++ b/libc/testlib/formatint.c @@ -34,5 +34,5 @@ dontdiscard char *testlib_formatint(intptr_t x) { } *p++ = ')'; *p++ = '\0'; - return str; + return strdup(str); } diff --git a/libc/tinymath/asin.c b/libc/tinymath/asin.c index 440127f46..c37d612ef 100644 --- a/libc/tinymath/asin.c +++ b/libc/tinymath/asin.c @@ -31,7 +31,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /* origin: FreeBSD /usr/src/lib/msun/src/e_asin.c */ /* @@ -147,3 +147,7 @@ double asin(double x) } return ng ? -x : x; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(asin, asinl); +#endif diff --git a/libc/tinymath/asinl.c b/libc/tinymath/asinl.c index 042598be3..ef2d6806c 100644 --- a/libc/tinymath/asinl.c +++ b/libc/tinymath/asinl.c @@ -29,6 +29,7 @@ #include "libc/tinymath/internal.h" #include "libc/tinymath/invtrigl.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ fdlibm (fdlibm license)\\n\ @@ -55,16 +56,6 @@ asm(".include \"libc/disclaimer.inc\""); * Converted to long double by David Schultz . */ -/** - * Returns arc sine of 𝑥. - * - * @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥))) - * @domain -1 ≤ 𝑥 ≤ 1 - */ -long double asinl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return asin(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 #if LDBL_MANT_DIG == 64 #define CLOSETO1(u) (u.i.m>>56 >= 0xf7) #define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32) @@ -73,6 +64,14 @@ long double asinl(long double x) { #define CLEARBOTTOM(u) (u.i.lo = 0) #endif +/** + * Returns arc sine of 𝑥. + * + * @define atan2(𝑥,sqrt((1-𝑥)*(1+𝑥))) + * @domain -1 ≤ 𝑥 ≤ 1 + */ +long double asinl(long double x) +{ union ldshape u = {x}; long double z, r, s; uint16_t e = u.i.se & 0x7fff; @@ -108,7 +107,6 @@ long double asinl(long double x) { } return sign ? -x : x; -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/atan.c b/libc/tinymath/atan.c index ee22b65cb..4faae90a2 100644 --- a/libc/tinymath/atan.c +++ b/libc/tinymath/atan.c @@ -154,3 +154,7 @@ double atan(double x) z = atanhi[id] - (x*(s1+s2) - atanlo[id] - x); return sign ? -z : z; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(atan, atanl); +#endif diff --git a/libc/tinymath/atan2.c b/libc/tinymath/atan2.c index 51b9ca89e..1a655ffb4 100644 --- a/libc/tinymath/atan2.c +++ b/libc/tinymath/atan2.c @@ -153,3 +153,7 @@ atan2(double y, double x) return (z-pi_lo)-pi;/* atan(-,-) */ } } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(atan2, atan2l); +#endif diff --git a/libc/tinymath/atan2l.c b/libc/tinymath/atan2l.c index 9b8a5fcbb..262b4a2e1 100644 --- a/libc/tinymath/atan2l.c +++ b/libc/tinymath/atan2l.c @@ -29,6 +29,7 @@ #include "libc/tinymath/internal.h" #include "libc/tinymath/invtrigl.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ fdlibm (fdlibm license)\\n\ @@ -69,11 +70,7 @@ long double atan2l(long double y, long double x) : "st(1)"); return x; -#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return atan2(y, x); - -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +#else union ldshape ux, uy; long double z; @@ -130,7 +127,7 @@ long double atan2l(long double y, long double x) return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */ } -#else -#error "architecture unsupported" #endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/atanh.c b/libc/tinymath/atanh.c index f930c69eb..112940c0d 100644 --- a/libc/tinymath/atanh.c +++ b/libc/tinymath/atanh.c @@ -32,7 +32,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /** * Returns inverse hyperbolic tangent of 𝑥. @@ -64,3 +64,7 @@ double atanh(double x) } return s ? -y : y; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(atanh, atanhl); +#endif diff --git a/libc/tinymath/atanhl.c b/libc/tinymath/atanhl.c index 2df853f03..401e00f25 100644 --- a/libc/tinymath/atanhl.c +++ b/libc/tinymath/atanhl.c @@ -28,19 +28,13 @@ #include "libc/math.h" #include "libc/tinymath/feval.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double atanhl(long double x) -{ - return atanh(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +// clang-format off /** * Returns inverse hyperbolic tangent of 𝑥. @@ -72,6 +66,4 @@ long double atanhl(long double x) return s ? -x : x; } -#else -#error "architecture unsupported" -#endif +#endif /* long double is long */ diff --git a/libc/tinymath/atanl.c b/libc/tinymath/atanl.c index ea2436523..f4df789b0 100644 --- a/libc/tinymath/atanl.c +++ b/libc/tinymath/atanl.c @@ -28,6 +28,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ fdlibm (fdlibm license)\\n\ @@ -54,13 +55,6 @@ asm(".include \"libc/disclaimer.inc\""); * Converted to long double by David Schultz . */ -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double atanl(long double x) -{ - return atan(x); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - #if LDBL_MANT_DIG == 64 #define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | (u.i.m>>55 & 0xff)) @@ -231,6 +225,4 @@ long double atanl(long double x) return sign ? -z : z; } -#else -#error "architecture unsupported" -#endif +#endif /* long double is long */ diff --git a/libc/tinymath/cabs.c b/libc/tinymath/cabs.c index 3ac214349..b4f81f2bf 100644 --- a/libc/tinymath/cabs.c +++ b/libc/tinymath/cabs.c @@ -25,3 +25,7 @@ double cabs(double complex z) { return hypot(creal(z), cimag(z)); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(cabs, cabsl); +#endif diff --git a/libc/tinymath/cabsl.c b/libc/tinymath/cabsl.c index 000ab21d3..99123254d 100644 --- a/libc/tinymath/cabsl.c +++ b/libc/tinymath/cabsl.c @@ -18,14 +18,13 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/complex.h" #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Returns absolute value of complex number. */ long double cabsl(long double complex z) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return cabs(z); -#else return hypotl(creall(z), cimagl(z)); -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/carg.c b/libc/tinymath/carg.c index 1fc294378..aab4e71b6 100644 --- a/libc/tinymath/carg.c +++ b/libc/tinymath/carg.c @@ -22,3 +22,7 @@ double carg(double complex z) { return atan2(cimag(z), creal(z)); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(carg, cargl); +#endif diff --git a/libc/tinymath/cargl.c b/libc/tinymath/cargl.c index 5a18fc27c..53d766355 100644 --- a/libc/tinymath/cargl.c +++ b/libc/tinymath/cargl.c @@ -18,11 +18,10 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/complex.h" #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) long double cargl(long double complex z) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return carg(z); -#else return atan2l(cimagl(z), creall(z)); -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/casin.c b/libc/tinymath/casin.c index d2a476dc2..ebde7f5e7 100644 --- a/libc/tinymath/casin.c +++ b/libc/tinymath/casin.c @@ -33,9 +33,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ - - +// clang-format off // FIXME @@ -52,3 +50,7 @@ double complex casin(double complex z) double complex r = clog(CMPLX(-y, x) + csqrt(w)); return CMPLX(cimag(r), -creal(r)); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(casin, casinl); +#endif diff --git a/libc/tinymath/casinl.c b/libc/tinymath/casinl.c index 84625db53..5d3c3c820 100644 --- a/libc/tinymath/casinl.c +++ b/libc/tinymath/casinl.c @@ -26,18 +26,16 @@ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/complex.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off -long double complex casinl(long double complex z) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return casin(z); -#else -// FIXME +long double complex casinl(long double complex z) +{ long double complex w; long double x, y; x = creall(z); @@ -45,5 +43,6 @@ long double complex casinl(long double complex z) { w = CMPLXL(1.0 - (x - y)*(x + y), -2.0*x*y); long double complex r = clogl(CMPLXL(-y, x) + csqrtl(w)); return CMPLXL(cimagl(r), -creall(r)); -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/catan.c b/libc/tinymath/catan.c index 7445341a3..8a0263db4 100644 --- a/libc/tinymath/catan.c +++ b/libc/tinymath/catan.c @@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /* origin: OpenBSD /usr/src/lib/libm/src/s_catan.c */ diff --git a/libc/tinymath/ccos.c b/libc/tinymath/ccos.c index c10449cb6..cfbb036eb 100644 --- a/libc/tinymath/ccos.c +++ b/libc/tinymath/ccos.c @@ -1,45 +1,24 @@ -/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ -│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ -╚──────────────────────────────────────────────────────────────────────────────╝ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ -│ 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. │ +│ 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/complex.h" #include "libc/math.h" -#include "libc/tinymath/complex.internal.h" -asm(".ident\t\"\\n\\n\ -Musl libc (MIT License)\\n\ -Copyright 2005-2014 Rich Felker, et. al.\""); -asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ - - - -/* cos(z) = cosh(i z) */ - -double complex ccos(double complex z) -{ - return ccosh(CMPLX(-cimag(z), creal(z))); +double complex ccos(double complex z) { + return ccosh(CMPLX(-cimag(z), creal(z))); } diff --git a/libc/tinymath/cos.c b/libc/tinymath/cos.c index 44ec3a96c..04a4673bf 100644 --- a/libc/tinymath/cos.c +++ b/libc/tinymath/cos.c @@ -36,7 +36,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /* origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */ /* @@ -120,3 +120,7 @@ double cos(double x) return __sin(y[0], y[1], 1); } } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(cos, cosl); +#endif diff --git a/libc/tinymath/cosh.c b/libc/tinymath/cosh.c index d68f6e6bc..a3a0a3b1c 100644 --- a/libc/tinymath/cosh.c +++ b/libc/tinymath/cosh.c @@ -33,7 +33,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /** * Returns hyperbolic cosine of 𝑥. diff --git a/libc/tinymath/cosl.c b/libc/tinymath/cosl.c index 41c9eacda..a439cf4d5 100644 --- a/libc/tinymath/cosl.c +++ b/libc/tinymath/cosl.c @@ -29,6 +29,7 @@ #include "libc/math.h" #include "libc/tinymath/kernel.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -41,9 +42,6 @@ asm(".include \"libc/disclaimer.inc\""); */ long double cosl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return cos(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 union ldshape u = {x}; unsigned n; long double y[2], hi, lo; @@ -72,7 +70,6 @@ long double cosl(long double x) default: return __sinl(hi, lo, 1); } -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/drem.c b/libc/tinymath/drem.c deleted file mode 100644 index 3124ef2a7..000000000 --- a/libc/tinymath/drem.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -double drem(double x, double y) { - return remainder(x, y); -} diff --git a/libc/tinymath/dremf.c b/libc/tinymath/dremf.c deleted file mode 100644 index de1e9ac35..000000000 --- a/libc/tinymath/dremf.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -float dremf(float x, float y) { - return remainderf(x, y); -} diff --git a/libc/tinymath/dreml.c b/libc/tinymath/dreml.c deleted file mode 100644 index f9024bfb8..000000000 --- a/libc/tinymath/dreml.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -long double dreml(long double x, long double y) { - return remainderl(x, y); -} diff --git a/libc/tinymath/exp.c b/libc/tinymath/exp.c index cb9e7e893..79aaaadac 100644 --- a/libc/tinymath/exp.c +++ b/libc/tinymath/exp.c @@ -168,3 +168,7 @@ double exp(double x) is no spurious underflow here even without fma. */ return eval_as_double(scale + scale * tmp); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(exp, expl); +#endif diff --git a/libc/tinymath/exp10.c b/libc/tinymath/exp10.c index bc7ab0a6a..0c95576f8 100644 --- a/libc/tinymath/exp10.c +++ b/libc/tinymath/exp10.c @@ -33,6 +33,9 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off +/** + * Returns 10ˣ. + */ double exp10(double x) { static const double p10[] = { @@ -51,3 +54,8 @@ double exp10(double x) } return pow(10.0, x); } + +__strong_reference(exp10, pow10); +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(exp10, exp10l); +#endif diff --git a/libc/tinymath/exp10f.c b/libc/tinymath/exp10f.c index 9b8b8a9c0..2df7954b3 100644 --- a/libc/tinymath/exp10f.c +++ b/libc/tinymath/exp10f.c @@ -33,6 +33,9 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off +/** + * Returns 10ˣ. + */ float exp10f(float x) { static const float p10[] = { @@ -49,3 +52,5 @@ float exp10f(float x) } return exp2(3.32192809488736234787031942948939 * x); } + +__strong_reference(exp10f, pow10f); diff --git a/libc/tinymath/exp10l.c b/libc/tinymath/exp10l.c index 369cacd47..456e94a06 100644 --- a/libc/tinymath/exp10l.c +++ b/libc/tinymath/exp10l.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -34,10 +35,11 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -long double exp10l(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return exp10(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +/** + * Returns 10ˣ. + */ +long double exp10l(long double x) +{ static const long double p10[] = { 1e-15L, 1e-14L, 1e-13L, 1e-12L, 1e-11L, 1e-10L, 1e-9L, 1e-8L, 1e-7L, 1e-6L, 1e-5L, 1e-4L, 1e-3L, 1e-2L, 1e-1L, @@ -53,7 +55,8 @@ long double exp10l(long double x) { return y * p10[(int)n+15]; } return powl(10.0, x); -#else -#error "architecture unsupported" -#endif } + +__strong_reference(exp10l, pow10l); + +#endif /* long double is long */ diff --git a/libc/tinymath/exp2.c b/libc/tinymath/exp2.c index 819c51118..55ea241dd 100644 --- a/libc/tinymath/exp2.c +++ b/libc/tinymath/exp2.c @@ -155,3 +155,7 @@ double exp2(double x) is no spurious underflow here even without fma. */ return eval_as_double(scale + scale * tmp); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(exp2, exp2l); +#endif diff --git a/libc/tinymath/exp2l.c b/libc/tinymath/exp2l.c index 90b4b160e..8e11706e1 100644 --- a/libc/tinymath/exp2l.c +++ b/libc/tinymath/exp2l.c @@ -28,6 +28,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -65,12 +66,6 @@ asm(".include \"libc/disclaimer.inc\""); * SUCH DAMAGE. */ -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double exp2l(long double x) -{ - return exp2(x); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 #define TBLBITS 7 #define TBLSIZE (1 << TBLBITS) @@ -235,6 +230,10 @@ static const double tbl[TBLSIZE * 2] = { * The table entries each have 104 bits of accuracy, encoded as * a pair of double precision values. */ + +/** + * Returns 2^𝑥. + */ long double exp2l(long double x) { union ldshape u = {x}; @@ -289,6 +288,7 @@ long double exp2l(long double x) return scalbnl(r, k.i); } + #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 #define TBLBITS 7 #define TBLSIZE (1 << TBLBITS) @@ -600,6 +600,10 @@ static const float eps[TBLSIZE] = { * Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library * for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991). */ + +/** + * Returns 2^𝑥. + */ long double exp2l(long double x) { @@ -654,6 +658,5 @@ exp2l(long double x) return scalbnl(r, k.i); } -#else -#error "architecture unsupported" + #endif diff --git a/libc/tinymath/expl.c b/libc/tinymath/expl.c index f683dc303..168309e9b 100644 --- a/libc/tinymath/expl.c +++ b/libc/tinymath/expl.c @@ -18,13 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - -long double expl(long double x) { - return exp(x); -} - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 #include "libc/tinymath/internal.h" asm(".ident\t\"\\n\\n\ @@ -120,6 +114,9 @@ LN2HI = 6.9314575195312500000000E-1L, LN2LO = 1.4286068203094172321215E-6L, LOG2E = 1.4426950408889634073599E0L; +/** + * Returns 𝑒ˣ. + */ long double expl(long double x) { long double px, xx; @@ -211,6 +208,45 @@ o_threshold = 11356.523406294143949491931077970763428L, /* log(2**(-16381-64-1)) rounded towards zero: */ u_threshold = -11433.462743336297878837243843452621503L; +static const double +/* + * ln2/INTERVALS = L1+L2 (hi+lo decomposition for multiplication). L1 must + * have at least 22 (= log2(|LDBL_MIN_EXP-extras|) + log2(INTERVALS)) lowest + * bits zero so that multiplication of it by n is exact. + */ +INV_L = 1.8466496523378731e+2, /* 0x171547652b82fe.0p-45 */ +L2 = -1.0253670638894731e-29; /* -0x1.9ff0342542fc3p-97 */ +static const long double +/* 0x1.62e42fefa39ef35793c768000000p-8 */ +L1 = 5.41521234812457272982212595914567508e-3L; + +/* + * XXX values in hex in comments have been lost (or were never present) + * from here. + */ +static const long double +/* + * Domain [-0.002708, 0.002708], range ~[-2.4021e-38, 2.4234e-38]: + * |exp(x) - p(x)| < 2**-124.9 + * (0.002708 is ln2/(2*INTERVALS) rounded up a little). + * + * XXX the coeffs aren't very carefully rounded, and I get 3.6 more bits. + */ +A2 = 0.5, +A3 = 1.66666666666666666666666666651085500e-1L, +A4 = 4.16666666666666666666666666425885320e-2L, +A5 = 8.33333333333333333334522877160175842e-3L, +A6 = 1.38888888888888888889971139751596836e-3L; + +static const double +A7 = 1.9841269841269470e-4, /* 0x1.a01a01a019f91p-13 */ +A8 = 2.4801587301585286e-5, /* 0x1.71de3ec75a967p-19 */ +A9 = 2.7557324277411235e-6, /* 0x1.71de3ec75a967p-19 */ +A10 = 2.7557333722375069e-7; /* 0x1.27e505ab56259p-22 */ + +/** + * Returns 𝑒ˣ. + */ long double expl(long double x) { @@ -354,6 +390,9 @@ D15 = 7.6478532249581686e-13, /* 0x1.ae892e3D16fcep-41 */ D16 = 4.7628892832607741e-14, /* 0x1.ad00Dfe41feccp-45 */ D17 = 3.0524857220358650e-15; /* 0x1.D7e8d886Df921p-49 */ +/** + * Returns 𝑒ˣ-1. + */ long double expm1l(long double x) { @@ -440,30 +479,30 @@ expm1l(long double x) /* * Evaluate lower terms of - * expl(endpoint[n2] + r1 + r2) = tbl[n2] * expl(r1 + r2). + * expl(endpoint[n2] + r1 + r2) = kExplData[n2] * expl(r1 + r2). */ dr = r; q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 + dr * (A7 + dr * (A8 + dr * (A9 + dr * A10)))))))); - t = tbl[n2].lo + tbl[n2].hi; + t = kExplData[n2].lo + kExplData[n2].hi; if (k == 0) { - t = SUM2P(tbl[n2].hi - 1, tbl[n2].lo * (r1 + 1) + t * q + - tbl[n2].hi * r1); + t = SUM2P(kExplData[n2].hi - 1, kExplData[n2].lo * (r1 + 1) + t * q + + kExplData[n2].hi * r1); RETURNI(t); } if (k == -1) { - t = SUM2P(tbl[n2].hi - 2, tbl[n2].lo * (r1 + 1) + t * q + - tbl[n2].hi * r1); + t = SUM2P(kExplData[n2].hi - 2, kExplData[n2].lo * (r1 + 1) + t * q + + kExplData[n2].hi * r1); RETURNI(t / 2); } if (k < -7) { - t = SUM2P(tbl[n2].hi, tbl[n2].lo + t * (q + r1)); + t = SUM2P(kExplData[n2].hi, kExplData[n2].lo + t * (q + r1)); RETURNI(t * twopk - 1); } if (k > 2 * LDBL_MANT_DIG - 1) { - t = SUM2P(tbl[n2].hi, tbl[n2].lo + t * (q + r1)); + t = SUM2P(kExplData[n2].hi, kExplData[n2].lo + t * (q + r1)); if (k == LDBL_MAX_EXP) RETURNI(t * 2 * 0x1p16383L - 1); RETURNI(t * twopk - 1); @@ -473,12 +512,10 @@ expm1l(long double x) twomk = v.e; if (k > LDBL_MANT_DIG - 1) - t = SUM2P(tbl[n2].hi, tbl[n2].lo - twomk + t * (q + r1)); + t = SUM2P(kExplData[n2].hi, kExplData[n2].lo - twomk + t * (q + r1)); else - t = SUM2P(tbl[n2].hi - twomk, tbl[n2].lo + t * (q + r1)); + t = SUM2P(kExplData[n2].hi - twomk, kExplData[n2].lo + t * (q + r1)); RETURNI(t * twopk); } -#else -#error "architecture unsupported" #endif diff --git a/libc/tinymath/expm1.c b/libc/tinymath/expm1.c index dee375cd4..657abd8aa 100644 --- a/libc/tinymath/expm1.c +++ b/libc/tinymath/expm1.c @@ -236,3 +236,7 @@ double expm1(double x) y = (x-(e+u.f)+1)*twopk; return y; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(expm1, expm1l); +#endif diff --git a/libc/tinymath/expm1f.c b/libc/tinymath/expm1f.c index 64d4e078c..70460b115 100644 --- a/libc/tinymath/expm1f.c +++ b/libc/tinymath/expm1f.c @@ -65,7 +65,7 @@ Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */ static volatile float huge = 1.0e+30; /** - * Returns 𝑒^𝑥-𝟷. + * Returns 𝑒ˣ-1. */ float expm1f(float x) diff --git a/libc/tinymath/expm1l.c b/libc/tinymath/expm1l.c index 2fa85565b..bd585bca8 100644 --- a/libc/tinymath/expm1l.c +++ b/libc/tinymath/expm1l.c @@ -1,14 +1,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" // clang-format off - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - -long double expm1l(long double x) { - return expm1(x); -} - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ OpenBSD libm (ISC License)\\n\ @@ -88,6 +81,9 @@ minarg = -4.5054566736396445112120088E1L, /* ln 2^16384 */ maxarg = 1.1356523406294143949492E4L; +/** + * Returns 𝑒ˣ-1. + */ long double expm1l(long double x) { long double px, qx, xx; @@ -124,10 +120,4 @@ long double expm1l(long double x) return x; } -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - -// see expl.c - -#else -#error "architecture unsupported" -#endif +#endif /* long double is long */ diff --git a/libc/tinymath/expo2.c b/libc/tinymath/expo2.c index 6be72474c..3632481dd 100644 --- a/libc/tinymath/expo2.c +++ b/libc/tinymath/expo2.c @@ -26,6 +26,7 @@ │ │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#include "libc/tinymath/expo.internal.h" asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ diff --git a/libc/tinymath/fabs.c b/libc/tinymath/fabs.c index 8c0ab999e..75cc9fbe8 100644 --- a/libc/tinymath/fabs.c +++ b/libc/tinymath/fabs.c @@ -29,3 +29,7 @@ double fabs(double x) { u.i &= -1ULL / 2; return u.f; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(fabs, fabsl); +#endif diff --git a/libc/tinymath/fabsl.c b/libc/tinymath/fabsl.c index 8cf78d3d8..9701fa216 100644 --- a/libc/tinymath/fabsl.c +++ b/libc/tinymath/fabsl.c @@ -18,18 +18,15 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Returns absolute value of floating point number. */ long double fabsl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return fabs(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 union ldshape u = {x}; u.i.se &= 0x7fff; return u.f; -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/fdim.c b/libc/tinymath/fdim.c index 38cc33ef7..e76f946be 100644 --- a/libc/tinymath/fdim.c +++ b/libc/tinymath/fdim.c @@ -25,3 +25,7 @@ double fdim(double x, double y) { if (isunordered(x, y)) return NAN; return x > y ? x - y : 0; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(fdim, fdiml); +#endif diff --git a/libc/tinymath/fdiml.c b/libc/tinymath/fdiml.c index 5e005b69a..4b561348f 100644 --- a/libc/tinymath/fdiml.c +++ b/libc/tinymath/fdiml.c @@ -17,15 +17,14 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Returns positive difference. */ long double fdiml(long double x, long double y) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return fdim(x, y); -#else if (isunordered(x, y)) return NAN; return x > y ? x - y : 0; -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/floor.c b/libc/tinymath/floor.c index c8fedbdd9..69cf60187 100644 --- a/libc/tinymath/floor.c +++ b/libc/tinymath/floor.c @@ -94,3 +94,7 @@ double floor(double x) #endif /* __aarch64__ */ } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(floor, floorl); +#endif diff --git a/libc/tinymath/floorl.c b/libc/tinymath/floorl.c index 96298a09a..4636f700b 100644 --- a/libc/tinymath/floorl.c +++ b/libc/tinymath/floorl.c @@ -28,6 +28,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -40,11 +41,6 @@ asm(".include \"libc/disclaimer.inc\""); */ long double floorl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return floor(x); - -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 static const long double toint = 1/LDBL_EPSILON; union ldshape u = {x}; @@ -66,8 +62,6 @@ long double floorl(long double x) if (y > 0) return x + y - 1; return x + y; - -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/fmin.c b/libc/tinymath/fmin.c index aa4e06da5..a382ebf85 100644 --- a/libc/tinymath/fmin.c +++ b/libc/tinymath/fmin.c @@ -33,3 +33,7 @@ double fmin(double x, double y) { } return x < y ? x : y; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(fmin, fminl); +#endif diff --git a/libc/tinymath/fminl.c b/libc/tinymath/fminl.c index 2eeb761b5..98230af5a 100644 --- a/libc/tinymath/fminl.c +++ b/libc/tinymath/fminl.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Returns minimum of two long doubles. @@ -33,3 +34,5 @@ long double fminl(long double x, long double y) { } return x < y ? x : y; } + +#endif /* long double is long */ diff --git a/libc/tinymath/freebsd.internal.h b/libc/tinymath/freebsd.internal.h index dae1c3637..be8b158f1 100644 --- a/libc/tinymath/freebsd.internal.h +++ b/libc/tinymath/freebsd.internal.h @@ -944,54 +944,11 @@ long double __kernel_sinl(long double, long double, int); long double __kernel_cosl(long double, long double); long double __kernel_tanl(long double, long double, int); -/* - * ld128 version of k_expl.h. See ../ld80/s_expl.c for most comments. - * - * See ../src/e_exp.c and ../src/k_exp.h for precision-independent comments - * about the secondary kernels. - */ - #define INTERVALS 128 #define LOG2_INTERVALS 7 -#define BIAS (LDBL_MAX_EXP - 1) +#define BIAS (LDBL_MAX_EXP - 1) -static const double -/* - * ln2/INTERVALS = L1+L2 (hi+lo decomposition for multiplication). L1 must - * have at least 22 (= log2(|LDBL_MIN_EXP-extras|) + log2(INTERVALS)) lowest - * bits zero so that multiplication of it by n is exact. - */ -INV_L = 1.8466496523378731e+2, /* 0x171547652b82fe.0p-45 */ -L2 = -1.0253670638894731e-29; /* -0x1.9ff0342542fc3p-97 */ -static const long double -/* 0x1.62e42fefa39ef35793c768000000p-8 */ -L1 = 5.41521234812457272982212595914567508e-3L; - -/* - * XXX values in hex in comments have been lost (or were never present) - * from here. - */ -static const long double -/* - * Domain [-0.002708, 0.002708], range ~[-2.4021e-38, 2.4234e-38]: - * |exp(x) - p(x)| < 2**-124.9 - * (0.002708 is ln2/(2*INTERVALS) rounded up a little). - * - * XXX the coeffs aren't very carefully rounded, and I get 3.6 more bits. - */ -A2 = 0.5, -A3 = 1.66666666666666666666666666651085500e-1L, -A4 = 4.16666666666666666666666666425885320e-2L, -A5 = 8.33333333333333333334522877160175842e-3L, -A6 = 1.38888888888888888889971139751596836e-3L; - -static const double -A7 = 1.9841269841269470e-4, /* 0x1.a01a01a019f91p-13 */ -A8 = 2.4801587301585286e-5, /* 0x1.71de3ec75a967p-19 */ -A9 = 2.7557324277411235e-6, /* 0x1.71de3ec75a967p-19 */ -A10 = 2.7557333722375069e-7; /* 0x1.27e505ab56259p-22 */ - -static const struct { +struct ExplData { /* * hi must be rounded to at most 106 bits so that multiplication * by r1 in expm1l() is exact, but it is rounded to 88 bits due to @@ -1011,167 +968,11 @@ static const struct { */ long double hi; long double lo; -} tbl[INTERVALS] = { - {0x1p0L, 0x0p0L}, - {0x1.0163da9fb33356d84a66aep0L, 0x3.36dcdfa4003ec04c360be2404078p-92L}, - {0x1.02c9a3e778060ee6f7cacap0L, 0x4.f7a29bde93d70a2cabc5cb89ba10p-92L}, - {0x1.04315e86e7f84bd738f9a2p0L, 0xd.a47e6ed040bb4bfc05af6455e9b8p-96L}, - {0x1.059b0d31585743ae7c548ep0L, 0xb.68ca417fe53e3495f7df4baf84a0p-92L}, - {0x1.0706b29ddf6ddc6dc403a8p0L, 0x1.d87b27ed07cb8b092ac75e311753p-88L}, - {0x1.0874518759bc808c35f25cp0L, 0x1.9427fa2b041b2d6829d8993a0d01p-88L}, - {0x1.09e3ecac6f3834521e060cp0L, 0x5.84d6b74ba2e023da730e7fccb758p-92L}, - {0x1.0b5586cf9890f6298b92b6p0L, 0x1.1842a98364291408b3ceb0a2a2bbp-88L}, - {0x1.0cc922b7247f7407b705b8p0L, 0x9.3dc5e8aac564e6fe2ef1d431fd98p-92L}, - {0x1.0e3ec32d3d1a2020742e4ep0L, 0x1.8af6a552ac4b358b1129e9f966a4p-88L}, - {0x1.0fb66affed31af232091dcp0L, 0x1.8a1426514e0b627bda694a400a27p-88L}, - {0x1.11301d0125b50a4ebbf1aep0L, 0xd.9318ceac5cc47ab166ee57427178p-92L}, - {0x1.12abdc06c31cbfb92bad32p0L, 0x4.d68e2f7270bdf7cedf94eb1cb818p-92L}, - {0x1.1429aaea92ddfb34101942p0L, 0x1.b2586d01844b389bea7aedd221d4p-88L}, - {0x1.15a98c8a58e512480d573cp0L, 0x1.d5613bf92a2b618ee31b376c2689p-88L}, - {0x1.172b83c7d517adcdf7c8c4p0L, 0x1.0eb14a792035509ff7d758693f24p-88L}, - {0x1.18af9388c8de9bbbf70b9ap0L, 0x3.c2505c97c0102e5f1211941d2840p-92L}, - {0x1.1a35beb6fcb753cb698f68p0L, 0x1.2d1c835a6c30724d5cfae31b84e5p-88L}, - {0x1.1bbe084045cd39ab1e72b4p0L, 0x4.27e35f9acb57e473915519a1b448p-92L}, - {0x1.1d4873168b9aa7805b8028p0L, 0x9.90f07a98b42206e46166cf051d70p-92L}, - {0x1.1ed5022fcd91cb8819ff60p0L, 0x1.121d1e504d36c47474c9b7de6067p-88L}, - {0x1.2063b88628cd63b8eeb028p0L, 0x1.50929d0fc487d21c2b84004264dep-88L}, - {0x1.21f49917ddc962552fd292p0L, 0x9.4bdb4b61ea62477caa1dce823ba0p-92L}, - {0x1.2387a6e75623866c1fadb0p0L, 0x1.c15cb593b0328566902df69e4de2p-88L}, - {0x1.251ce4fb2a63f3582ab7dep0L, 0x9.e94811a9c8afdcf796934bc652d0p-92L}, - {0x1.26b4565e27cdd257a67328p0L, 0x1.d3b249dce4e9186ddd5ff44e6b08p-92L}, - {0x1.284dfe1f5638096cf15cf0p0L, 0x3.ca0967fdaa2e52d7c8106f2e262cp-92L}, - {0x1.29e9df51fdee12c25d15f4p0L, 0x1.a24aa3bca890ac08d203fed80a07p-88L}, - {0x1.2b87fd0dad98ffddea4652p0L, 0x1.8fcab88442fdc3cb6de4519165edp-88L}, - {0x1.2d285a6e4030b40091d536p0L, 0xd.075384589c1cd1b3e4018a6b1348p-92L}, - {0x1.2ecafa93e2f5611ca0f45cp0L, 0x1.523833af611bdcda253c554cf278p-88L}, - {0x1.306fe0a31b7152de8d5a46p0L, 0x3.05c85edecbc27343629f502f1af2p-92L}, - {0x1.32170fc4cd8313539cf1c2p0L, 0x1.008f86dde3220ae17a005b6412bep-88L}, - {0x1.33c08b26416ff4c9c8610cp0L, 0x1.96696bf95d1593039539d94d662bp-88L}, - {0x1.356c55f929ff0c94623476p0L, 0x3.73af38d6d8d6f9506c9bbc93cbc0p-92L}, - {0x1.371a7373aa9caa7145502ep0L, 0x1.4547987e3e12516bf9c699be432fp-88L}, - {0x1.38cae6d05d86585a9cb0d8p0L, 0x1.bed0c853bd30a02790931eb2e8f0p-88L}, - {0x1.3a7db34e59ff6ea1bc9298p0L, 0x1.e0a1d336163fe2f852ceeb134067p-88L}, - {0x1.3c32dc313a8e484001f228p0L, 0xb.58f3775e06ab66353001fae9fca0p-92L}, - {0x1.3dea64c12342235b41223ep0L, 0x1.3d773fba2cb82b8244267c54443fp-92L}, - {0x1.3fa4504ac801ba0bf701aap0L, 0x4.1832fb8c1c8dbdff2c49909e6c60p-92L}, - {0x1.4160a21f72e29f84325b8ep0L, 0x1.3db61fb352f0540e6ba05634413ep-88L}, - {0x1.431f5d950a896dc7044394p0L, 0x1.0ccec81e24b0caff7581ef4127f7p-92L}, - {0x1.44e086061892d03136f408p0L, 0x1.df019fbd4f3b48709b78591d5cb5p-88L}, - {0x1.46a41ed1d005772512f458p0L, 0x1.229d97df404ff21f39c1b594d3a8p-88L}, - {0x1.486a2b5c13cd013c1a3b68p0L, 0x1.062f03c3dd75ce8757f780e6ec99p-88L}, - {0x1.4a32af0d7d3de672d8bcf4p0L, 0x6.f9586461db1d878b1d148bd3ccb8p-92L}, - {0x1.4bfdad5362a271d4397afep0L, 0xc.42e20e0363ba2e159c579f82e4b0p-92L}, - {0x1.4dcb299fddd0d63b36ef1ap0L, 0x9.e0cc484b25a5566d0bd5f58ad238p-92L}, - {0x1.4f9b2769d2ca6ad33d8b68p0L, 0x1.aa073ee55e028497a329a7333dbap-88L}, - {0x1.516daa2cf6641c112f52c8p0L, 0x4.d822190e718226177d7608d20038p-92L}, - {0x1.5342b569d4f81df0a83c48p0L, 0x1.d86a63f4e672a3e429805b049465p-88L}, - {0x1.551a4ca5d920ec52ec6202p0L, 0x4.34ca672645dc6c124d6619a87574p-92L}, - {0x1.56f4736b527da66ecb0046p0L, 0x1.64eb3c00f2f5ab3d801d7cc7272dp-88L}, - {0x1.58d12d497c7fd252bc2b72p0L, 0x1.43bcf2ec936a970d9cc266f0072fp-88L}, - {0x1.5ab07dd48542958c930150p0L, 0x1.91eb345d88d7c81280e069fbdb63p-88L}, - {0x1.5c9268a5946b701c4b1b80p0L, 0x1.6986a203d84e6a4a92f179e71889p-88L}, - {0x1.5e76f15ad21486e9be4c20p0L, 0x3.99766a06548a05829e853bdb2b52p-92L}, - {0x1.605e1b976dc08b076f592ap0L, 0x4.86e3b34ead1b4769df867b9c89ccp-92L}, - {0x1.6247eb03a5584b1f0fa06ep0L, 0x1.d2da42bb1ceaf9f732275b8aef30p-88L}, - {0x1.6434634ccc31fc76f8714cp0L, 0x4.ed9a4e41000307103a18cf7a6e08p-92L}, - {0x1.66238825522249127d9e28p0L, 0x1.b8f314a337f4dc0a3adf1787ff74p-88L}, - {0x1.68155d44ca973081c57226p0L, 0x1.b9f32706bfe4e627d809a85dcc66p-88L}, - {0x1.6a09e667f3bcc908b2fb12p0L, 0x1.66ea957d3e3adec17512775099dap-88L}, - {0x1.6c012750bdabeed76a9980p0L, 0xf.4f33fdeb8b0ecd831106f57b3d00p-96L}, - {0x1.6dfb23c651a2ef220e2cbep0L, 0x1.bbaa834b3f11577ceefbe6c1c411p-92L}, - {0x1.6ff7df9519483cf87e1b4ep0L, 0x1.3e213bff9b702d5aa477c12523cep-88L}, - {0x1.71f75e8ec5f73dd2370f2ep0L, 0xf.0acd6cb434b562d9e8a20adda648p-92L}, - {0x1.73f9a48a58173bd5c9a4e6p0L, 0x8.ab1182ae217f3a7681759553e840p-92L}, - {0x1.75feb564267c8bf6e9aa32p0L, 0x1.a48b27071805e61a17b954a2dad8p-88L}, - {0x1.780694fde5d3f619ae0280p0L, 0x8.58b2bb2bdcf86cd08e35fb04c0f0p-92L}, - {0x1.7a11473eb0186d7d51023ep0L, 0x1.6cda1f5ef42b66977960531e821bp-88L}, - {0x1.7c1ed0130c1327c4933444p0L, 0x1.937562b2dc933d44fc828efd4c9cp-88L}, - {0x1.7e2f336cf4e62105d02ba0p0L, 0x1.5797e170a1427f8fcdf5f3906108p-88L}, - {0x1.80427543e1a11b60de6764p0L, 0x9.a354ea706b8e4d8b718a672bf7c8p-92L}, - {0x1.82589994cce128acf88afap0L, 0xb.34a010f6ad65cbbac0f532d39be0p-92L}, - {0x1.8471a4623c7acce52f6b96p0L, 0x1.c64095370f51f48817914dd78665p-88L}, - {0x1.868d99b4492ec80e41d90ap0L, 0xc.251707484d73f136fb5779656b70p-92L}, - {0x1.88ac7d98a669966530bcdep0L, 0x1.2d4e9d61283ef385de170ab20f96p-88L}, - {0x1.8ace5422aa0db5ba7c55a0p0L, 0x1.92c9bb3e6ed61f2733304a346d8fp-88L}, - {0x1.8cf3216b5448bef2aa1cd0p0L, 0x1.61c55d84a9848f8c453b3ca8c946p-88L}, - {0x1.8f1ae991577362b982745cp0L, 0x7.2ed804efc9b4ae1458ae946099d4p-92L}, - {0x1.9145b0b91ffc588a61b468p0L, 0x1.f6b70e01c2a90229a4c4309ea719p-88L}, - {0x1.93737b0cdc5e4f4501c3f2p0L, 0x5.40a22d2fc4af581b63e8326efe9cp-92L}, - {0x1.95a44cbc8520ee9b483694p0L, 0x1.a0fc6f7c7d61b2b3a22a0eab2cadp-88L}, - {0x1.97d829fde4e4f8b9e920f8p0L, 0x1.1e8bd7edb9d7144b6f6818084cc7p-88L}, - {0x1.9a0f170ca07b9ba3109b8cp0L, 0x4.6737beb19e1eada6825d3c557428p-92L}, - {0x1.9c49182a3f0901c7c46b06p0L, 0x1.1f2be58ddade50c217186c90b457p-88L}, - {0x1.9e86319e323231824ca78ep0L, 0x6.4c6e010f92c082bbadfaf605cfd4p-92L}, - {0x1.a0c667b5de564b29ada8b8p0L, 0xc.ab349aa0422a8da7d4512edac548p-92L}, - {0x1.a309bec4a2d3358c171f76p0L, 0x1.0daad547fa22c26d168ea762d854p-88L}, - {0x1.a5503b23e255c8b424491cp0L, 0xa.f87bc8050a405381703ef7caff50p-92L}, - {0x1.a799e1330b3586f2dfb2b0p0L, 0x1.58f1a98796ce8908ae852236ca94p-88L}, - {0x1.a9e6b5579fdbf43eb243bcp0L, 0x1.ff4c4c58b571cf465caf07b4b9f5p-88L}, - {0x1.ac36bbfd3f379c0db966a2p0L, 0x1.1265fc73e480712d20f8597a8e7bp-88L}, - {0x1.ae89f995ad3ad5e8734d16p0L, 0x1.73205a7fbc3ae675ea440b162d6cp-88L}, - {0x1.b0e07298db66590842acdep0L, 0x1.c6f6ca0e5dcae2aafffa7a0554cbp-88L}, - {0x1.b33a2b84f15faf6bfd0e7ap0L, 0x1.d947c2575781dbb49b1237c87b6ep-88L}, - {0x1.b59728de559398e3881110p0L, 0x1.64873c7171fefc410416be0a6525p-88L}, - {0x1.b7f76f2fb5e46eaa7b081ap0L, 0xb.53c5354c8903c356e4b625aacc28p-92L}, - {0x1.ba5b030a10649840cb3c6ap0L, 0xf.5b47f297203757e1cc6eadc8bad0p-92L}, - {0x1.bcc1e904bc1d2247ba0f44p0L, 0x1.b3d08cd0b20287092bd59be4ad98p-88L}, - {0x1.bf2c25bd71e088408d7024p0L, 0x1.18e3449fa073b356766dfb568ff4p-88L}, - {0x1.c199bdd85529c2220cb12ap0L, 0x9.1ba6679444964a36661240043970p-96L}, - {0x1.c40ab5fffd07a6d14df820p0L, 0xf.1828a5366fd387a7bdd54cdf7300p-92L}, - {0x1.c67f12e57d14b4a2137fd2p0L, 0xf.2b301dd9e6b151a6d1f9d5d5f520p-96L}, - {0x1.c8f6d9406e7b511acbc488p0L, 0x5.c442ddb55820171f319d9e5076a8p-96L}, - {0x1.cb720dcef90691503cbd1ep0L, 0x9.49db761d9559ac0cb6dd3ed599e0p-92L}, - {0x1.cdf0b555dc3f9c44f8958ep0L, 0x1.ac51be515f8c58bdfb6f5740a3a4p-88L}, - {0x1.d072d4a07897b8d0f22f20p0L, 0x1.a158e18fbbfc625f09f4cca40874p-88L}, - {0x1.d2f87080d89f18ade12398p0L, 0x9.ea2025b4c56553f5cdee4c924728p-92L}, - {0x1.d5818dcfba48725da05aeap0L, 0x1.66e0dca9f589f559c0876ff23830p-88L}, - {0x1.d80e316c98397bb84f9d04p0L, 0x8.805f84bec614de269900ddf98d28p-92L}, - {0x1.da9e603db3285708c01a5ap0L, 0x1.6d4c97f6246f0ec614ec95c99392p-88L}, - {0x1.dd321f301b4604b695de3cp0L, 0x6.30a393215299e30d4fb73503c348p-96L}, - {0x1.dfc97337b9b5eb968cac38p0L, 0x1.ed291b7225a944efd5bb5524b927p-88L}, - {0x1.e264614f5a128a12761fa0p0L, 0x1.7ada6467e77f73bf65e04c95e29dp-88L}, - {0x1.e502ee78b3ff6273d13014p0L, 0x1.3991e8f49659e1693be17ae1d2f9p-88L}, - {0x1.e7a51fbc74c834b548b282p0L, 0x1.23786758a84f4956354634a416cep-88L}, - {0x1.ea4afa2a490d9858f73a18p0L, 0xf.5db301f86dea20610ceee13eb7b8p-92L}, - {0x1.ecf482d8e67f08db0312fap0L, 0x1.949cef462010bb4bc4ce72a900dfp-88L}, - {0x1.efa1bee615a27771fd21a8p0L, 0x1.2dac1f6dd5d229ff68e46f27e3dfp-88L}, - {0x1.f252b376bba974e8696fc2p0L, 0x1.6390d4c6ad5476b5162f40e1d9a9p-88L}, - {0x1.f50765b6e4540674f84b76p0L, 0x2.862baff99000dfc4352ba29b8908p-92L}, - {0x1.f7bfdad9cbe138913b4bfep0L, 0x7.2bd95c5ce7280fa4d2344a3f5618p-92L}, - {0x1.fa7c1819e90d82e90a7e74p0L, 0xb.263c1dc060c36f7650b4c0f233a8p-92L}, - {0x1.fd3c22b8f71f10975ba4b2p0L, 0x1.2bcf3a5e12d269d8ad7c1a4a8875p-88L} }; -/* - * Kernel for expl(x). x must be finite and not tiny or huge. - * "tiny" is anything that would make us underflow (|A6*x^6| < ~LDBL_MIN). - * "huge" is anything that would make fn*L1 inexact (|x| > ~2**17*ln2). - */ -static inline void -__k_expl(long double x, long double *hip, long double *lop, int *kp) -{ - long double q, r, r1, t; - double dr, fn, r2; - int n, n2; +extern const struct ExplData kExplData[INTERVALS]; - /* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */ - fn = rnint((double)x * INV_L); - n = irint(fn); - n2 = (unsigned)n % INTERVALS; - /* Depend on the sign bit being propagated: */ - *kp = n >> LOG2_INTERVALS; - r1 = x - fn * L1; - r2 = fn * -L2; - r = r1 + r2; - - /* Evaluate expl(endpoint[n2] + r1 + r2) = tbl[n2] * expl(r1 + r2). */ - dr = r; - q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 + - dr * (A7 + dr * (A8 + dr * (A9 + dr * A10)))))))); - t = tbl[n2].lo + tbl[n2].hi; - *hip = tbl[n2].hi; - *lop = tbl[n2].lo + t * (q + r1); -} +void __k_expl(long double , long double *, long double *, int *) _Hide; /* * XXX: the rest of the functions are identical for ld80 and ld128. diff --git a/libc/tinymath/frexp.c b/libc/tinymath/frexp.c index f93725202..c3bad0761 100644 --- a/libc/tinymath/frexp.c +++ b/libc/tinymath/frexp.c @@ -31,7 +31,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /** * Splits number normalized fraction and exponent. @@ -56,3 +56,7 @@ double frexp(double x, int *e) y.i |= 0x3fe0000000000000ull; return y.d; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(frexp, frexpl); +#endif diff --git a/libc/tinymath/frexpl.c b/libc/tinymath/frexpl.c index 30f61d5dd..3d7e6ca45 100644 --- a/libc/tinymath/frexpl.c +++ b/libc/tinymath/frexpl.c @@ -29,6 +29,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/freebsd.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ FreeBSD libm (BSD-2 License)\\n\ @@ -64,3 +65,5 @@ frexpl(long double x, int *ex) } return (u.e); } + +#endif /* long double is long */ diff --git a/libc/tinymath/hypot.c b/libc/tinymath/hypot.c index 5f64d803a..97ca1af9e 100644 --- a/libc/tinymath/hypot.c +++ b/libc/tinymath/hypot.c @@ -99,3 +99,7 @@ double hypot(double x, double y) sq(&hy, &ly, y); return z*sqrt(ly+lx+hy+hx); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(hypot, hypotl); +#endif diff --git a/libc/tinymath/hypotl.c b/libc/tinymath/hypotl.c index 66dd8ecab..d6ec22f82 100644 --- a/libc/tinymath/hypotl.c +++ b/libc/tinymath/hypotl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -34,12 +35,6 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double hypotl(long double x, long double y) -{ - return hypot(x, y); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 #if LDBL_MANT_DIG == 64 #define SPLIT (0x1p32L+1) #elif LDBL_MANT_DIG == 113 @@ -56,6 +51,9 @@ static void sq(long double *hi, long double *lo, long double x) *lo = xh*xh - *hi + 2*xh*xl + xl*xl; } +/** + * Returns euclidean distance. + */ long double hypotl(long double x, long double y) { union ldshape ux = {x}, uy = {y}; @@ -97,6 +95,5 @@ long double hypotl(long double x, long double y) sq(&hy, &ly, y); return z*sqrtl(ly+lx+hy+hx); } -#else -#error "architecture unsupported" -#endif + +#endif /* long double is long */ diff --git a/libc/tinymath/kexpl.c b/libc/tinymath/kexpl.c new file mode 100644 index 000000000..678dca3de --- /dev/null +++ b/libc/tinymath/kexpl.c @@ -0,0 +1,252 @@ +/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ +│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ +╚──────────────────────────────────────────────────────────────────────────────╝ +│ │ +│ FreeBSD lib/msun/src/s_tanhf.c │ +│ Converted to long double by 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 │ +│ 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/tinymath/freebsd.internal.h" + +asm(".ident\t\"\\n\\n\ +FreeBSD libm (BSD-2 License)\\n\ +Copyright (c) 2005-2011, Bruce D. Evans, Steven G. Kargl, David Schultz.\""); +// clang-format off + +/* + * ld128 version of k_expl.h. See ../ld80/s_expl.c for most comments. + * + * See ../src/e_exp.c and ../src/k_exp.h for precision-independent comments + * about the secondary kernels. + */ + +#define INTERVALS 128 +#define LOG2_INTERVALS 7 + +static const double +/* + * ln2/INTERVALS = L1+L2 (hi+lo decomposition for multiplication). L1 must + * have at least 22 (= log2(|LDBL_MIN_EXP-extras|) + log2(INTERVALS)) lowest + * bits zero so that multiplication of it by n is exact. + */ +INV_L = 1.8466496523378731e+2, /* 0x171547652b82fe.0p-45 */ +L2 = -1.0253670638894731e-29; /* -0x1.9ff0342542fc3p-97 */ +static const long double +/* 0x1.62e42fefa39ef35793c768000000p-8 */ +L1 = 5.41521234812457272982212595914567508e-3L; + +/* + * XXX values in hex in comments have been lost (or were never present) + * from here. + */ +static const long double +/* + * Domain [-0.002708, 0.002708], range ~[-2.4021e-38, 2.4234e-38]: + * |exp(x) - p(x)| < 2**-124.9 + * (0.002708 is ln2/(2*INTERVALS) rounded up a little). + * + * XXX the coeffs aren't very carefully rounded, and I get 3.6 more bits. + */ +A2 = 0.5, +A3 = 1.66666666666666666666666666651085500e-1L, +A4 = 4.16666666666666666666666666425885320e-2L, +A5 = 8.33333333333333333334522877160175842e-3L, +A6 = 1.38888888888888888889971139751596836e-3L; + +static const double +A7 = 1.9841269841269470e-4, /* 0x1.a01a01a019f91p-13 */ +A8 = 2.4801587301585286e-5, /* 0x1.71de3ec75a967p-19 */ +A9 = 2.7557324277411235e-6, /* 0x1.71de3ec75a967p-19 */ +A10 = 2.7557333722375069e-7; /* 0x1.27e505ab56259p-22 */ + +const struct ExplData kExplData[INTERVALS] = { + {0x1p0L, 0x0p0L}, + {0x1.0163da9fb33356d84a66aep0L, 0x3.36dcdfa4003ec04c360be2404078p-92L}, + {0x1.02c9a3e778060ee6f7cacap0L, 0x4.f7a29bde93d70a2cabc5cb89ba10p-92L}, + {0x1.04315e86e7f84bd738f9a2p0L, 0xd.a47e6ed040bb4bfc05af6455e9b8p-96L}, + {0x1.059b0d31585743ae7c548ep0L, 0xb.68ca417fe53e3495f7df4baf84a0p-92L}, + {0x1.0706b29ddf6ddc6dc403a8p0L, 0x1.d87b27ed07cb8b092ac75e311753p-88L}, + {0x1.0874518759bc808c35f25cp0L, 0x1.9427fa2b041b2d6829d8993a0d01p-88L}, + {0x1.09e3ecac6f3834521e060cp0L, 0x5.84d6b74ba2e023da730e7fccb758p-92L}, + {0x1.0b5586cf9890f6298b92b6p0L, 0x1.1842a98364291408b3ceb0a2a2bbp-88L}, + {0x1.0cc922b7247f7407b705b8p0L, 0x9.3dc5e8aac564e6fe2ef1d431fd98p-92L}, + {0x1.0e3ec32d3d1a2020742e4ep0L, 0x1.8af6a552ac4b358b1129e9f966a4p-88L}, + {0x1.0fb66affed31af232091dcp0L, 0x1.8a1426514e0b627bda694a400a27p-88L}, + {0x1.11301d0125b50a4ebbf1aep0L, 0xd.9318ceac5cc47ab166ee57427178p-92L}, + {0x1.12abdc06c31cbfb92bad32p0L, 0x4.d68e2f7270bdf7cedf94eb1cb818p-92L}, + {0x1.1429aaea92ddfb34101942p0L, 0x1.b2586d01844b389bea7aedd221d4p-88L}, + {0x1.15a98c8a58e512480d573cp0L, 0x1.d5613bf92a2b618ee31b376c2689p-88L}, + {0x1.172b83c7d517adcdf7c8c4p0L, 0x1.0eb14a792035509ff7d758693f24p-88L}, + {0x1.18af9388c8de9bbbf70b9ap0L, 0x3.c2505c97c0102e5f1211941d2840p-92L}, + {0x1.1a35beb6fcb753cb698f68p0L, 0x1.2d1c835a6c30724d5cfae31b84e5p-88L}, + {0x1.1bbe084045cd39ab1e72b4p0L, 0x4.27e35f9acb57e473915519a1b448p-92L}, + {0x1.1d4873168b9aa7805b8028p0L, 0x9.90f07a98b42206e46166cf051d70p-92L}, + {0x1.1ed5022fcd91cb8819ff60p0L, 0x1.121d1e504d36c47474c9b7de6067p-88L}, + {0x1.2063b88628cd63b8eeb028p0L, 0x1.50929d0fc487d21c2b84004264dep-88L}, + {0x1.21f49917ddc962552fd292p0L, 0x9.4bdb4b61ea62477caa1dce823ba0p-92L}, + {0x1.2387a6e75623866c1fadb0p0L, 0x1.c15cb593b0328566902df69e4de2p-88L}, + {0x1.251ce4fb2a63f3582ab7dep0L, 0x9.e94811a9c8afdcf796934bc652d0p-92L}, + {0x1.26b4565e27cdd257a67328p0L, 0x1.d3b249dce4e9186ddd5ff44e6b08p-92L}, + {0x1.284dfe1f5638096cf15cf0p0L, 0x3.ca0967fdaa2e52d7c8106f2e262cp-92L}, + {0x1.29e9df51fdee12c25d15f4p0L, 0x1.a24aa3bca890ac08d203fed80a07p-88L}, + {0x1.2b87fd0dad98ffddea4652p0L, 0x1.8fcab88442fdc3cb6de4519165edp-88L}, + {0x1.2d285a6e4030b40091d536p0L, 0xd.075384589c1cd1b3e4018a6b1348p-92L}, + {0x1.2ecafa93e2f5611ca0f45cp0L, 0x1.523833af611bdcda253c554cf278p-88L}, + {0x1.306fe0a31b7152de8d5a46p0L, 0x3.05c85edecbc27343629f502f1af2p-92L}, + {0x1.32170fc4cd8313539cf1c2p0L, 0x1.008f86dde3220ae17a005b6412bep-88L}, + {0x1.33c08b26416ff4c9c8610cp0L, 0x1.96696bf95d1593039539d94d662bp-88L}, + {0x1.356c55f929ff0c94623476p0L, 0x3.73af38d6d8d6f9506c9bbc93cbc0p-92L}, + {0x1.371a7373aa9caa7145502ep0L, 0x1.4547987e3e12516bf9c699be432fp-88L}, + {0x1.38cae6d05d86585a9cb0d8p0L, 0x1.bed0c853bd30a02790931eb2e8f0p-88L}, + {0x1.3a7db34e59ff6ea1bc9298p0L, 0x1.e0a1d336163fe2f852ceeb134067p-88L}, + {0x1.3c32dc313a8e484001f228p0L, 0xb.58f3775e06ab66353001fae9fca0p-92L}, + {0x1.3dea64c12342235b41223ep0L, 0x1.3d773fba2cb82b8244267c54443fp-92L}, + {0x1.3fa4504ac801ba0bf701aap0L, 0x4.1832fb8c1c8dbdff2c49909e6c60p-92L}, + {0x1.4160a21f72e29f84325b8ep0L, 0x1.3db61fb352f0540e6ba05634413ep-88L}, + {0x1.431f5d950a896dc7044394p0L, 0x1.0ccec81e24b0caff7581ef4127f7p-92L}, + {0x1.44e086061892d03136f408p0L, 0x1.df019fbd4f3b48709b78591d5cb5p-88L}, + {0x1.46a41ed1d005772512f458p0L, 0x1.229d97df404ff21f39c1b594d3a8p-88L}, + {0x1.486a2b5c13cd013c1a3b68p0L, 0x1.062f03c3dd75ce8757f780e6ec99p-88L}, + {0x1.4a32af0d7d3de672d8bcf4p0L, 0x6.f9586461db1d878b1d148bd3ccb8p-92L}, + {0x1.4bfdad5362a271d4397afep0L, 0xc.42e20e0363ba2e159c579f82e4b0p-92L}, + {0x1.4dcb299fddd0d63b36ef1ap0L, 0x9.e0cc484b25a5566d0bd5f58ad238p-92L}, + {0x1.4f9b2769d2ca6ad33d8b68p0L, 0x1.aa073ee55e028497a329a7333dbap-88L}, + {0x1.516daa2cf6641c112f52c8p0L, 0x4.d822190e718226177d7608d20038p-92L}, + {0x1.5342b569d4f81df0a83c48p0L, 0x1.d86a63f4e672a3e429805b049465p-88L}, + {0x1.551a4ca5d920ec52ec6202p0L, 0x4.34ca672645dc6c124d6619a87574p-92L}, + {0x1.56f4736b527da66ecb0046p0L, 0x1.64eb3c00f2f5ab3d801d7cc7272dp-88L}, + {0x1.58d12d497c7fd252bc2b72p0L, 0x1.43bcf2ec936a970d9cc266f0072fp-88L}, + {0x1.5ab07dd48542958c930150p0L, 0x1.91eb345d88d7c81280e069fbdb63p-88L}, + {0x1.5c9268a5946b701c4b1b80p0L, 0x1.6986a203d84e6a4a92f179e71889p-88L}, + {0x1.5e76f15ad21486e9be4c20p0L, 0x3.99766a06548a05829e853bdb2b52p-92L}, + {0x1.605e1b976dc08b076f592ap0L, 0x4.86e3b34ead1b4769df867b9c89ccp-92L}, + {0x1.6247eb03a5584b1f0fa06ep0L, 0x1.d2da42bb1ceaf9f732275b8aef30p-88L}, + {0x1.6434634ccc31fc76f8714cp0L, 0x4.ed9a4e41000307103a18cf7a6e08p-92L}, + {0x1.66238825522249127d9e28p0L, 0x1.b8f314a337f4dc0a3adf1787ff74p-88L}, + {0x1.68155d44ca973081c57226p0L, 0x1.b9f32706bfe4e627d809a85dcc66p-88L}, + {0x1.6a09e667f3bcc908b2fb12p0L, 0x1.66ea957d3e3adec17512775099dap-88L}, + {0x1.6c012750bdabeed76a9980p0L, 0xf.4f33fdeb8b0ecd831106f57b3d00p-96L}, + {0x1.6dfb23c651a2ef220e2cbep0L, 0x1.bbaa834b3f11577ceefbe6c1c411p-92L}, + {0x1.6ff7df9519483cf87e1b4ep0L, 0x1.3e213bff9b702d5aa477c12523cep-88L}, + {0x1.71f75e8ec5f73dd2370f2ep0L, 0xf.0acd6cb434b562d9e8a20adda648p-92L}, + {0x1.73f9a48a58173bd5c9a4e6p0L, 0x8.ab1182ae217f3a7681759553e840p-92L}, + {0x1.75feb564267c8bf6e9aa32p0L, 0x1.a48b27071805e61a17b954a2dad8p-88L}, + {0x1.780694fde5d3f619ae0280p0L, 0x8.58b2bb2bdcf86cd08e35fb04c0f0p-92L}, + {0x1.7a11473eb0186d7d51023ep0L, 0x1.6cda1f5ef42b66977960531e821bp-88L}, + {0x1.7c1ed0130c1327c4933444p0L, 0x1.937562b2dc933d44fc828efd4c9cp-88L}, + {0x1.7e2f336cf4e62105d02ba0p0L, 0x1.5797e170a1427f8fcdf5f3906108p-88L}, + {0x1.80427543e1a11b60de6764p0L, 0x9.a354ea706b8e4d8b718a672bf7c8p-92L}, + {0x1.82589994cce128acf88afap0L, 0xb.34a010f6ad65cbbac0f532d39be0p-92L}, + {0x1.8471a4623c7acce52f6b96p0L, 0x1.c64095370f51f48817914dd78665p-88L}, + {0x1.868d99b4492ec80e41d90ap0L, 0xc.251707484d73f136fb5779656b70p-92L}, + {0x1.88ac7d98a669966530bcdep0L, 0x1.2d4e9d61283ef385de170ab20f96p-88L}, + {0x1.8ace5422aa0db5ba7c55a0p0L, 0x1.92c9bb3e6ed61f2733304a346d8fp-88L}, + {0x1.8cf3216b5448bef2aa1cd0p0L, 0x1.61c55d84a9848f8c453b3ca8c946p-88L}, + {0x1.8f1ae991577362b982745cp0L, 0x7.2ed804efc9b4ae1458ae946099d4p-92L}, + {0x1.9145b0b91ffc588a61b468p0L, 0x1.f6b70e01c2a90229a4c4309ea719p-88L}, + {0x1.93737b0cdc5e4f4501c3f2p0L, 0x5.40a22d2fc4af581b63e8326efe9cp-92L}, + {0x1.95a44cbc8520ee9b483694p0L, 0x1.a0fc6f7c7d61b2b3a22a0eab2cadp-88L}, + {0x1.97d829fde4e4f8b9e920f8p0L, 0x1.1e8bd7edb9d7144b6f6818084cc7p-88L}, + {0x1.9a0f170ca07b9ba3109b8cp0L, 0x4.6737beb19e1eada6825d3c557428p-92L}, + {0x1.9c49182a3f0901c7c46b06p0L, 0x1.1f2be58ddade50c217186c90b457p-88L}, + {0x1.9e86319e323231824ca78ep0L, 0x6.4c6e010f92c082bbadfaf605cfd4p-92L}, + {0x1.a0c667b5de564b29ada8b8p0L, 0xc.ab349aa0422a8da7d4512edac548p-92L}, + {0x1.a309bec4a2d3358c171f76p0L, 0x1.0daad547fa22c26d168ea762d854p-88L}, + {0x1.a5503b23e255c8b424491cp0L, 0xa.f87bc8050a405381703ef7caff50p-92L}, + {0x1.a799e1330b3586f2dfb2b0p0L, 0x1.58f1a98796ce8908ae852236ca94p-88L}, + {0x1.a9e6b5579fdbf43eb243bcp0L, 0x1.ff4c4c58b571cf465caf07b4b9f5p-88L}, + {0x1.ac36bbfd3f379c0db966a2p0L, 0x1.1265fc73e480712d20f8597a8e7bp-88L}, + {0x1.ae89f995ad3ad5e8734d16p0L, 0x1.73205a7fbc3ae675ea440b162d6cp-88L}, + {0x1.b0e07298db66590842acdep0L, 0x1.c6f6ca0e5dcae2aafffa7a0554cbp-88L}, + {0x1.b33a2b84f15faf6bfd0e7ap0L, 0x1.d947c2575781dbb49b1237c87b6ep-88L}, + {0x1.b59728de559398e3881110p0L, 0x1.64873c7171fefc410416be0a6525p-88L}, + {0x1.b7f76f2fb5e46eaa7b081ap0L, 0xb.53c5354c8903c356e4b625aacc28p-92L}, + {0x1.ba5b030a10649840cb3c6ap0L, 0xf.5b47f297203757e1cc6eadc8bad0p-92L}, + {0x1.bcc1e904bc1d2247ba0f44p0L, 0x1.b3d08cd0b20287092bd59be4ad98p-88L}, + {0x1.bf2c25bd71e088408d7024p0L, 0x1.18e3449fa073b356766dfb568ff4p-88L}, + {0x1.c199bdd85529c2220cb12ap0L, 0x9.1ba6679444964a36661240043970p-96L}, + {0x1.c40ab5fffd07a6d14df820p0L, 0xf.1828a5366fd387a7bdd54cdf7300p-92L}, + {0x1.c67f12e57d14b4a2137fd2p0L, 0xf.2b301dd9e6b151a6d1f9d5d5f520p-96L}, + {0x1.c8f6d9406e7b511acbc488p0L, 0x5.c442ddb55820171f319d9e5076a8p-96L}, + {0x1.cb720dcef90691503cbd1ep0L, 0x9.49db761d9559ac0cb6dd3ed599e0p-92L}, + {0x1.cdf0b555dc3f9c44f8958ep0L, 0x1.ac51be515f8c58bdfb6f5740a3a4p-88L}, + {0x1.d072d4a07897b8d0f22f20p0L, 0x1.a158e18fbbfc625f09f4cca40874p-88L}, + {0x1.d2f87080d89f18ade12398p0L, 0x9.ea2025b4c56553f5cdee4c924728p-92L}, + {0x1.d5818dcfba48725da05aeap0L, 0x1.66e0dca9f589f559c0876ff23830p-88L}, + {0x1.d80e316c98397bb84f9d04p0L, 0x8.805f84bec614de269900ddf98d28p-92L}, + {0x1.da9e603db3285708c01a5ap0L, 0x1.6d4c97f6246f0ec614ec95c99392p-88L}, + {0x1.dd321f301b4604b695de3cp0L, 0x6.30a393215299e30d4fb73503c348p-96L}, + {0x1.dfc97337b9b5eb968cac38p0L, 0x1.ed291b7225a944efd5bb5524b927p-88L}, + {0x1.e264614f5a128a12761fa0p0L, 0x1.7ada6467e77f73bf65e04c95e29dp-88L}, + {0x1.e502ee78b3ff6273d13014p0L, 0x1.3991e8f49659e1693be17ae1d2f9p-88L}, + {0x1.e7a51fbc74c834b548b282p0L, 0x1.23786758a84f4956354634a416cep-88L}, + {0x1.ea4afa2a490d9858f73a18p0L, 0xf.5db301f86dea20610ceee13eb7b8p-92L}, + {0x1.ecf482d8e67f08db0312fap0L, 0x1.949cef462010bb4bc4ce72a900dfp-88L}, + {0x1.efa1bee615a27771fd21a8p0L, 0x1.2dac1f6dd5d229ff68e46f27e3dfp-88L}, + {0x1.f252b376bba974e8696fc2p0L, 0x1.6390d4c6ad5476b5162f40e1d9a9p-88L}, + {0x1.f50765b6e4540674f84b76p0L, 0x2.862baff99000dfc4352ba29b8908p-92L}, + {0x1.f7bfdad9cbe138913b4bfep0L, 0x7.2bd95c5ce7280fa4d2344a3f5618p-92L}, + {0x1.fa7c1819e90d82e90a7e74p0L, 0xb.263c1dc060c36f7650b4c0f233a8p-92L}, + {0x1.fd3c22b8f71f10975ba4b2p0L, 0x1.2bcf3a5e12d269d8ad7c1a4a8875p-88L} +}; + +/* + * Kernel for expl(x). x must be finite and not tiny or huge. + * "tiny" is anything that would make us underflow (|A6*x^6| < ~LDBL_MIN). + * "huge" is anything that would make fn*L1 inexact (|x| > ~2**17*ln2). + */ +void +__k_expl(long double x, long double *hip, long double *lop, int *kp) +{ + long double q, r, r1, t; + double dr, fn, r2; + int n, n2; + + /* Reduce x to (k*ln2 + endpoint[n2] + r1 + r2). */ + fn = rnint((double)x * INV_L); + n = irint(fn); + n2 = (unsigned)n % INTERVALS; + /* Depend on the sign bit being propagated: */ + *kp = n >> LOG2_INTERVALS; + r1 = x - fn * L1; + r2 = fn * -L2; + r = r1 + r2; + + /* Evaluate expl(endpoint[n2] + r1 + r2) = kExplData[n2] * expl(r1 + r2). */ + dr = r; + q = r2 + r * r * (A2 + r * (A3 + r * (A4 + r * (A5 + r * (A6 + + dr * (A7 + dr * (A8 + dr * (A9 + dr * A10)))))))); + t = kExplData[n2].lo + kExplData[n2].hi; + *hip = kExplData[n2].hi; + *lop = kExplData[n2].lo + t * (q + r1); +} diff --git a/libc/tinymath/lgammaf_r.c b/libc/tinymath/lgammaf_r.c index 99f9b5ebf..62f10f5b8 100644 --- a/libc/tinymath/lgammaf_r.c +++ b/libc/tinymath/lgammaf_r.c @@ -35,7 +35,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /* origin: FreeBSD /usr/src/lib/msun/src/e_lgammaf_r.c */ /* diff --git a/libc/tinymath/log.c b/libc/tinymath/log.c index 846fcb2c6..d5f41744e 100644 --- a/libc/tinymath/log.c +++ b/libc/tinymath/log.c @@ -140,3 +140,7 @@ double log(double x) r * r2 * (A[1] + r * A[2] + r2 * (A[3] + r * A[4])) + hi; return eval_as_double(y); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(log, logl); +#endif diff --git a/libc/tinymath/log10.c b/libc/tinymath/log10.c index c09746e9e..88bea6c85 100644 --- a/libc/tinymath/log10.c +++ b/libc/tinymath/log10.c @@ -141,3 +141,7 @@ double log10(double x) return val_lo + val_hi; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(log10, log10l); +#endif diff --git a/libc/tinymath/log10l.c b/libc/tinymath/log10l.c index ac1aaa1a5..0484c04e7 100644 --- a/libc/tinymath/log10l.c +++ b/libc/tinymath/log10l.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/internal.h" +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 asm(".ident\t\"\\n\\n\ OpenBSD libm (ISC License)\\n\ @@ -163,11 +164,7 @@ long double log10l(long double x) : "st(1)"); return x; -#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return log10(x); - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#else long double y, z; int e; @@ -234,12 +231,7 @@ done: z += e * (L102A); return z; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - - long double __log10lq(long double); - return __log10lq(x); - -#else -#error "architecture unsupported" #endif } + +#endif /* ieee80 */ diff --git a/libc/tinymath/log1p.c b/libc/tinymath/log1p.c index 877faa1f1..c5045416f 100644 --- a/libc/tinymath/log1p.c +++ b/libc/tinymath/log1p.c @@ -159,3 +159,7 @@ double log1p(double x) dk = k; return s*(hfsq+R) + (dk*ln2_lo+c) - hfsq + f + dk*ln2_hi; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(log1p, log1pl); +#endif diff --git a/libc/tinymath/log1pl.c b/libc/tinymath/log1pl.c index d846a1df1..acea941da 100644 --- a/libc/tinymath/log1pl.c +++ b/libc/tinymath/log1pl.c @@ -28,6 +28,7 @@ #include "libc/complex.h" #include "libc/math.h" #include "libc/tinymath/complex.internal.h" +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 asm(".ident\t\"\\n\\n\ OpenBSD libm (ISC License)\\n\ @@ -138,12 +139,6 @@ static const long double C2 = 1.4286068203094172321215E-6L; */ long double log1pl(long double xm1) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return log1p(xm1); - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - long double x, y, z; int e; @@ -208,13 +203,6 @@ long double log1pl(long double xm1) z = z + x; z = z + e * C1; return z; - -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - - long double __log1plq(long double); - return __log1plq(xm1); - -#else -#error "architecture unsupported" -#endif } + +#endif /* ieee80 */ diff --git a/libc/tinymath/log2.c b/libc/tinymath/log2.c index 829f7141f..5675c66db 100644 --- a/libc/tinymath/log2.c +++ b/libc/tinymath/log2.c @@ -35,7 +35,7 @@ asm(".ident\t\"\\n\\n\ Double-precision math functions (MIT License)\\n\ Copyright 2018 ARM Limited\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /* * Double-precision log2(x) function. @@ -157,3 +157,7 @@ double log2(double x) y = lo + r2 * p + hi; return eval_as_double(y); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(log2, log2l); +#endif diff --git a/libc/tinymath/log2l.c b/libc/tinymath/log2l.c index 4be575409..5a44f56b8 100644 --- a/libc/tinymath/log2l.c +++ b/libc/tinymath/log2l.c @@ -28,6 +28,7 @@ #include "libc/complex.h" #include "libc/math.h" #include "libc/tinymath/complex.internal.h" +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 asm(".ident\t\"\\n\\n\ OpenBSD libm (ISC License)\\n\ @@ -155,11 +156,7 @@ long double log2l(long double x) : "st(1)"); return x; -#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return log2(x); - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#else long double y, z; int e; @@ -226,12 +223,7 @@ done: z += e; return z; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - - long double __log2lq(long double); - return __log2lq(x); - -#else -#error "architecture unsupported" #endif } + +#endif /* 80-bit floating point */ diff --git a/libc/tinymath/logl.c b/libc/tinymath/logl.c index a3137eb0c..a4d5f6e99 100644 --- a/libc/tinymath/logl.c +++ b/libc/tinymath/logl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/internal.h" +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 asm(".ident\t\"\\n\\n\ OpenBSD libm (ISC License)\\n\ @@ -151,11 +152,7 @@ long double logl(long double x) : "st(1)"); return x; -#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return log(x); - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#else long double y, z; int e; @@ -216,12 +213,7 @@ long double logl(long double x) z = z + e * C1; /* This sum has an error of 1/2 lsb. */ return z; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - - long double __loglq(long double); - return __loglq(x); - -#else -#error "architecture unsupported" #endif } + +#endif /* 80-bit floating point */ diff --git a/libc/tinymath/loglq.c b/libc/tinymath/loglq.c index 386d311bb..f88ea35d9 100644 --- a/libc/tinymath/loglq.c +++ b/libc/tinymath/loglq.c @@ -563,8 +563,11 @@ logl(long double x) RETURN2(rp, val_hi, val_lo); } +/** + * Returns log(𝟷+𝑥). + */ long double -__log1plq(long double x) +log1pl(long double x) { long double d, d_hi, f_lo, val_hi, val_lo; long double f_hi, twopminusk; @@ -674,8 +677,11 @@ __log1plq(long double x) #ifdef STRUCT_RETURN +/** + * Returns natural logarithm of 𝑥. + */ long double -__loglq(long double x) +logl(long double x) { struct ld r; @@ -701,8 +707,11 @@ invln2_lo = 6.33178418956604368501892137426645911e-10L, /* 0x15c17f0bbbe87fed0 invln10_lo_plus_hi = invln10_lo + invln10_hi, invln2_lo_plus_hi = invln2_lo + invln2_hi; +/** + * Calculates log₁₀𝑥. + */ long double -__log10lq(long double x) +log10l(long double x) { struct ld r; long double hi, lo; @@ -719,8 +728,11 @@ __log10lq(long double x) invln10_lo_plus_hi * lo + invln10_lo * hi); } +/** + * Calculates log₂𝑥. + */ long double -__log2lq(long double x) +log2l(long double x) { struct ld r; long double hi, lo; diff --git a/libc/tinymath/lrint.c b/libc/tinymath/lrint.c index 61eab7760..f25c08454 100644 --- a/libc/tinymath/lrint.c +++ b/libc/tinymath/lrint.c @@ -113,3 +113,7 @@ long lrint(double x) return lrint_slow(x); #endif /* __x86_64__ */ } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(lrint, lrintl); +#endif diff --git a/libc/tinymath/lrintl.c b/libc/tinymath/lrintl.c index de6178b63..d07d99183 100644 --- a/libc/tinymath/lrintl.c +++ b/libc/tinymath/lrintl.c @@ -30,6 +30,7 @@ #include "libc/runtime/fenv.h" #include "libc/tinymath/expo.internal.h" #include "libc/tinymath/feval.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -37,10 +38,9 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -long lrintl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return lrint(x); -#elif defined(FE_INEXACT) +long lrintl(long double x) +{ +#ifdef FE_INEXACT /* see comments in lrint.c @@ -61,3 +61,5 @@ raises inexact (with tonearest or upward rounding mode) return rintl(x); #endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/lround.c b/libc/tinymath/lround.c index 3dd8a639d..b18b3dd4a 100644 --- a/libc/tinymath/lround.c +++ b/libc/tinymath/lround.c @@ -24,3 +24,7 @@ long lround(double x) { return round(x); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(lround, lroundl); +#endif diff --git a/libc/tinymath/lroundl.c b/libc/tinymath/lroundl.c index c1a7d32f9..ab27d203e 100644 --- a/libc/tinymath/lroundl.c +++ b/libc/tinymath/lroundl.c @@ -17,7 +17,10 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) long lroundl(long double x) { return roundl(x); } + +#endif /* long double is long */ diff --git a/libc/tinymath/magicu.h b/libc/tinymath/magicu.h index 987c09f16..63d4c7c74 100644 --- a/libc/tinymath/magicu.h +++ b/libc/tinymath/magicu.h @@ -17,7 +17,7 @@ struct magicu __magicu_get(uint32_t); * @param d should be `__magicu_get(y)` if computing `x / y` * @return result of unsigned integer division */ -static inline optimizesize uint32_t __magicu_div(uint32_t x, struct magicu d) { +forceinline uint32_t __magicu_div(uint32_t x, struct magicu d) { return ((((uint64_t)x * d.M) >> 32) + ((d.s & 64) ? x : 0)) >> (d.s & 63); } diff --git a/libc/tinymath/nearbyint.c b/libc/tinymath/nearbyint.c index 4aac23e81..114a410d9 100644 --- a/libc/tinymath/nearbyint.c +++ b/libc/tinymath/nearbyint.c @@ -40,3 +40,7 @@ double nearbyint(double x) { #endif /* __aarch64__ */ return x; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(nearbyint, nearbyintl); +#endif diff --git a/libc/tinymath/nearbyintl.c b/libc/tinymath/nearbyintl.c index 1360a5939..f1838ca00 100644 --- a/libc/tinymath/nearbyintl.c +++ b/libc/tinymath/nearbyintl.c @@ -18,14 +18,12 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/runtime/fenv.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) /** * Rounds to nearest integer. */ long double nearbyintl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return nearbyint(x); -#else #ifdef FE_INEXACT // #pragma STDC FENV_ACCESS ON int e; @@ -36,5 +34,6 @@ long double nearbyintl(long double x) { if (!e) feclearexcept(FE_INEXACT); #endif return x; -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/nextafter.c b/libc/tinymath/nextafter.c index c28b50aeb..f99e08269 100644 --- a/libc/tinymath/nextafter.c +++ b/libc/tinymath/nextafter.c @@ -63,3 +63,7 @@ double nextafter(double x, double y) feval(x*x + ux.f*ux.f); return ux.f; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(nextafter, nextafterl); +#endif diff --git a/libc/tinymath/nextafterl.c b/libc/tinymath/nextafterl.c index 5affcb9d6..d278feeac 100644 --- a/libc/tinymath/nextafterl.c +++ b/libc/tinymath/nextafterl.c @@ -29,6 +29,7 @@ #include "libc/tinymath/feval.internal.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -38,9 +39,7 @@ asm(".include \"libc/disclaimer.inc\""); long double nextafterl(long double x, long double y) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return nextafter(x, y); -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 union ldshape ux, uy; if (isunordered(x, y)) @@ -101,7 +100,7 @@ long double nextafterl(long double x, long double y) if ((ux.i.se & 0x7fff) == 0) FORCE_EVAL(x*x + ux.f*ux.f); return ux.f; -#else -#error "architecture unsupported" #endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/nexttowardl.c b/libc/tinymath/nexttowardl.c index 3afd934a4..00cc93c9b 100644 --- a/libc/tinymath/nexttowardl.c +++ b/libc/tinymath/nexttowardl.c @@ -1,39 +1,23 @@ -/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ -│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ -╚──────────────────────────────────────────────────────────────────────────────╝ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ -│ Musl Libc │ -│ Copyright © 2005-2020 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. │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ │ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" -asm(".ident\t\"\\n\\n\ -Musl libc (MIT License)\\n\ -Copyright 2005-2014 Rich Felker, et. al.\""); -asm(".include \"libc/disclaimer.inc\""); -// clang-format off - -long double nexttowardl(long double x, long double y) -{ - return nextafterl(x, y); +long double nexttowardl(long double x, long double y) { + return nextafterl(x, y); } diff --git a/libc/tinymath/pow.c b/libc/tinymath/pow.c index 45e0d37a9..da9725098 100644 --- a/libc/tinymath/pow.c +++ b/libc/tinymath/pow.c @@ -378,3 +378,8 @@ double pow(double x, double y) #endif return exp_inline(ehi, elo, sign_bias); } + +__weak_reference(pow, __pow_finite); +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(pow, powl); +#endif diff --git a/libc/tinymath/pow10.c b/libc/tinymath/pow10.c deleted file mode 100644 index 8d6037e07..000000000 --- a/libc/tinymath/pow10.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -double pow10(double x) { - return exp10(x); -} diff --git a/libc/tinymath/pow10f.c b/libc/tinymath/pow10f.c deleted file mode 100644 index b12b4945c..000000000 --- a/libc/tinymath/pow10f.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -float pow10f(float x) { - return exp10f(x); -} diff --git a/libc/tinymath/pow10l.c b/libc/tinymath/pow10l.c deleted file mode 100644 index df94fa795..000000000 --- a/libc/tinymath/pow10l.c +++ /dev/null @@ -1,23 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -long double pow10l(long double x) { - return exp10l(x); -} diff --git a/libc/tinymath/powf.c b/libc/tinymath/powf.c index 92ecda64a..b8782ccee 100644 --- a/libc/tinymath/powf.c +++ b/libc/tinymath/powf.c @@ -221,3 +221,5 @@ float powf(float x, float y) } return exp2_inline(ylogx, sign_bias); } + +__weak_reference(powf, __powf_finite); diff --git a/libc/tinymath/powfin.c b/libc/tinymath/powfin.c deleted file mode 100644 index 308a54886..000000000 --- a/libc/tinymath/powfin.c +++ /dev/null @@ -1,30 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/math.h" - -#define powl __powl_finite -#include "libc/tinymath/powl.c" - -double __pow_finite(double x, double y) { - return __powl_finite(x, y); -} - -float __powf_finite(float x, float y) { - return __powl_finite(x, y); -} diff --git a/libc/tinymath/powl.c b/libc/tinymath/powl.c index f51afed48..a39abbd57 100644 --- a/libc/tinymath/powl.c +++ b/libc/tinymath/powl.c @@ -19,6 +19,8 @@ #include "libc/errno.h" #include "libc/math.h" #include "libc/tinymath/internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) + #ifdef __x86_64__ /** @@ -93,7 +95,7 @@ long double powl(long double x, long double y) { } } -#else +#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 asm(".ident\t\"\\n\\n\ OpenBSD libm (ISC License)\\n\ @@ -173,13 +175,6 @@ asm(".include \"libc/disclaimer.inc\""); * */ -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double powl(long double x, long double y) -{ - return pow(x, y); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - /* Table size */ #define NXT 32 @@ -617,6 +612,7 @@ static long double powil(long double x, int nn) y = 1.0/y; return y; } + #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 #include "libc/tinymath/freebsd.internal.h" @@ -1060,8 +1056,8 @@ powl(long double x, long double y) return s * z; } -#else -#error "architecture unsupported" -#endif - #endif /* __x86_64__ */ + +__weak_reference(powl, __powl_finite); + +#endif /* long double is long */ diff --git a/libc/tinymath/remainder.c b/libc/tinymath/remainder.c index c9597440d..e71201f08 100644 --- a/libc/tinymath/remainder.c +++ b/libc/tinymath/remainder.c @@ -18,7 +18,15 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +/** + * Returns remainder of dividing 𝑥 by 𝑦. + */ double remainder(double x, double y) { int q; return remquo(x, y, &q); } + +__strong_reference(remainder, drem); +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(remainder, remainderl); +#endif diff --git a/libc/tinymath/remainderf.c b/libc/tinymath/remainderf.c index 275a9a480..ac807e0db 100644 --- a/libc/tinymath/remainderf.c +++ b/libc/tinymath/remainderf.c @@ -17,8 +17,58 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#include "libc/tinymath/freebsd.internal.h" +// clang-format off + +/** + * Returns remainder of dividing 𝑥 by 𝑦. + */ float remainderf(float x, float y) { int q; return remquof(x, y, &q); } + +static const float zero = 0.0; + +float +remainderf2(float x, float p) +{ + int32_t hx,hp; + uint32_t sx; + float p_half; + + GET_FLOAT_WORD(hx,x); + GET_FLOAT_WORD(hp,p); + sx = hx&0x80000000; + hp &= 0x7fffffff; + hx &= 0x7fffffff; + + /* purge off exception values */ + if((hp==0)|| /* p = 0 */ + (hx>=0x7f800000)|| /* x not finite */ + ((hp>0x7f800000))) /* p is NaN */ + return nan_mix_op(x, p, *)/nan_mix_op(x, p, *); + + + if (hp<=0x7effffff) x = fmodf(x,p+p); /* now x < 2p */ + if ((hx-hp)==0) return zero*x; + x = fabsf(x); + p = fabsf(p); + if (hp<0x01000000) { + if(x+x>p) { + x-=p; + if(x+x>=p) x -= p; + } + } else { + p_half = (float)0.5*p; + if(x>p_half) { + x-=p; + if(x>=p_half) x -= p; + } + } + GET_FLOAT_WORD(hx,x); + if ((hx&0x7fffffff)==0) hx = 0; + SET_FLOAT_WORD(x,hx^sx); + return x; +} diff --git a/libc/tinymath/remainderl.c b/libc/tinymath/remainderl.c index 17b308c4f..8ecbef860 100644 --- a/libc/tinymath/remainderl.c +++ b/libc/tinymath/remainderl.c @@ -17,12 +17,14 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) +/** + * Returns remainder of dividing 𝑥 by 𝑦. + */ long double remainderl(long double x, long double y) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return remainder(x, y); -#else int q; return remquol(x, y, &q); -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/remquo.c b/libc/tinymath/remquo.c index b4a265170..4b69efa07 100644 --- a/libc/tinymath/remquo.c +++ b/libc/tinymath/remquo.c @@ -115,3 +115,7 @@ end: *quo = sx^sy ? -(int)q : (int)q; return sx ? -x : x; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(remquo, remquol); +#endif diff --git a/libc/tinymath/remquol.c b/libc/tinymath/remquol.c index 5d69396b7..678504b81 100644 --- a/libc/tinymath/remquol.c +++ b/libc/tinymath/remquol.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -37,10 +38,8 @@ asm(".include \"libc/disclaimer.inc\""); /** * Computes remainder and part of quotient. */ -long double remquol(long double x, long double y, int *quo) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return remquo(x, y, quo); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +long double remquol(long double x, long double y, int *quo) +{ union ldshape ux = {x}, uy = {y}; int ex = ux.i.se & 0x7fff; int ey = uy.i.se & 0x7fff; @@ -153,7 +152,6 @@ long double remquol(long double x, long double y, int *quo) { q &= 0x7fffffff; *quo = sx^sy ? -(int)q : (int)q; return sx ? -x : x; -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/rint.c b/libc/tinymath/rint.c index bfc972859..f2deb3a21 100644 --- a/libc/tinymath/rint.c +++ b/libc/tinymath/rint.c @@ -58,3 +58,7 @@ double rint(double x) return s ? -0.0 : 0; return y; } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(rint, rintl); +#endif diff --git a/libc/tinymath/rintl.c b/libc/tinymath/rintl.c index 11cd33c38..b8d3450f1 100644 --- a/libc/tinymath/rintl.c +++ b/libc/tinymath/rintl.c @@ -27,6 +27,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -34,10 +35,8 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -long double rintl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return rint(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +long double rintl(long double x) +{ static const long double toint = 1/LDBL_EPSILON; union ldshape u = {x}; @@ -54,7 +53,6 @@ long double rintl(long double x) { if (y == 0) return 0*x; return y; -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/round.c b/libc/tinymath/round.c index c8ab03612..672a76157 100644 --- a/libc/tinymath/round.c +++ b/libc/tinymath/round.c @@ -90,3 +90,7 @@ double round(double x) #endif /* __aarch64__ */ } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(round, roundl); +#endif diff --git a/libc/tinymath/roundl.c b/libc/tinymath/roundl.c index ff6dd3d61..aba71ed7d 100644 --- a/libc/tinymath/roundl.c +++ b/libc/tinymath/roundl.c @@ -28,6 +28,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -35,10 +36,11 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -long double roundl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return round(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 +/** + * Rounds 𝑥 to nearest integer, away from zero. + */ +long double roundl(long double x) +{ static const long double toint = 1/LDBL_EPSILON; union ldshape u = {x}; @@ -63,7 +65,6 @@ long double roundl(long double x) { if (u.i.se >> 15) y = -y; return y; -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/scalb.c b/libc/tinymath/scalb.c index f09b92bcc..cb327a6a4 100644 --- a/libc/tinymath/scalb.c +++ b/libc/tinymath/scalb.c @@ -56,18 +56,18 @@ asm(".include \"libc/disclaimer.inc\""); /** * Returns 𝑥 × 2ʸ. */ -double scalb(double x, double fn) +double scalb(double x, double y) { - if (isunordered(x, fn)) - return x*fn; - if (!isfinite(fn)) { - if (fn > 0.0) - return x*fn; + if (isunordered(x, y)) + return x*y; + if (!isfinite(y)) { + if (y > 0.0) + return x*y; else - return x/(-fn); + return x/(-y); } - if (rint(fn) != fn) return (fn-fn)/(fn-fn); - if ( fn > 65000.0) return scalbn(x, 65000); - if (-fn > 65000.0) return scalbn(x,-65000); - return scalbn(x,(int)fn); + if (rint(y) != y) return (y-y)/(y-y); + if ( y > 65000.0) return scalbn(x, 65000); + if (-y > 65000.0) return scalbn(x,-65000); + return scalbn(x,(int)y); } diff --git a/libc/tinymath/scalbln.c b/libc/tinymath/scalbln.c index 60e0a73b1..c83371f13 100644 --- a/libc/tinymath/scalbln.c +++ b/libc/tinymath/scalbln.c @@ -22,5 +22,9 @@ * Returns 𝑥 × 2ʸ. */ double scalbln(double x, long n) { - return ldexp(x, n > 65536 ? 65536 : n < -65536 ? -65536 : (int)n); + return scalbn(x, n > 65536 ? 65536 : n < -65536 ? -65536 : (int)n); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(scalbln, scalblnl); +#endif diff --git a/libc/tinymath/scalblnf.c b/libc/tinymath/scalblnf.c index dfa88ffaa..67a714428 100644 --- a/libc/tinymath/scalblnf.c +++ b/libc/tinymath/scalblnf.c @@ -22,5 +22,5 @@ * Returns 𝑥 × 2ʸ. */ float scalblnf(float x, long n) { - return ldexpf(x, n); + return scalbnf(x, n); } diff --git a/libc/tinymath/significand.c b/libc/tinymath/significand.c index 9a051d328..d4894fc9d 100644 --- a/libc/tinymath/significand.c +++ b/libc/tinymath/significand.c @@ -18,6 +18,13 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +/** + * Return mantissa of 𝑥 scaled to range [1,2). + */ double significand(double x) { return scalbn(x, -ilogb(x)); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(significand, significandl); +#endif diff --git a/libc/tinymath/significandf.c b/libc/tinymath/significandf.c index 66245f55e..1d6dfef41 100644 --- a/libc/tinymath/significandf.c +++ b/libc/tinymath/significandf.c @@ -18,6 +18,9 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +/** + * Return mantissa of 𝑥 scaled to range [1,2). + */ float significandf(float x) { return scalbnf(x, -ilogbf(x)); } diff --git a/libc/tinymath/significandl.c b/libc/tinymath/significandl.c index 4874f04ea..e9b9496e7 100644 --- a/libc/tinymath/significandl.c +++ b/libc/tinymath/significandl.c @@ -17,7 +17,13 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) +/** + * Return mantissa of 𝑥 scaled to range [1,2). + */ long double significandl(long double x) { return scalbnl(x, -ilogbl(x)); } + +#endif /* long double is long */ diff --git a/libc/tinymath/sin.c b/libc/tinymath/sin.c index fbd5e3486..d6165c569 100644 --- a/libc/tinymath/sin.c +++ b/libc/tinymath/sin.c @@ -121,3 +121,7 @@ double sin(double x) return -__cos(y[0], y[1]); } } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(sin, sinl); +#endif diff --git a/libc/tinymath/sincos.c b/libc/tinymath/sincos.c index d9d07e18d..1bec6f85d 100644 --- a/libc/tinymath/sincos.c +++ b/libc/tinymath/sincos.c @@ -112,3 +112,7 @@ void sincos(double x, double *sin, double *cos) break; } } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(sincos, sincosl); +#endif diff --git a/libc/tinymath/sincosl.c b/libc/tinymath/sincosl.c index e2b0d3122..9d21cde51 100644 --- a/libc/tinymath/sincosl.c +++ b/libc/tinymath/sincosl.c @@ -29,6 +29,7 @@ #include "libc/tinymath/internal.h" #include "libc/tinymath/kernel.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -41,15 +42,6 @@ asm(".include \"libc/disclaimer.inc\""); */ void sincosl(long double x, long double *sin, long double *cos) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - double sind, cosd; - sincos(x, &sind, &cosd); - *sin = sind; - *cos = cosd; - -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - union ldshape u = {x}; unsigned n; long double y[2], s, c; @@ -94,8 +86,6 @@ void sincosl(long double x, long double *sin, long double *cos) *cos = s; break; } - -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/sinl.c b/libc/tinymath/sinl.c index a21013076..e1cfe5941 100644 --- a/libc/tinymath/sinl.c +++ b/libc/tinymath/sinl.c @@ -29,6 +29,7 @@ #include "libc/tinymath/internal.h" #include "libc/tinymath/kernel.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -41,9 +42,6 @@ asm(".include \"libc/disclaimer.inc\""); */ long double sinl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - return sin(x); -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 union ldshape u = {x}; unsigned n; long double y[2], hi, lo; @@ -73,7 +71,6 @@ long double sinl(long double x) default: return -__cosl(hi, lo); } -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/sqrt.c b/libc/tinymath/sqrt.c index ee2d27445..332b4a683 100644 --- a/libc/tinymath/sqrt.c +++ b/libc/tinymath/sqrt.c @@ -220,3 +220,7 @@ double sqrt(double x) #endif /* __x86_64__ */ } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(sqrt, sqrtl); +#endif diff --git a/libc/tinymath/sqrtl.c b/libc/tinymath/sqrtl.c index 2cc268dfa..5b03147a5 100644 --- a/libc/tinymath/sqrtl.c +++ b/libc/tinymath/sqrtl.c @@ -29,6 +29,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -36,13 +37,6 @@ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); // clang-format off -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double sqrtl(long double x) -{ - return sqrt(x); -} -#elif (LDBL_MANT_DIG == 113 || LDBL_MANT_DIG == 64) && LDBL_MAX_EXP == 16384 - #define FENV_SUPPORT 1 typedef struct { @@ -298,6 +292,4 @@ long double sqrtl(long double x) #endif /* __x86__ */ } -#else -#error unsupported long double format -#endif +#endif /* long double is long */ diff --git a/libc/tinymath/tan.c b/libc/tinymath/tan.c index b6702300d..efb25e3a2 100644 --- a/libc/tinymath/tan.c +++ b/libc/tinymath/tan.c @@ -113,3 +113,7 @@ double tan(double x) n = __rem_pio2(x, y); return __tan(y[0], y[1], n&1); } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(tan, tanl); +#endif diff --git a/libc/tinymath/tanl.c b/libc/tinymath/tanl.c index 169520070..cbe1d852d 100644 --- a/libc/tinymath/tanl.c +++ b/libc/tinymath/tanl.c @@ -29,6 +29,7 @@ #include "libc/tinymath/internal.h" #include "libc/tinymath/kernel.internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -41,12 +42,6 @@ asm(".include \"libc/disclaimer.inc\""); */ long double tanl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return tan(x); - -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 - union ldshape u = {x}; long double y[2]; unsigned n; @@ -64,8 +59,6 @@ long double tanl(long double x) } n = __rem_pio2l(x, y); return __tanl(y[0], y[1], n&1); - -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/libc/tinymath/tgamma.c b/libc/tinymath/tgamma.c index b6b0d2aae..0b5ceb997 100644 --- a/libc/tinymath/tgamma.c +++ b/libc/tinymath/tgamma.c @@ -33,7 +33,7 @@ asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ Copyright 2005-2014 Rich Felker, et. al.\""); asm(".include \"libc/disclaimer.inc\""); -/* clang-format off */ +// clang-format off /* "A Precision Approximation of the Gamma Function" - Cornelius Lanczos (1964) @@ -141,6 +141,9 @@ static double S(double x) return num/den; } +/** + * Calculates gamma function of 𝑥. + */ double tgamma(double x) { union {double f; uint64_t i;} u = {x}; diff --git a/libc/calls/kntprioritycombos.internal.h b/libc/tinymath/tinymath.h similarity index 100% rename from libc/calls/kntprioritycombos.internal.h rename to libc/tinymath/tinymath.h diff --git a/libc/tinymath/trunc.c b/libc/tinymath/trunc.c index 9a1216d23..e51aef61a 100644 --- a/libc/tinymath/trunc.c +++ b/libc/tinymath/trunc.c @@ -80,3 +80,7 @@ double trunc(double x) #endif /* __aarch64__ */ } + +#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +__strong_reference(trunc, truncl); +#endif diff --git a/libc/tinymath/truncl.c b/libc/tinymath/truncl.c index 92b71ec3e..343655872 100644 --- a/libc/tinymath/truncl.c +++ b/libc/tinymath/truncl.c @@ -28,6 +28,7 @@ #include "libc/math.h" #include "libc/tinymath/internal.h" #include "libc/tinymath/ldshape.internal.h" +#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024) asm(".ident\t\"\\n\\n\ Musl libc (MIT License)\\n\ @@ -40,11 +41,6 @@ asm(".include \"libc/disclaimer.inc\""); */ long double truncl(long double x) { -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - - return trunc(x); - -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 static const long double toint = 1/LDBL_EPSILON; union ldshape u = {x}; @@ -66,8 +62,6 @@ long double truncl(long double x) y -= 1; x += y; return s ? -x : x; - -#else -#error "architecture unsupported" -#endif } + +#endif /* long double is long */ diff --git a/test/libc/bits/test.mk b/test/libc/bits/test.mk deleted file mode 100755 index e69de29bb..000000000 diff --git a/test/libc/calls/ptrace_test.c b/test/libc/calls/ptrace_test.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/libc/calls/sys_ptrace_test.c b/test/libc/calls/sys_ptrace_test.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/libc/intrin/pthread_spin_lock_test.c b/test/libc/intrin/pthread_spin_lock_test.c index 96531d897..62260f96a 100644 --- a/test/libc/intrin/pthread_spin_lock_test.c +++ b/test/libc/intrin/pthread_spin_lock_test.c @@ -19,7 +19,6 @@ #include "libc/atomic.h" #include "libc/calls/struct/timespec.h" #include "libc/intrin/atomic.h" -#include "libc/intrin/intrin.h" #include "libc/intrin/kprintf.h" #include "libc/testlib/testlib.h" #include "libc/thread/thread.h" diff --git a/test/libc/str/strcmp_test.c b/test/libc/intrin/strcmp_test.c similarity index 86% rename from test/libc/str/strcmp_test.c rename to test/libc/intrin/strcmp_test.c index ada05d0f8..10c47cc7a 100644 --- a/test/libc/str/strcmp_test.c +++ b/test/libc/intrin/strcmp_test.c @@ -544,32 +544,32 @@ BENCH(bench_00_strcmp, bench) { EZBENCH2("strcmp [2 diff]", donothing, EXPROPRIATE(strcmp(VEIL("r", "hi"), VEIL("r", "there")))); - EZBENCH2("strcmp_pure [2 diff]", donothing, + EZBENCH2("scmppure [2 diff]", donothing, EXPROPRIATE(strcmp_pure(VEIL("r", "hi"), VEIL("r", "there")))); EZBENCH2("strcmp [2 dupe]", randomize_buf2str_dupe(2, data, dupe), EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcmp_pure [2 dupe]", randomize_buf2str_dupe(2, data, dupe), + EZBENCH2("scmp_pure [2 dupe]", randomize_buf2str_dupe(2, data, dupe), EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe)))); EZBENCH2("strcmp [4 dupe]", randomize_buf2str_dupe(4, data, dupe), EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcmp_pure [4 dupe]", randomize_buf2str_dupe(4, data, dupe), + EZBENCH2("scmp_pure [4 dupe]", randomize_buf2str_dupe(4, data, dupe), EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe)))); EZBENCH2("strcmp [8 dupe]", randomize_buf2str_dupe(8, data, dupe), EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcmp_pure [8 dupe]", randomize_buf2str_dupe(8, data, dupe), + EZBENCH2("scmp_pure [8 dupe]", randomize_buf2str_dupe(8, data, dupe), EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe)))); EZBENCH2("strcmp [sdupe]", randomize_buf2str_dupe(size, data, dupe), EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe), + EZBENCH2("scmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe), EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe)))); EZBENCH2("strcmp [ldupe]", longstringislong_dupe(size, data, dupe), EXPROPRIATE(strcmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcmp_pure [ldupe]", longstringislong_dupe(size, data, dupe), + EZBENCH2("scmp_pure [ldupe]", longstringislong_dupe(size, data, dupe), EXPROPRIATE(strcmp_pure(VEIL("r", data), VEIL("r", dupe)))); } @@ -580,17 +580,17 @@ BENCH(bench_01_strcasecmp, bench) { data = gc(malloc(size)); dupe = gc(malloc(size)); - EZBENCH2("strcasecmp [identity]", longstringislong(size, data), + EZBENCH2("strcasecmp [iden]", longstringislong(size, data), EXPROPRIATE(strcasecmp(VEIL("r", data), data))); EZBENCH2("strcasecmp [sdupe]", randomize_buf2str_dupe(size, data, dupe), EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcasecmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe), + EZBENCH2("sccmp_pure [sdupe]", randomize_buf2str_dupe(size, data, dupe), EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe)))); EZBENCH2("strcasecmp [ldupe]", longstringislong_dupe(size, data, dupe), EXPROPRIATE(strcasecmp(VEIL("r", data), VEIL("r", dupe)))); - EZBENCH2("strcasecmp_pure [ldupe]", longstringislong_dupe(size, data, dupe), + EZBENCH2("sccmp_pure [ldupe]", longstringislong_dupe(size, data, dupe), EXPROPRIATE(strcasecmp_pure(VEIL("r", data), VEIL("r", dupe)))); } @@ -602,3 +602,49 @@ BENCH(memcmp, bench) { EZBENCH2("memcmp 18", donothing, EXPROPRIATE(memcmp("tough little ship", copy, 18))); } + +/* jart + * strcmp [identity] l: 3c 1ns m: 30c 10ns + * strcmp [2 diff] l: 4c 1ns m: 30c 10ns + * scmppure [2 diff] l: 3c 1ns m: 31c 10ns + * strcmp [2 dupe] l: 8c 3ns m: 39c 13ns + * scmp_pure [2 dupe] l: 6c 2ns m: 34c 11ns + * strcmp [4 dupe] l: 9c 3ns m: 40c 13ns + * scmp_pure [4 dupe] l: 9c 3ns m: 38c 12ns + * strcmp [8 dupe] l: 10c 3ns m: 40c 13ns + * scmp_pure [8 dupe] l: 11c 4ns m: 41c 13ns + * strcmp [sdupe] l: 87c 28ns m: 121c 39ns + * scmp_pure [sdupe] l: 188c 61ns m: 294c 95ns + * strcmp [ldupe] l: 3,458c 1,117ns m: 3,486c 1,126ns + * scmp_pure [ldupe] l: 11,441c 3,695ns m: 11,520c 3,721ns + * strcasecmp [iden] l: 3c 1ns m: 30c 10ns + * strcasecmp [sdupe] l: 105c 34ns m: 156c 50ns + * sccmp_pure [sdupe] l: 644c 208ns m: 963c 311ns + * strcasecmp [ldupe] l: 36,527c 11,798ns m: 36,582c 11,816ns + * sccmp_pure [ldupe] l: 365,880c 118,177ns m: 365,721c 118,125ns + * memcmp big l: 2,050c 662ns m: 2,093c 676ns + * memcmp 18 l: 6c 2ns m: 35c 11ns + */ + +/* jart+intel + * strcmp [identity] l: 1c 0ns m: 28c 9ns + * strcmp [2 diff] l: 2c 1ns m: 29c 9ns + * scmppure [2 diff] l: 2c 1ns m: 29c 9ns + * strcmp [2 dupe] l: 8c 3ns m: 40c 13ns + * scmp_pure [2 dupe] l: 5c 2ns m: 32c 10ns + * strcmp [4 dupe] l: 9c 3ns m: 41c 13ns + * scmp_pure [4 dupe] l: 7c 2ns m: 34c 11ns + * strcmp [8 dupe] l: 10c 3ns m: 40c 13ns + * scmp_pure [8 dupe] l: 10c 3ns m: 39c 13ns + * strcmp [sdupe] l: 57c 18ns m: 87c 28ns + * scmp_pure [sdupe] l: 191c 62ns m: 224c 72ns + * strcmp [ldupe] l: 1,667c 538ns m: 1,708c 552ns + * scmp_pure [ldupe] l: 10,988c 3,549ns m: 11,055c 3,571ns + * strcasecmp [iden] l: 2c 1ns m: 31c 10ns + * strcasecmp [sdupe] l: 121c 39ns m: 160c 52ns + * sccmp_pure [sdupe] l: 684c 221ns m: 702c 227ns + * strcasecmp [ldupe] l: 34,325c 11,087ns m: 35,954c 11,613ns + * sccmp_pure [ldupe] l: 361,449c 116,746ns m: 366,022c 118,223ns + * memcmp big l: 2,040c 659ns m: 2,083c 673ns + * memcmp 18 l: 5c 2ns m: 35c 11ns + */ diff --git a/test/libc/str/strnlen_test.c b/test/libc/str/strnlen_test.c deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/libc/tinymath/cosh_test.c b/test/libc/tinymath/cosh_test.c index 921bcbf7c..0b6724665 100644 --- a/test/libc/tinymath/cosh_test.c +++ b/test/libc/tinymath/cosh_test.c @@ -18,6 +18,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/math.h" #include "libc/mem/gc.internal.h" +#include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" #include "libc/x/x.h" @@ -60,3 +61,9 @@ TEST(coshf, test) { EXPECT_STREQ("INFINITY", gc(xdtoaf(_coshf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_coshf(-INFINITY)))); } + +BENCH(cosh, bench) { + EZBENCH2("cosh", donothing, _cosh(.7)); // ~6ns + EZBENCH2("coshf", donothing, _coshf(.7)); // ~5ns + EZBENCH2("coshl", donothing, _coshl(.7)); // ~25ns +} diff --git a/test/libc/tinymath/exp_test.c b/test/libc/tinymath/exp_test.c index 62dc2e3bd..6a301b5ba 100644 --- a/test/libc/tinymath/exp_test.c +++ b/test/libc/tinymath/exp_test.c @@ -64,7 +64,7 @@ TEST(exp, fun) { ASSERT_STREQ("6.389056", _gc(xasprintf("%f", _exp(2.0) - 1.0))); } -BENCH(_expl, bench) { +BENCH(expl, bench) { EZBENCH2("exp", donothing, _exp(.7)); /* ~6ns */ EZBENCH2("expf", donothing, _expf(.7)); /* ~5ns */ EZBENCH2("expl", donothing, _expl(.7)); /* ~20ns */ diff --git a/test/libc/tinymath/remainder_test.c b/test/libc/tinymath/remainder_test.c new file mode 100644 index 000000000..c8eb912f5 --- /dev/null +++ b/test/libc/tinymath/remainder_test.c @@ -0,0 +1,112 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2023 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/assert.h" +#include "libc/fmt/conv.h" +#include "libc/intrin/kprintf.h" +#include "libc/math.h" +#include "libc/mem/gc.h" +#include "libc/runtime/runtime.h" +#include "libc/testlib/ezbench.h" +#include "libc/testlib/testlib.h" +#include "libc/tinymath/tinymath.h" +#include "libc/x/x.h" + +float remainderf2(float, float); +double _remainder(double, double) asm("remainder"); +float _remainderf(float, float) asm("remainderf"); +long double _remainderl(long double, long double) asm("remainderl"); + +TEST(remainder, test) { + EXPECT_TRUE(isnan(_remainder(7, NAN))); + EXPECT_TRUE(isnan(_remainder(NAN, 7))); + EXPECT_TRUE(isnan(_remainder(INFINITY, 7))); + EXPECT_TRUE(isnan(_remainder(7, 0))); + EXPECT_STREQ("-1", _gc(xdtoa(_remainder(7, 4)))); +} + +TEST(remainderf, test) { + EXPECT_TRUE(isnan(_remainderf(7, NAN))); + EXPECT_TRUE(isnan(_remainderf(NAN, 7))); + EXPECT_TRUE(isnan(_remainderf(INFINITY, 7))); + EXPECT_TRUE(isnan(_remainderf(7, 0))); + EXPECT_STREQ("-1", _gc(xdtoaf(_remainderf(7, 4)))); +} + +TEST(remainderl, test) { + EXPECT_TRUE(isnan(_remainderl(7, NAN))); + EXPECT_TRUE(isnan(_remainderl(NAN, 7))); + EXPECT_TRUE(isnan(_remainderl(INFINITY, 7))); + EXPECT_TRUE(isnan(_remainderl(7, 0))); + EXPECT_STREQ("-1", _gc(xdtoal(_remainderl(7, 4)))); +} + +static inline float i2f(uint32_t i) { + union { + uint32_t i; + float f; + } u = {i}; + return u.f; +} + +static inline uint32_t f2i(float f) { + union { + float f; + uint32_t i; + } u = {f}; + return u.i; +} + +BENCH(remainder, bench) { + EZBENCH2("remainder", donothing, _remainder(7, 3)); // ~20ns + EZBENCH2("remainderf", donothing, _remainderf(7, 3)); // ~20ns + EZBENCH2("remainderl", donothing, _remainderl(7, 3)); // ~169ns +} + +#if 0 +TEST(remainderf, brute) { + long i, j; + float a, b; + int lim = 100; + uint32_t x, y; + for (i = 0; i <= 0x100000000; i += 1048573) { + for (j = 0; j <= 0x100000000; j += 1048573) { + a = remainderf(i2f(i), i2f(j)); + b = remainderf2(i2f(i), i2f(j)); + if (isunordered(a, b)) { + assert(isnan(a) == isnan(b)); + assert(isfinite(a) == isfinite(b)); + continue; + } + x = f2i(a); + y = f2i(b); + if (abs(x - y) > 1) { + kprintf("bah %#lx %s %#lx %d\n", i, _gc(xdtoaf(i2f(i))), j, + _gc(xdtoaf(i2f(j))), abs(x - y)); + kprintf(" %-12s %#x\n", _gc(xdtoaf(i2f(x))), x); + kprintf(" %-12s %#x\n", _gc(xdtoaf(i2f(y))), y); + if (!--lim) break; + } + } + kprintf("%ld\r", i); + } + if (lim != 100) { + exit(1); + } +} +#endif diff --git a/test/tool/build/lib/xlaterrno_test.c b/test/tool/build/lib/xlaterrno_test.c index 9e5aa2ad5..9d41acf49 100644 --- a/test/tool/build/lib/xlaterrno_test.c +++ b/test/tool/build/lib/xlaterrno_test.c @@ -19,7 +19,6 @@ #include "libc/errno.h" #include "libc/testlib/testlib.h" #include "tool/build/lib/xlat.h" -#include "tool/build/lib/xlaterrno.h" TEST(xlaterrno, test) { EXPECT_EQ(95, XlatErrno(EOPNOTSUPP)); diff --git a/third_party/ggml/common.cc b/third_party/ggml/common.cc index ed4c1fc6b..e9f95ed1f 100644 --- a/third_party/ggml/common.cc +++ b/third_party/ggml/common.cc @@ -685,7 +685,7 @@ int put_codepoint(console_state & con_st, const char* utf8_codepoint, size_t len if (width < 0) { // Calculate the width considering text wrapping struct winsize w; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + tcgetwinsize(STDOUT_FILENO, &w); width += w.ws_col; } return width; diff --git a/third_party/ggml/fp16.c b/third_party/ggml/fp16.c index ab71cb955..2491addd9 100644 --- a/third_party/ggml/fp16.c +++ b/third_party/ggml/fp16.c @@ -85,7 +85,7 @@ void ggml_fp16_to_fp32_row(const ggml_fp16_t * x, float * y, size_t n) { void ggml_fp32_to_fp16_row(const float * x, ggml_fp16_t * y, size_t n) { size_t i = 0; -#if defined(__F16C__) +#ifdef __F16C__ for (; i + 7 < n; i += 8) { __m256 x_vec = _mm256_loadu_ps(x + i); __m128i y_vec = _mm256_cvtps_ph(x_vec, _MM_FROUND_TO_NEAREST_INT); diff --git a/third_party/ggml/ggml.c b/third_party/ggml/ggml.c index b0c375612..aefd4f9ce 100644 --- a/third_party/ggml/ggml.c +++ b/third_party/ggml/ggml.c @@ -48,6 +48,7 @@ #include "libc/assert.h" #include "libc/assert.h" #include "third_party/ggml/ggml.h" +#include "libc/intrin/bsr.h" #include "third_party/libcxx/math.h" asm(".ident\t\"\\n\\n\ @@ -8096,10 +8097,10 @@ static void ggml_compute_forward_alibi_f32( assert(ne1 + n_past == ne0); (void) n_past; // add alibi to src0 (KQ_scaled) - const int n_heads_log2_floor = 1 << (int) floor(log2(n_head)); + const int n_heads_log2_floor = 1 << _bsr(n_head); - const float m0 = powf(2.0f, -8.0f / n_heads_log2_floor); - const float m1 = powf(2.0f, -4.0f / n_heads_log2_floor); + const float m0 = exp2f(-8.0f / n_heads_log2_floor); + const float m1 = exp2f(-4.0f / n_heads_log2_floor); for (int i = 0; i < ne0; i++) { for (int j = 0; j < ne1; j++) { @@ -8157,10 +8158,10 @@ static void ggml_compute_forward_alibi_f16( assert(ne1 + n_past == ne0); (void) n_past; // add alibi to src0 (KQ_scaled) - const int n_heads_log2_floor = 1 << (int) floor(log2(n_head)); + const int n_heads_log2_floor = 1 << _bsr(n_head); - const float m0 = powf(2.0f, -8.0f / n_heads_log2_floor); - const float m1 = powf(2.0f, -4.0f / n_heads_log2_floor); + const float m0 = exp2f(-8.0f / n_heads_log2_floor); + const float m1 = exp2f(-4.0f / n_heads_log2_floor); for (int i = 0; i < ne0; i++) { for (int j = 0; j < ne1; j++) { diff --git a/third_party/ggml/ggml.mk b/third_party/ggml/ggml.mk index df6b6450f..e1c768350 100644 --- a/third_party/ggml/ggml.mk +++ b/third_party/ggml/ggml.mk @@ -99,12 +99,23 @@ endif THIRD_PARTY_GGML_ARTIFACTS += THIRD_PARTY_GGML_LLAMA THIRD_PARTY_GGML_LLAMA = o/$(MODE)/third_party/ggml/llama.com -THIRD_PARTY_GGML_LLAMA_HDRS = third_party/ggml/llama.h third_party/ggml/llama_util.h third_party/ggml/common.h -THIRD_PARTY_GGML_LLAMA_SRCS = third_party/ggml/main.cc third_party/ggml/llama.cc third_party/ggml/common.cc THIRD_PARTY_GGML_LLAMA_OBJS = $(THIRD_PARTY_GGML_LLAMA_SRCS:%.cc=o/$(MODE)/%.o) THIRD_PARTY_GGML_LLAMA_FILES := $(THIRD_PARTY_GGML_LLAMA_SRCS) $(THIRD_PARTY_GGML_LLAMA_HDRS) THIRD_PARTY_GGML_LLAMA_CHECKS = $(THIRD_PARTY_GGML_LLAMA).pkg $(THIRD_PARTY_GGML_LLAMA_HDRS:%=o/$(MODE)/%.okk) +THIRD_PARTY_GGML_LLAMA_HDRS = \ + third_party/ggml/common.cc \ + third_party/ggml/llama.h \ + third_party/ggml/llama_util.h \ + third_party/ggml/common.h + +THIRD_PARTY_GGML_LLAMA_SRCS = \ + third_party/ggml/main.cc \ + third_party/ggml/llama.cc \ + third_party/ggml/common.cc \ + third_party/ggml/quantize.cc \ + third_party/ggml/perplexity.cc + THIRD_PARTY_GGML_LLAMA_DIRECTDEPS = \ LIBC_CALLS \ LIBC_FMT \ @@ -137,6 +148,26 @@ $(THIRD_PARTY_GGML_LLAMA).dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) +o/$(MODE)/third_party/ggml/quantize.com.dbg: \ + $(THIRD_PARTY_GGML_LLAMA).pkg \ + $(THIRD_PARTY_GGML_LLAMA_DEPS) \ + o/$(MODE)/third_party/ggml/common.o \ + o/$(MODE)/third_party/ggml/llama.o \ + o/$(MODE)/third_party/ggml/quantize.o \ + $(CRT) \ + $(APE_NO_MODIFY_SELF) + @$(APELINK) + +o/$(MODE)/third_party/ggml/perplexity.com.dbg: \ + $(THIRD_PARTY_GGML_LLAMA).pkg \ + $(THIRD_PARTY_GGML_LLAMA_DEPS) \ + o/$(MODE)/third_party/ggml/common.o \ + o/$(MODE)/third_party/ggml/llama.o \ + o/$(MODE)/third_party/ggml/perplexity.o \ + $(CRT) \ + $(APE_NO_MODIFY_SELF) + @$(APELINK) + $(THIRD_PARTY_GGML_LLAMA).pkg: \ $(THIRD_PARTY_GGML_LLAMA_OBJS) \ $(foreach x,$(THIRD_PARTY_GGML_LLAMA_DIRECTDEPS),$($(x)_A).pkg) @@ -147,7 +178,10 @@ o/$(MODE)/third_party/ggml/companionai.txt.zip.o: private \ ################################################################################ -THIRD_PARTY_GGML_COMS = $(THIRD_PARTY_GGML_LLAMA) +THIRD_PARTY_GGML_COMS = \ + $(THIRD_PARTY_GGML_LLAMA) \ + o/$(MODE)/third_party/ggml/perplexity.com + THIRD_PARTY_GGML_BINS = $(THIRD_PARTY_GGML_COMS) $(THIRD_PARTY_GGML_COMS:%=%.dbg) THIRD_PARTY_GGML_LIBS = $(foreach x,$(THIRD_PARTY_GGML_ARTIFACTS),$($(x))) THIRD_PARTY_GGML_SRCS = $(foreach x,$(THIRD_PARTY_GGML_ARTIFACTS),$($(x)_SRCS)) diff --git a/third_party/ggml/perplexity.cc b/third_party/ggml/perplexity.cc new file mode 100644 index 000000000..0e54f40b3 --- /dev/null +++ b/third_party/ggml/perplexity.cc @@ -0,0 +1,197 @@ +/*-*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-│ +│vi: set net ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi│ +╚──────────────────────────────────────────────────────────────────────────────╝ +│ │ +│ llama.com │ +│ Copyright (c) 2023 Georgi Gerganov │ +│ │ +│ 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 "third_party/ggml/common.h" +#include "third_party/ggml/llama.h" +#include "third_party/libcxx/vector" + +asm(".ident\t\"\\n\\n\ +llama.cpp (MIT License)\\n\ +Copyright (c) 2023 Georgi Gerganov\""); +asm(".include \"libc/disclaimer.inc\""); +// clang-format off + +std::vector softmax(const std::vector& logits) { + std::vector probs(logits.size()); + float max_logit = logits[0]; + for (float v : logits) max_logit = std::max(max_logit, v); + double sum_exp = 0.0; + for (size_t i = 0; i < logits.size(); i++) { + // Subtract the maximum logit value from the current logit value for numerical stability + const float logit = logits[i] - max_logit; + const float exp_logit = expf(logit); + sum_exp += exp_logit; + probs[i] = exp_logit; + } + for (size_t i = 0; i < probs.size(); i++) probs[i] /= sum_exp; + return probs; +} + +void perplexity(llama_context * ctx, const gpt_params & params) { + // Download: https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-raw-v1.zip?ref=salesforce-research + // Run `./perplexity -m models/7B/ggml-model-q4_0.bin -f wiki.test.raw` + // Output: `perplexity: 13.5106 [114/114]` + // BOS tokens will be added for each chunk before eval + auto tokens = ::llama_tokenize(ctx, params.prompt, true); + + int count = 0; + + const int n_chunk = tokens.size() / params.n_ctx; + const int n_vocab = llama_n_vocab(ctx); + const int n_batch = params.n_batch; + + double nll = 0.0; + fprintf(stderr, "%s: calculating perplexity over %d chunks, batch_size=%d\n", __func__, n_chunk, n_batch); + + for (int i = 0; i < n_chunk; ++i) { + const int start = i * params.n_ctx; + const int end = start + params.n_ctx; + + const int num_batches = (params.n_ctx + n_batch - 1) / n_batch; + + std::vector logits; + + const auto t_start = std::chrono::high_resolution_clock::now(); + + for (int j = 0; j < num_batches; ++j) { + const int batch_start = start + j * n_batch; + const int batch_size = std::min(end - batch_start, n_batch); + + // save original token and restore it after eval + const auto token_org = tokens[batch_start]; + + // add BOS token for the first batch of each chunk + if (j == 0) { + tokens[batch_start] = llama_token_bos(); + } + + if (llama_eval(ctx, tokens.data() + batch_start, batch_size, j * n_batch, params.n_threads)) { + fprintf(stderr, "%s : failed to eval\n", __func__); + return; + } + + // restore the original token in case it was set to BOS + tokens[batch_start] = token_org; + + const auto batch_logits = llama_get_logits(ctx); + logits.insert(logits.end(), batch_logits, batch_logits + batch_size * n_vocab); + } + + const auto t_end = std::chrono::high_resolution_clock::now(); + + if (i == 0) { + const float t_total = std::chrono::duration(t_end - t_start).count(); + fprintf(stderr, "%s: %.2f seconds per pass - ETA ", __func__, t_total); + int total_seconds = (int)(t_total * n_chunk); + if (total_seconds >= 60*60) { + fprintf(stderr, "%d hours ", total_seconds / (60*60)); + total_seconds = total_seconds % (60*60); + } + fprintf(stderr, "%d minutes\n", total_seconds / 60); + } + + // We get the logits for all the tokens in the context window (params.n_ctx) + // from llama_eval above. Now, based on https://huggingface.co/docs/transformers/perplexity, + // calculate the perplexity over the last half of the window (so the model always has + // some context to predict the token). + // + // We rely on the fact that attention in the forward pass only looks at previous + // tokens here, so the logits returned for each token are an accurate representation + // of what the model would have predicted at that point. + // + // Example, we have a context window of 512, we will compute perplexity for each of the + // last 256 tokens. Then, we split the input up into context window size chunks to + // process the entire prompt. + for (int j = std::min(512, params.n_ctx / 2); j < params.n_ctx - 1; ++j) { + // Calculate probability of next token, given the previous ones. + const std::vector tok_logits( + logits.begin() + (j + 0) * n_vocab, + logits.begin() + (j + 1) * n_vocab); + + const float prob = softmax(tok_logits)[tokens[start + j + 1]]; + + nll += -std::log(prob); + ++count; + } + // perplexity is e^(average negative log-likelihood) + printf("[%d]%.4lf,", i + 1, std::exp(nll / count)); + fflush(stdout); + } + printf("\n"); +} + +int main(int argc, char ** argv) { + gpt_params params; + params.model = "models/llama-7B/ggml-model.bin"; + + params.n_batch = 512; + if (gpt_params_parse(argc, argv, params) == false) { + return 1; + } + + params.perplexity = true; + params.n_batch = std::min(params.n_batch, params.n_ctx); + + if (params.n_ctx > 2048) { + fprintf(stderr, "%s: warning: model does not support context sizes greater than 2048 tokens (%d specified);" + "expect poor results\n", __func__, params.n_ctx); + } + + if (params.seed < 0) { + params.seed = time(NULL); + } + + fprintf(stderr, "%s: seed = %d\n", __func__, params.seed); + + std::mt19937 rng(params.seed); + if (params.random_prompt) { + params.prompt = gpt_random_prompt(rng); + } + + llama_context * ctx; + + // load the model and apply lora adapter, if any + ctx = llama_init_from_gpt_params(params); + if (ctx == NULL) { + fprintf(stderr, "%s: error: unable to load model\n", __func__); + return 1; + } + + // print system information + { + fprintf(stderr, "\n"); + fprintf(stderr, "system_info: n_threads = %d / %d | %s\n", + params.n_threads, std::thread::hardware_concurrency(), llama_print_system_info()); + } + + perplexity(ctx, params); + + llama_print_timings(ctx); + llama_free(ctx); + + return 0; +} diff --git a/third_party/ggml/quantize.cc b/third_party/ggml/quantize.cc new file mode 100644 index 000000000..fe5a0c8f5 --- /dev/null +++ b/third_party/ggml/quantize.cc @@ -0,0 +1,175 @@ +/*-*-mode:c++;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8-*-│ +│vi: set net ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi│ +╚──────────────────────────────────────────────────────────────────────────────╝ +│ │ +│ llama.com │ +│ Copyright (c) 2023 Georgi Gerganov │ +│ │ +│ 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 "third_party/ggml/common.h" +#include "third_party/ggml/ggml.h" +#include "third_party/ggml/llama.h" +#include "third_party/libcxx/map" +#include "third_party/libcxx/vector" + +asm(".ident\t\"\\n\\n\ +llama.cpp (MIT License)\\n\ +Copyright (c) 2023 Georgi Gerganov\""); +asm(".include \"libc/disclaimer.inc\""); +// clang-format off + +static const std::map LLAMA_FTYPE_MAP = { + {"q4_0", LLAMA_FTYPE_MOSTLY_Q4_0}, + {"q4_1", LLAMA_FTYPE_MOSTLY_Q4_1}, + {"q4_2", LLAMA_FTYPE_MOSTLY_Q4_2}, + {"q5_0", LLAMA_FTYPE_MOSTLY_Q5_0}, + {"q5_1", LLAMA_FTYPE_MOSTLY_Q5_1}, + {"q8_0", LLAMA_FTYPE_MOSTLY_Q8_0}, +}; + +bool try_parse_ftype(const std::string & ftype_str, llama_ftype & ftype, std::string & ftype_str_out) { + auto it = LLAMA_FTYPE_MAP.find(ftype_str); + if (it != LLAMA_FTYPE_MAP.end()) { + ftype = it->second; + ftype_str_out = it->first; + return true; + } + // try to parse as an integer + // try { + int ftype_int = std::stoi(ftype_str); + for (auto it = LLAMA_FTYPE_MAP.begin(); it != LLAMA_FTYPE_MAP.end(); it++) { + if (it->second == ftype_int) { + ftype = it->second; + ftype_str_out = it->first; + return true; + } + } + // } + // catch (...) { + // // stoi failed + // } + return false; +} + +// usage: +// ./quantize models/llama/ggml-model.bin [models/llama/ggml-model-quant.bin] type [nthreads] +// +int main(int argc, char ** argv) { + ggml_time_init(); + + if (argc < 3) { + fprintf(stderr, "usage: %s model-f32.bin [model-quant.bin] type [nthreads]\n", argv[0]); + for (auto it = LLAMA_FTYPE_MAP.begin(); it != LLAMA_FTYPE_MAP.end(); it++) { + fprintf(stderr, " type = \"%s\" or %d\n", it->first.c_str(), it->second); + } + return 1; + } + + // needed to initialize f16 tables + { + struct ggml_init_params params = { 0, NULL, false }; + struct ggml_context * ctx = ggml_init(params); + ggml_free(ctx); + } + + // parse command line arguments + const std::string fname_inp = argv[1]; + std::string fname_out; + int nthread; + llama_ftype ftype; + + int arg_idx = 2; + std::string ftype_str; + if (try_parse_ftype(argv[arg_idx], ftype, ftype_str)) { + // argv[2] is the ftype + std::string fpath; + const size_t pos = fname_inp.find_last_of('/'); + if (pos != std::string::npos) { + fpath = fname_inp.substr(0, pos + 1); + } + // export as [inp path]/ggml-model-[ftype].bin + fname_out = fpath + "ggml-model-" + ftype_str + ".bin"; + arg_idx++; + } + else { + // argv[2] is the output path + fname_out = argv[arg_idx]; + arg_idx++; + + if (argc <= arg_idx) { + fprintf(stderr, "%s: missing ftype\n", __func__); + return 1; + } + // argv[3] is the ftype + if (!try_parse_ftype(argv[arg_idx], ftype, ftype_str)) { + fprintf(stderr, "%s: invalid ftype '%s'\n", __func__, argv[3]); + return 1; + } + arg_idx++; + } + + // parse nthreads + if (argc > arg_idx) { + // try { + nthread = std::stoi(argv[arg_idx]); + // } + // catch (const std::exception & e) { + // Die("%s: invalid nthread '%s' (%s)\n", __func__, argv[arg_idx], e.what()); + // return 1; + // } + } else { + nthread = 0; + } + + fprintf(stderr, "%s: quantizing '%s' to '%s' as %s", __func__, fname_inp.c_str(), fname_out.c_str(), ftype_str.c_str()); + if (nthread > 0) { + fprintf(stderr, " using %d threads", nthread); + } + fprintf(stderr, "\n"); + + const int64_t t_main_start_us = ggml_time_us(); + + int64_t t_quantize_us = 0; + + // load the model + { + const int64_t t_start_us = ggml_time_us(); + + if (llama_model_quantize(fname_inp.c_str(), fname_out.c_str(), ftype, nthread)) { + fprintf(stderr, "%s: failed to quantize model from '%s'\n", __func__, fname_inp.c_str()); + return 1; + } + + t_quantize_us = ggml_time_us() - t_start_us; + } + + // report timing + { + const int64_t t_main_end_us = ggml_time_us(); + + printf("\n"); + printf("%s: quantize time = %8.2f ms\n", __func__, t_quantize_us/1000.0); + printf("%s: total time = %8.2f ms\n", __func__, (t_main_end_us - t_main_start_us)/1000.0); + } + + return 0; +} diff --git a/third_party/math.h b/third_party/math.h deleted file mode 100755 index e69de29bb..000000000 diff --git a/third_party/nsync/mem/mem.mk b/third_party/nsync/mem/mem.mk index 1b01ce9da..5b17ee960 100644 --- a/third_party/nsync/mem/mem.mk +++ b/third_party/nsync/mem/mem.mk @@ -48,7 +48,7 @@ THIRD_PARTY_NSYNC_MEM_LIBS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($( THIRD_PARTY_NSYNC_MEM_SRCS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)_SRCS)) THIRD_PARTY_NSYNC_MEM_CHECKS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)_CHECKS)) THIRD_PARTY_NSYNC_MEM_OBJS = $(foreach x,$(THIRD_PARTY_NSYNC_MEM_ARTIFACTS),$($(x)_OBJS)) -$(THIRD_PARTY_NSYNC_MEM_OBJS): third_party/nsync/mem/nsync.mk +$(THIRD_PARTY_NSYNC_MEM_OBJS): third_party/nsync/mem/mem.mk .PHONY: o/$(MODE)/third_party/nsync/mem o/$(MODE)/third_party/nsync/mem: $(THIRD_PARTY_NSYNC_MEM_CHECKS) diff --git a/third_party/nsync/mem/nsync.mk b/third_party/nsync/mem/nsync.mk deleted file mode 100755 index e69de29bb..000000000 diff --git a/tool/build/lib/syscall.c b/tool/build/lib/syscall.c index 60c58cc71..34a725180 100644 --- a/tool/build/lib/syscall.c +++ b/tool/build/lib/syscall.c @@ -16,6 +16,7 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "tool/build/lib/syscall.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/ioctl.h" @@ -88,10 +89,8 @@ #include "tool/build/lib/memory.h" #include "tool/build/lib/pml4t.h" #include "tool/build/lib/signal.h" -#include "tool/build/lib/syscall.h" #include "tool/build/lib/throw.h" #include "tool/build/lib/xlat.h" -#include "tool/build/lib/xlaterrno.h" #define TIOCGWINSZ_LINUX 0x5413 #define TCGETS_LINUX 0x5401 diff --git a/tool/build/lib/xlaterrno.c b/tool/build/lib/xlaterrno.c index 26602f95d..640756702 100644 --- a/tool/build/lib/xlaterrno.c +++ b/tool/build/lib/xlaterrno.c @@ -18,7 +18,6 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" #include "libc/mem/mem.h" -#include "tool/build/lib/xlaterrno.h" struct thatispacked LinuxErrno { int32_t local; diff --git a/tool/build/lib/xlaterrno.h b/tool/build/lib/xlaterrno.h deleted file mode 100755 index e69de29bb..000000000 diff --git a/tool/emacs/cosmo-c-builtins.el b/tool/emacs/cosmo-c-builtins.el index 425558589..e54408191 100644 --- a/tool/emacs/cosmo-c-builtins.el +++ b/tool/emacs/cosmo-c-builtins.el @@ -34,245 +34,72 @@ "__UINT_FAST64_TYPE__" "__INTPTR_TYPE__" "__UINTPTR_TYPE__" - "__INT8_C" - "__INT16_C" - "__INT32_C" - "__INT64_C" - "__UINT8_C" - "__UINT16_C" - "__UINT32_C" - "__UINT64_C" - "__INTMAX_C" - "__UINTMAX_C" "__TIMESTAMP__" "__SANITIZE_ADDRESS__" "__SANITIZE_UNDEFINED__" "__FP_FAST_FMA" "__FP_FAST_FMAF" - "__FP_FAST_FMAL" - "__FP_FAST_FMAF16" - "__FP_FAST_FMAF32" - "__FP_FAST_FMAF64" - "__FP_FAST_FMAF128" - "__FP_FAST_FMAF32X" - "__FP_FAST_FMAF64X" - "__FP_FAST_FMAF128X")) + "__FP_FAST_FMAL")) (gcc-builtin-types '("__builtin_va_list")) (gcc-builtin-functions - '("__has_attribute" - "__has_builtin" - "__has_feature" - "__has_cpp_attribute" - "__builtin_va_arg" - "__builtin_va_copy" - "__builtin_va_start" - "__builtin_va_end" - "__builtin_abs" - "__builtin_strcpy" - "__builtin_strstr" - "__builtin_strpbrk" - "__builtin_strchr" - "__builtin_stpcpy" - "__builtin_setjmp" - "__builtin_longjmp" - "__builtin_apply_args" - "__builtin_apply" - "__builtin_return" - "__builtin_va_arg_pack" - "__builtin_va_arg_pack_len" - "__builtin_constant_p" - "__builtin_return_address" - "__builtin_extract_return_addr" - "__builtin_frob_return_address" - "__builtin_frame_address" - "__builtin_shuffle" - "__builtin_convertvector" - "__builtin_offsetof" - "__builtin_add_overflow" - "__builtin_sadd_overflow" - "__builtin_saddl_overflow" - "__builtin_saddll_overflow" - "__builtin_uadd_overflow" - "__builtin_uaddl_overflow" - "__builtin_uaddll_overflow" - "__builtin_sub_overflow" - "__builtin_ssub_overflow" - "__builtin_ssubl_overflow" - "__builtin_ssubll_overflow" - "__builtin_usub_overflow" - "__builtin_usubl_overflow" - "__builtin_usubll_overflow" - "__builtin_mul_overflow" - "__builtin_smul_overflow" - "__builtin_smull_overflow" - "__builtin_smulll_overflow" - "__builtin_umul_overflow" - "__builtin_umull_overflow" - "__builtin_umulll_overflow" + '("__builtin_add_overflow" "__builtin_add_overflow_p" - "__builtin_sub_overflow_p" - "__builtin_mul_overflow_p" - "__builtin_object_size" - "__builtin___memcpy_chk" - "__builtin___memmove_chk" - "__builtin___sprintf_chk" - "__builtin___snprintf_chk" - "__builtin___vsprintf_chk" - "__builtin___vsnprintf_chk" + "__builtin_alloc" "__builtin_alloca" "__builtin_alloca_with_align" - "__builtin_alloc" "__builtin_alloca_with_align_and_max" - "__builtin_has_attribute" - "__builtin_speculation_safe_value" - "__builtin_types_compatible_p" - "__builtin_call_with_static_chain" - "__builtin_choose_expr" - "__builtin_tgmath" - "__builtin_complex" - "__builtin_is_constant_evaluated" - "__builtin_expect" - "__builtin_expect_with_probability" - "__builtin_trap" - "__builtin_unreachable" + "__builtin_apply" + "__builtin_apply_args" "__builtin_assume" "__builtin_assume_aligned" - "__builtin_LINE" - "__builtin_FUNCTION" - "__builtin_FILE" - "__builtin___clear_cache" - "__builtin_prefetch" - "__builtin_huge_val" - "__builtin_huge_valf" - "__builtin_huge_vall" - "__builtin_huge_valfn" - "__builtin_huge_valfnx" - "__builtin_fpclassify" - "__builtin_inf" - "__builtin_infd32" - "__builtin_infd64" - "__builtin_infd128" - "__builtin_inff" - "__builtin_fma" - "__builtin_infl" - "__builtin_inffn" - "__builtin_inffnx" - "__builtin_isnan" - "__builtin_signbit" - "__builtin_signbitf" - "__builtin_signbitl" - "__builtin_isfinite" - "__builtin_isinf" - "__builtin_isinfinite" - "__builtin_isnormal" - "__builtin_isinf_sign" - "__builtin_isgreater" - "__builtin_isgreaterequal" - "__builtin_isgreater" - "__builtin_isgreaterequal" - "__builtin_isless" - "__builtin_islessequal" - "__builtin_islessgreater" - "__builtin_isunordered" - "__builtin_nan" - "__builtin_nand32" - "__builtin_nand64" - "__builtin_nand128" - "__builtin_nanf" - "__builtin_nanl" - "__builtin_nanfn" - "__builtin_nanfnx" - "__builtin_nans" - "__builtin_nansf" - "__builtin_nansl" - "__builtin_nansfn" - "__builtin_nansfnx" - "__builtin_ffs" - "__builtin_clz" - "__builtin_ctz" - "__builtin_clrsb" - "__builtin_popcount" - "__builtin_parity" - "__builtin_ffsl" - "__builtin_clzl" - "__builtin_ctzl" - "__builtin_clrsbl" - "__builtin_popcountl" - "__builtin_parityl" - "__builtin_ffsll" - "__builtin_clzll" - "__builtin_ctzll" - "__builtin_clrsbll" - "__builtin_popcountll" - "__builtin_parityll" - "__builtin_powi" - "__builtin_powif" - "__builtin_powil" "__builtin_bswap16" "__builtin_bswap32" "__builtin_bswap64" - "__builtin_extend_pointer" - "__builtin_goacc_parlevel_id" - "__builtin_goacc_parlevel_size" - "__builtin_fabsq" - "__builtin_copysignq" - "__builtin_infq" - "__builtin_huge_valq" - "__builtin_nanq" - "__builtin_nansq" - "__builtin_copysign" - "__builtin_copysignf" - "__builtin_copysignl" - "__builtin_fabs" - "__builtin_fabsf" - "__builtin_fabsl" - "__builtin_ceil" - "__builtin_ceilf" - "__builtin_ceill" - "__builtin_floor" - "__builtin_floorf" - "__builtin_floorl" - "__builtin_trunc" - "__builtin_truncf" - "__builtin_truncl" - "__builtin_round" - "__builtin_roundf" - "__builtin_roundl" - "__builtin_lround" - "__builtin_lroundf" - "__builtin_lroundl" - "__builtin_nearbyint" - "__builtin_nearbyintf" - "__builtin_nearbyintl" - "__builtin_scalbn" - "__builtin_scalbnf" - "__builtin_scalbnl" - "__builtin_logb" - "__builtin_logbf" - "__builtin_logbl" - "__builtin_fmax" - "__builtin_fmaxf" - "__builtin_fmaxl" - "__builtin_fmin" - "__builtin_fminf" - "__builtin_fminl" - "__builtin_rint" - "__builtin_rintf" - "__builtin_rintl" - "__builtin_lrint" - "__builtin_lrintf" - "__builtin_lrintl" - "__builtin_memcpy" - "__builtin_mempcpy" - "__builtin_memmove" - "__builtin_memcmp" - "__builtin_bcmp" - "__builtin_bzero" - "__builtin_memset" - "__builtin_strlen" + "__builtin_call_with_static_chain" + "__builtin_choose_expr" + "__builtin_clz" + "__builtin_clzl" + "__builtin_clzll" + "__builtin_constant_p" + "__builtin_ctz" + "__builtin_ctzl" + "__builtin_ctzll" + "__builtin_expect" + "__builtin_expect_with_probability" + "__builtin_extract_return_addr" + "__builtin_isnan" + "__builtin_signbit" + "__builtin_signbitl" + "__builtin_ffs" + "__builtin_ffsl" + "__builtin_ffsll" + "__builtin_fma" + "__builtin_fpclassify" + "__builtin_frame_address" + "__builtin_frob_return_addr" + "__builtin_has_attribute" + "__builtin_mul_overflow" + "__builtin_mul_overflow_p" + "__builtin_object_size" + "__builtin_offsetof" + "__builtin_popcount" + "__builtin_popcountl" + "__builtin_popcountll" + "__builtin_prefetch" + "__builtin_return" + "__builtin_return_address" + "__builtin_sub_overflow" + "__builtin_sub_overflow_p" + "__builtin_trap" + "__builtin_types_compatible_p" + "__builtin_unreachable" + "__has_attribute" + "__has_builtin" + "__has_cpp_attribute" + "__has_feature" "__ATOMIC_RELAXED" "__ATOMIC_CONSUME" "__ATOMIC_ACQUIRE" @@ -328,940 +155,7 @@ "__sync_lock_release")) (gcc-builtin-functions-ia32 - '("__builtin_ia32_pause" - "__builtin_ia32_paddb" - "__builtin_ia32_paddw" - "__builtin_ia32_paddd" - "__builtin_ia32_psubb" - "__builtin_ia32_psubw" - "__builtin_ia32_psubd" - "__builtin_ia32_paddsb" - "__builtin_ia32_paddsw" - "__builtin_ia32_psubsb" - "__builtin_ia32_psubsw" - "__builtin_ia32_paddusb" - "__builtin_ia32_paddusw" - "__builtin_ia32_psubusb" - "__builtin_ia32_psubusw" - "__builtin_ia32_pmullw" - "__builtin_ia32_pmulhw" - "__builtin_ia32_pand" - "__builtin_ia32_pandn" - "__builtin_ia32_por" - "__builtin_ia32_pxor" - "__builtin_ia32_pcmpeqb" - "__builtin_ia32_pcmpeqw" - "__builtin_ia32_pcmpeqd" - "__builtin_ia32_pcmpgtb" - "__builtin_ia32_pcmpgtw" - "__builtin_ia32_pcmpgtd" - "__builtin_ia32_punpckhbw" - "__builtin_ia32_punpckhwd" - "__builtin_ia32_punpckhdq" - "__builtin_ia32_punpcklbw" - "__builtin_ia32_punpcklwd" - "__builtin_ia32_punpckldq" - "__builtin_ia32_packsswb" - "__builtin_ia32_packssdw" - "__builtin_ia32_packuswb" - "__builtin_ia32_psllw" - "__builtin_ia32_pslld" - "__builtin_ia32_psllq" - "__builtin_ia32_psrlw" - "__builtin_ia32_psrld" - "__builtin_ia32_psrlq" - "__builtin_ia32_psraw" - "__builtin_ia32_psrad" - "__builtin_ia32_psllwi" - "__builtin_ia32_pslldi" - "__builtin_ia32_psllqi" - "__builtin_ia32_psrlwi" - "__builtin_ia32_psrldi" - "__builtin_ia32_psrlqi" - "__builtin_ia32_psrawi" - "__builtin_ia32_psradi" - "__builtin_ia32_pmulhuw" - "__builtin_ia32_pavgb" - "__builtin_ia32_pavgw" - "__builtin_ia32_psadbw" - "__builtin_ia32_pmaxub" - "__builtin_ia32_pmaxsw" - "__builtin_ia32_pminub" - "__builtin_ia32_pminsw" - "__builtin_ia32_pmovmskb" - "__builtin_ia32_maskmovq" - "__builtin_ia32_movntq" - "__builtin_ia32_sfence" - "__builtin_ia32_comieq" - "__builtin_ia32_comineq" - "__builtin_ia32_comilt" - "__builtin_ia32_comile" - "__builtin_ia32_comigt" - "__builtin_ia32_comige" - "__builtin_ia32_ucomieq" - "__builtin_ia32_ucomineq" - "__builtin_ia32_ucomilt" - "__builtin_ia32_ucomile" - "__builtin_ia32_ucomigt" - "__builtin_ia32_ucomige" - "__builtin_ia32_addps" - "__builtin_ia32_subps" - "__builtin_ia32_mulps" - "__builtin_ia32_divps" - "__builtin_ia32_addss" - "__builtin_ia32_subss" - "__builtin_ia32_mulss" - "__builtin_ia32_divss" - "__builtin_ia32_cmpeqps" - "__builtin_ia32_cmpltps" - "__builtin_ia32_cmpleps" - "__builtin_ia32_cmpgtps" - "__builtin_ia32_cmpgeps" - "__builtin_ia32_cmpunordps" - "__builtin_ia32_cmpneqps" - "__builtin_ia32_cmpnltps" - "__builtin_ia32_cmpnleps" - "__builtin_ia32_cmpngtps" - "__builtin_ia32_cmpngeps" - "__builtin_ia32_cmpordps" - "__builtin_ia32_cmpeqss" - "__builtin_ia32_cmpltss" - "__builtin_ia32_cmpless" - "__builtin_ia32_cmpunordss" - "__builtin_ia32_cmpneqss" - "__builtin_ia32_cmpnltss" - "__builtin_ia32_cmpnless" - "__builtin_ia32_cmpordss" - "__builtin_ia32_maxps" - "__builtin_ia32_maxss" - "__builtin_ia32_minps" - "__builtin_ia32_minss" - "__builtin_ia32_andps" - "__builtin_ia32_andnps" - "__builtin_ia32_orps" - "__builtin_ia32_xorps" - "__builtin_ia32_movss" - "__builtin_ia32_movhlps" - "__builtin_ia32_movlhps" - "__builtin_ia32_unpckhps" - "__builtin_ia32_unpcklps" - "__builtin_ia32_cvtpi2ps" - "__builtin_ia32_cvtsi2ss" - "__builtin_ia32_cvtps2pi" - "__builtin_ia32_cvtss2si" - "__builtin_ia32_cvttps2pi" - "__builtin_ia32_cvttss2si" - "__builtin_ia32_rcpps" - "__builtin_ia32_rsqrtps" - "__builtin_ia32_sqrtps" - "__builtin_ia32_rcpss" - "__builtin_ia32_rsqrtss" - "__builtin_ia32_sqrtss" - "__builtin_ia32_shufps" - "__builtin_ia32_movntps" - "__builtin_ia32_movmskps" - "__builtin_ia32_loadups" - "__builtin_ia32_storeups" - "__builtin_ia32_loadss" - "__builtin_ia32_loadhps" - "__builtin_ia32_loadlps" - "__builtin_ia32_storehps" - "__builtin_ia32_storelps" - "__builtin_ia32_comisdeq" - "__builtin_ia32_comisdlt" - "__builtin_ia32_comisdle" - "__builtin_ia32_comisdgt" - "__builtin_ia32_comisdge" - "__builtin_ia32_comisdneq" - "__builtin_ia32_ucomisdeq" - "__builtin_ia32_ucomisdlt" - "__builtin_ia32_ucomisdle" - "__builtin_ia32_ucomisdgt" - "__builtin_ia32_ucomisdge" - "__builtin_ia32_ucomisdneq" - "__builtin_ia32_cmpeqpd" - "__builtin_ia32_cmpltpd" - "__builtin_ia32_cmplepd" - "__builtin_ia32_cmpgtpd" - "__builtin_ia32_cmpgepd" - "__builtin_ia32_cmpunordpd" - "__builtin_ia32_cmpneqpd" - "__builtin_ia32_cmpnltpd" - "__builtin_ia32_cmpnlepd" - "__builtin_ia32_cmpngtpd" - "__builtin_ia32_cmpngepd" - "__builtin_ia32_cmpordpd" - "__builtin_ia32_cmpeqsd" - "__builtin_ia32_cmpltsd" - "__builtin_ia32_cmplesd" - "__builtin_ia32_cmpunordsd" - "__builtin_ia32_cmpneqsd" - "__builtin_ia32_cmpnltsd" - "__builtin_ia32_cmpnlesd" - "__builtin_ia32_cmpordsd" - "__builtin_ia32_paddq" - "__builtin_ia32_psubq" - "__builtin_ia32_addpd" - "__builtin_ia32_subpd" - "__builtin_ia32_mulpd" - "__builtin_ia32_divpd" - "__builtin_ia32_addsd" - "__builtin_ia32_subsd" - "__builtin_ia32_mulsd" - "__builtin_ia32_divsd" - "__builtin_ia32_minpd" - "__builtin_ia32_maxpd" - "__builtin_ia32_minsd" - "__builtin_ia32_maxsd" - "__builtin_ia32_andpd" - "__builtin_ia32_andnpd" - "__builtin_ia32_orpd" - "__builtin_ia32_xorpd" - "__builtin_ia32_movsd" - "__builtin_ia32_unpckhpd" - "__builtin_ia32_unpcklpd" - "__builtin_ia32_paddb128" - "__builtin_ia32_paddw128" - "__builtin_ia32_paddd128" - "__builtin_ia32_paddq128" - "__builtin_ia32_psubb128" - "__builtin_ia32_psubw128" - "__builtin_ia32_psubd128" - "__builtin_ia32_psubq128" - "__builtin_ia32_pmullw128" - "__builtin_ia32_pmulhw128" - "__builtin_ia32_pand128" - "__builtin_ia32_pandn128" - "__builtin_ia32_por128" - "__builtin_ia32_pxor128" - "__builtin_ia32_pavgb128" - "__builtin_ia32_pavgw128" - "__builtin_ia32_pcmpeqb128" - "__builtin_ia32_pcmpeqw128" - "__builtin_ia32_pcmpeqd128" - "__builtin_ia32_pcmpgtb128" - "__builtin_ia32_pcmpgtw128" - "__builtin_ia32_pcmpgtd128" - "__builtin_ia32_pmaxub128" - "__builtin_ia32_pmaxsw128" - "__builtin_ia32_pminub128" - "__builtin_ia32_pminsw128" - "__builtin_ia32_punpckhbw128" - "__builtin_ia32_punpckhwd128" - "__builtin_ia32_punpckhdq128" - "__builtin_ia32_punpckhqdq128" - "__builtin_ia32_punpcklbw128" - "__builtin_ia32_punpcklwd128" - "__builtin_ia32_punpckldq128" - "__builtin_ia32_punpcklqdq128" - "__builtin_ia32_packsswb128" - "__builtin_ia32_packssdw128" - "__builtin_ia32_packuswb128" - "__builtin_ia32_pmulhuw128" - "__builtin_ia32_maskmovdqu" - "__builtin_ia32_loadupd" - "__builtin_ia32_storeupd" - "__builtin_ia32_loadhpd" - "__builtin_ia32_loadlpd" - "__builtin_ia32_movmskpd" - "__builtin_ia32_pmovmskb128" - "__builtin_ia32_movnti" - "__builtin_ia32_movnti64" - "__builtin_ia32_movntpd" - "__builtin_ia32_movntdq" - "__builtin_ia32_pshufd" - "__builtin_ia32_pshuflw" - "__builtin_ia32_pshufhw" - "__builtin_ia32_psadbw128" - "__builtin_ia32_sqrtpd" - "__builtin_ia32_sqrtsd" - "__builtin_ia32_shufpd" - "__builtin_ia32_cvtdq2pd" - "__builtin_ia32_cvtdq2ps" - "__builtin_ia32_cvtpd2dq" - "__builtin_ia32_cvtpd2pi" - "__builtin_ia32_cvtpd2ps" - "__builtin_ia32_cvttpd2dq" - "__builtin_ia32_cvttpd2pi" - "__builtin_ia32_cvtpi2pd" - "__builtin_ia32_cvtsd2si" - "__builtin_ia32_cvttsd2si" - "__builtin_ia32_cvtsd2si64" - "__builtin_ia32_cvttsd2si64" - "__builtin_ia32_cvtps2dq" - "__builtin_ia32_cvtps2pd" - "__builtin_ia32_cvttps2dq" - "__builtin_ia32_cvtsi2sd" - "__builtin_ia32_cvtsi642sd" - "__builtin_ia32_cvtsd2ss" - "__builtin_ia32_cvtss2sd" - "__builtin_ia32_clflush" - "__builtin_ia32_lfence" - "__builtin_ia32_mfence" - "__builtin_ia32_loaddqu" - "__builtin_ia32_storedqu" - "__builtin_ia32_pmuludq" - "__builtin_ia32_pmuludq128" - "__builtin_ia32_psllw128" - "__builtin_ia32_pslld128" - "__builtin_ia32_psllq128" - "__builtin_ia32_psrlw128" - "__builtin_ia32_psrld128" - "__builtin_ia32_psrlq128" - "__builtin_ia32_psraw128" - "__builtin_ia32_psrad128" - "__builtin_ia32_pslldqi128" - "__builtin_ia32_psllwi128" - "__builtin_ia32_pslldi128" - "__builtin_ia32_psllqi128" - "__builtin_ia32_psrldqi128" - "__builtin_ia32_psrlwi128" - "__builtin_ia32_psrldi128" - "__builtin_ia32_psrlqi128" - "__builtin_ia32_psrawi128" - "__builtin_ia32_psradi128" - "__builtin_ia32_pmaddwd128" - "__builtin_ia32_movq128" - "__builtin_ia32_addsubpd" - "__builtin_ia32_addsubps" - "__builtin_ia32_haddpd" - "__builtin_ia32_haddps" - "__builtin_ia32_hsubpd" - "__builtin_ia32_hsubps" - "__builtin_ia32_lddqu" - "__builtin_ia32_monitor" - "__builtin_ia32_movshdup" - "__builtin_ia32_movsldup" - "__builtin_ia32_mwait" - "__builtin_ia32_phaddd" - "__builtin_ia32_phaddw" - "__builtin_ia32_phaddsw" - "__builtin_ia32_phsubd" - "__builtin_ia32_phsubw" - "__builtin_ia32_phsubsw" - "__builtin_ia32_pmaddubsw" - "__builtin_ia32_pmulhrsw" - "__builtin_ia32_pshufb" - "__builtin_ia32_psignb" - "__builtin_ia32_psignd" - "__builtin_ia32_psignw" - "__builtin_ia32_palignr" - "__builtin_ia32_pabsb" - "__builtin_ia32_pabsd" - "__builtin_ia32_pabsw" - "__builtin_ia32_phaddd128" - "__builtin_ia32_phaddw128" - "__builtin_ia32_phaddsw128" - "__builtin_ia32_phsubd128" - "__builtin_ia32_phsubw128" - "__builtin_ia32_phsubsw128" - "__builtin_ia32_pmaddubsw128" - "__builtin_ia32_pmulhrsw128" - "__builtin_ia32_pshufb128" - "__builtin_ia32_psignb128" - "__builtin_ia32_psignd128" - "__builtin_ia32_psignw128" - "__builtin_ia32_palignr128" - "__builtin_ia32_pabsb128" - "__builtin_ia32_pabsd128" - "__builtin_ia32_pabsw128" - "__builtin_ia32_blendpd" - "__builtin_ia32_blendps" - "__builtin_ia32_blendvpd" - "__builtin_ia32_blendvps" - "__builtin_ia32_dppd" - "__builtin_ia32_dpps" - "__builtin_ia32_insertps128" - "__builtin_ia32_movntdqa" - "__builtin_ia32_mpsadbw128" - "__builtin_ia32_packusdw128" - "__builtin_ia32_pblendvb128" - "__builtin_ia32_pblendw128" - "__builtin_ia32_pcmpeqq" - "__builtin_ia32_phminposuw128" - "__builtin_ia32_pmaxsb128" - "__builtin_ia32_pmaxsd128" - "__builtin_ia32_pmaxud128" - "__builtin_ia32_pmaxuw128" - "__builtin_ia32_pminsb128" - "__builtin_ia32_pminsd128" - "__builtin_ia32_pminud128" - "__builtin_ia32_pminuw128" - "__builtin_ia32_pmovsxbd128" - "__builtin_ia32_pmovsxbq128" - "__builtin_ia32_pmovsxbw128" - "__builtin_ia32_pmovsxdq128" - "__builtin_ia32_pmovsxwd128" - "__builtin_ia32_pmovsxwq128" - "__builtin_ia32_pmovzxbd128" - "__builtin_ia32_pmovzxbq128" - "__builtin_ia32_pmovzxbw128" - "__builtin_ia32_pmovzxdq128" - "__builtin_ia32_pmovzxwd128" - "__builtin_ia32_pmovzxwq128" - "__builtin_ia32_pmuldq128" - "__builtin_ia32_pmulld128" - "__builtin_ia32_ptestc128" - "__builtin_ia32_ptestnzc128" - "__builtin_ia32_ptestz128" - "__builtin_ia32_roundpd" - "__builtin_ia32_roundps" - "__builtin_ia32_roundsd" - "__builtin_ia32_roundss" - "__builtin_ia32_vec_set_v4sf" - "__builtin_ia32_vec_ext_v16qi" - "__builtin_ia32_vec_set_v16qi" - "__builtin_ia32_vec_set_v4si" - "__builtin_ia32_vec_set_v2di" - "__builtin_ia32_vec_ext_v4sf" - "__builtin_ia32_vec_ext_v4si" - "__builtin_ia32_vec_ext_v2di" - "__builtin_ia32_pcmpestrm128" - "__builtin_ia32_pcmpestri128" - "__builtin_ia32_pcmpestria128" - "__builtin_ia32_pcmpestric128" - "__builtin_ia32_pcmpestrio128" - "__builtin_ia32_pcmpestris128" - "__builtin_ia32_pcmpestriz128" - "__builtin_ia32_pcmpistrm128" - "__builtin_ia32_pcmpistri128" - "__builtin_ia32_pcmpistria128" - "__builtin_ia32_pcmpistric128" - "__builtin_ia32_pcmpistrio128" - "__builtin_ia32_pcmpistris128" - "__builtin_ia32_pcmpistriz128" - "__builtin_ia32_pcmpgtq" - "__builtin_ia32_crc32qi" - "__builtin_ia32_crc32hi" - "__builtin_ia32_crc32si" - "__builtin_ia32_crc32di" - "__builtin_ia32_addpd256" - "__builtin_ia32_addps256" - "__builtin_ia32_addsubpd256" - "__builtin_ia32_addsubps256" - "__builtin_ia32_andnpd256" - "__builtin_ia32_andnps256" - "__builtin_ia32_andpd256" - "__builtin_ia32_andps256" - "__builtin_ia32_blendpd256" - "__builtin_ia32_blendps256" - "__builtin_ia32_blendvpd256" - "__builtin_ia32_blendvps256" - "__builtin_ia32_cmppd" - "__builtin_ia32_cmppd256" - "__builtin_ia32_cmpps" - "__builtin_ia32_cmpps256" - "__builtin_ia32_cmpsd" - "__builtin_ia32_cmpss" - "__builtin_ia32_cvtdq2pd256" - "__builtin_ia32_cvtdq2ps256" - "__builtin_ia32_cvtpd2dq256" - "__builtin_ia32_cvtpd2ps256" - "__builtin_ia32_cvtps2dq256" - "__builtin_ia32_cvtps2pd256" - "__builtin_ia32_cvttpd2dq256" - "__builtin_ia32_cvttps2dq256" - "__builtin_ia32_divpd256" - "__builtin_ia32_divps256" - "__builtin_ia32_dpps256" - "__builtin_ia32_haddpd256" - "__builtin_ia32_haddps256" - "__builtin_ia32_hsubpd256" - "__builtin_ia32_hsubps256" - "__builtin_ia32_lddqu256" - "__builtin_ia32_loaddqu256" - "__builtin_ia32_loadupd256" - "__builtin_ia32_loadups256" - "__builtin_ia32_maskloadpd" - "__builtin_ia32_maskloadpd256" - "__builtin_ia32_maskloadps" - "__builtin_ia32_maskloadps256" - "__builtin_ia32_maskstorepd" - "__builtin_ia32_maskstorepd256" - "__builtin_ia32_maskstoreps" - "__builtin_ia32_maskstoreps256" - "__builtin_ia32_maxpd256" - "__builtin_ia32_maxps256" - "__builtin_ia32_minpd256" - "__builtin_ia32_minps256" - "__builtin_ia32_movddup256" - "__builtin_ia32_movmskpd256" - "__builtin_ia32_movmskps256" - "__builtin_ia32_movshdup256" - "__builtin_ia32_movsldup256" - "__builtin_ia32_mulpd256" - "__builtin_ia32_mulps256" - "__builtin_ia32_orpd256" - "__builtin_ia32_orps256" - "__builtin_ia32_pd_pd256" - "__builtin_ia32_pd256_pd" - "__builtin_ia32_ps_ps256" - "__builtin_ia32_ps256_ps" - "__builtin_ia32_ptestc256" - "__builtin_ia32_ptestnzc256" - "__builtin_ia32_ptestz256" - "__builtin_ia32_rcpps256" - "__builtin_ia32_roundpd256" - "__builtin_ia32_roundps256" - "__builtin_ia32_rsqrtps_nr256" - "__builtin_ia32_rsqrtps256" - "__builtin_ia32_shufpd256" - "__builtin_ia32_shufps256" - "__builtin_ia32_si_si256" - "__builtin_ia32_si256_si" - "__builtin_ia32_sqrtpd256" - "__builtin_ia32_sqrtps_nr256" - "__builtin_ia32_sqrtps256" - "__builtin_ia32_storedqu256" - "__builtin_ia32_storeupd256" - "__builtin_ia32_storeups256" - "__builtin_ia32_subpd256" - "__builtin_ia32_subps256" - "__builtin_ia32_unpckhpd256" - "__builtin_ia32_unpckhps256" - "__builtin_ia32_unpcklpd256" - "__builtin_ia32_unpcklps256" - "__builtin_ia32_vbroadcastf128_pd256" - "__builtin_ia32_vbroadcastf128_ps256" - "__builtin_ia32_vbroadcastsd256" - "__builtin_ia32_vbroadcastss" - "__builtin_ia32_vbroadcastss256" - "__builtin_ia32_vextractf128_pd256" - "__builtin_ia32_vextractf128_ps256" - "__builtin_ia32_vextractf128_si256" - "__builtin_ia32_vinsertf128_pd256" - "__builtin_ia32_vinsertf128_ps256" - "__builtin_ia32_vinsertf128_si256" - "__builtin_ia32_vperm2f128_pd256" - "__builtin_ia32_vperm2f128_ps256" - "__builtin_ia32_vperm2f128_si256" - "__builtin_ia32_vpermil2pd" - "__builtin_ia32_vpermil2pd256" - "__builtin_ia32_vpermil2ps" - "__builtin_ia32_vpermil2ps256" - "__builtin_ia32_vpermilpd" - "__builtin_ia32_vpermilpd256" - "__builtin_ia32_vpermilps" - "__builtin_ia32_vpermilps256" - "__builtin_ia32_vpermilvarpd" - "__builtin_ia32_vpermilvarpd256" - "__builtin_ia32_vpermilvarps" - "__builtin_ia32_vpermilvarps256" - "__builtin_ia32_vtestcpd" - "__builtin_ia32_vtestcpd256" - "__builtin_ia32_vtestcps" - "__builtin_ia32_vtestcps256" - "__builtin_ia32_vtestnzcpd" - "__builtin_ia32_vtestnzcpd256" - "__builtin_ia32_vtestnzcps" - "__builtin_ia32_vtestnzcps256" - "__builtin_ia32_vtestzpd" - "__builtin_ia32_vtestzpd256" - "__builtin_ia32_vtestzps" - "__builtin_ia32_vtestzps256" - "__builtin_ia32_vzeroall" - "__builtin_ia32_vzeroupper" - "__builtin_ia32_xorpd256" - "__builtin_ia32_xorps256" - "__builtin_ia32_mpsadbw256" - "__builtin_ia32_pabsb256" - "__builtin_ia32_pabsw256" - "__builtin_ia32_pabsd256" - "__builtin_ia32_packssdw256" - "__builtin_ia32_packsswb256" - "__builtin_ia32_packusdw256" - "__builtin_ia32_packuswb256" - "__builtin_ia32_paddb256" - "__builtin_ia32_paddw256" - "__builtin_ia32_paddd256" - "__builtin_ia32_paddq256" - "__builtin_ia32_paddsb256" - "__builtin_ia32_paddsw256" - "__builtin_ia32_paddusb256" - "__builtin_ia32_paddusw256" - "__builtin_ia32_palignr256" - "__builtin_ia32_andsi256" - "__builtin_ia32_andnotsi256" - "__builtin_ia32_pavgb256" - "__builtin_ia32_pavgw256" - "__builtin_ia32_pblendvb256" - "__builtin_ia32_pblendw256" - "__builtin_ia32_pcmpeqb256" - "__builtin_ia32_pcmpeqw256" - "__builtin_ia32_pcmpeqd256" - "__builtin_ia32_pcmpeqq256" - "__builtin_ia32_pcmpgtb256" - "__builtin_ia32_pcmpgtw256" - "__builtin_ia32_pcmpgtd256" - "__builtin_ia32_pcmpgtq256" - "__builtin_ia32_phaddw256" - "__builtin_ia32_phaddd256" - "__builtin_ia32_phaddsw256" - "__builtin_ia32_phsubw256" - "__builtin_ia32_phsubd256" - "__builtin_ia32_phsubsw256" - "__builtin_ia32_pmaddubsw256" - "__builtin_ia32_pmaddwd256" - "__builtin_ia32_pmaxsb256" - "__builtin_ia32_pmaxsw256" - "__builtin_ia32_pmaxsd256" - "__builtin_ia32_pmaxub256" - "__builtin_ia32_pmaxuw256" - "__builtin_ia32_pmaxud256" - "__builtin_ia32_pminsb256" - "__builtin_ia32_pminsw256" - "__builtin_ia32_pminsd256" - "__builtin_ia32_pminub256" - "__builtin_ia32_pminuw256" - "__builtin_ia32_pminud256" - "__builtin_ia32_pmovmskb256" - "__builtin_ia32_pmovsxbw256" - "__builtin_ia32_pmovsxbd256" - "__builtin_ia32_pmovsxbq256" - "__builtin_ia32_pmovsxwd256" - "__builtin_ia32_pmovsxwq256" - "__builtin_ia32_pmovsxdq256" - "__builtin_ia32_pmovzxbw256" - "__builtin_ia32_pmovzxbd256" - "__builtin_ia32_pmovzxbq256" - "__builtin_ia32_pmovzxwd256" - "__builtin_ia32_pmovzxwq256" - "__builtin_ia32_pmovzxdq256" - "__builtin_ia32_pmuldq256" - "__builtin_ia32_pmulhrsw256" - "__builtin_ia32_pmulhuw256" - "__builtin_ia32_pmulhw256" - "__builtin_ia32_pmullw256" - "__builtin_ia32_pmulld256" - "__builtin_ia32_pmuludq256" - "__builtin_ia32_por256" - "__builtin_ia32_psadbw256" - "__builtin_ia32_pshufb256" - "__builtin_ia32_pshufd256" - "__builtin_ia32_pshufhw256" - "__builtin_ia32_pshuflw256" - "__builtin_ia32_psignb256" - "__builtin_ia32_psignw256" - "__builtin_ia32_psignd256" - "__builtin_ia32_pslldqi256" - "__builtin_ia32_psllwi256" - "__builtin_ia32_pslldi256" - "__builtin_ia32_psllqi256" - "__builtin_ia32_psrawi256" - "__builtin_ia32_psraw256" - "__builtin_ia32_psradi256" - "__builtin_ia32_psrad256" - "__builtin_ia32_psrldqi256" - "__builtin_ia32_psrlwi256" - "__builtin_ia32_psrlw256" - "__builtin_ia32_psrldi256" - "__builtin_ia32_psrld256" - "__builtin_ia32_psrlqi256" - "__builtin_ia32_psubb256" - "__builtin_ia32_psubw256" - "__builtin_ia32_psubd256" - "__builtin_ia32_psubq256" - "__builtin_ia32_psubsb256" - "__builtin_ia32_psubsw256" - "__builtin_ia32_psubusb256" - "__builtin_ia32_psubusw256" - "__builtin_ia32_punpckhbw256" - "__builtin_ia32_punpckhwd256" - "__builtin_ia32_punpckhdq256" - "__builtin_ia32_punpckhqdq256" - "__builtin_ia32_punpcklbw256" - "__builtin_ia32_punpcklwd256" - "__builtin_ia32_punpckldq256" - "__builtin_ia32_punpcklqdq256" - "__builtin_ia32_pxor256" - "__builtin_ia32_movntdqa256" - "__builtin_ia32_vbroadcastss_ps" - "__builtin_ia32_vbroadcastss_ps256" - "__builtin_ia32_vbroadcastsd_pd256" - "__builtin_ia32_vbroadcastsi256" - "__builtin_ia32_pblendd128" - "__builtin_ia32_pblendd256" - "__builtin_ia32_pbroadcastb256" - "__builtin_ia32_pbroadcastw256" - "__builtin_ia32_pbroadcastd256" - "__builtin_ia32_pbroadcastq256" - "__builtin_ia32_pbroadcastb128" - "__builtin_ia32_pbroadcastw128" - "__builtin_ia32_pbroadcastd128" - "__builtin_ia32_pbroadcastq128" - "__builtin_ia32_permvarsi256" - "__builtin_ia32_permdf256" - "__builtin_ia32_permvarsf256" - "__builtin_ia32_permdi256" - "__builtin_ia32_permti256" - "__builtin_ia32_extract128i256" - "__builtin_ia32_insert128i256" - "__builtin_ia32_maskloadd256" - "__builtin_ia32_maskloadq256" - "__builtin_ia32_maskloadd" - "__builtin_ia32_maskloadq" - "__builtin_ia32_maskstored256" - "__builtin_ia32_maskstoreq256" - "__builtin_ia32_maskstored" - "__builtin_ia32_maskstoreq" - "__builtin_ia32_psllv8si" - "__builtin_ia32_psllv4si" - "__builtin_ia32_psllv4di" - "__builtin_ia32_psllv2di" - "__builtin_ia32_psrav8si" - "__builtin_ia32_psrav4si" - "__builtin_ia32_psrlv8si" - "__builtin_ia32_psrlv4si" - "__builtin_ia32_psrlv4di" - "__builtin_ia32_psrlv2di" - "__builtin_ia32_gathersiv2df" - "__builtin_ia32_gathersiv4df" - "__builtin_ia32_gatherdiv2df" - "__builtin_ia32_gatherdiv4df" - "__builtin_ia32_gathersiv4sf" - "__builtin_ia32_gathersiv8sf" - "__builtin_ia32_gatherdiv4sf" - "__builtin_ia32_gatherdiv4sf256" - "__builtin_ia32_gathersiv2di" - "__builtin_ia32_gathersiv4di" - "__builtin_ia32_gatherdiv2di" - "__builtin_ia32_gatherdiv4di" - "__builtin_ia32_gathersiv4si" - "__builtin_ia32_gathersiv8si" - "__builtin_ia32_gatherdiv4si" - "__builtin_ia32_gatherdiv4si256" - "__builtin_ia32_aesenc128" - "__builtin_ia32_aesenclast128" - "__builtin_ia32_aesdec128" - "__builtin_ia32_aesdeclast128" - "__builtin_ia32_aeskeygenassist128" - "__builtin_ia32_aesimc128" - "__builtin_ia32_pclmulqdq128" - "__builtin_ia32_rdfsbase32" - "__builtin_ia32_rdfsbase64" - "__builtin_ia32_rdgsbase32" - "__builtin_ia32_rdgsbase64" - "__builtin_ia32_rdrand16_step" - "__builtin_ia32_rdrand32_step" - "__builtin_ia32_rdrand64_step" - "__builtin_ia32_ptwrite32" - "__builtin_ia32_ptwrite64" - "__builtin_ia32_movntsd" - "__builtin_ia32_movntss" - "__builtin_ia32_extrqi" - "__builtin_ia32_insertq" - "__builtin_ia32_insertqi" - "__builtin_ia32_vfrczpd" - "__builtin_ia32_vfrczps" - "__builtin_ia32_vfrczsd" - "__builtin_ia32_vfrczss" - "__builtin_ia32_vfrczpd256" - "__builtin_ia32_vfrczps256" - "__builtin_ia32_vpcmov" - "__builtin_ia32_vpcmov_v2di" - "__builtin_ia32_vpcmov_v4si" - "__builtin_ia32_vpcmov_v8hi" - "__builtin_ia32_vpcmov_v16qi" - "__builtin_ia32_vpcmov_v2df" - "__builtin_ia32_vpcmov_v4sf" - "__builtin_ia32_vpcmov_v4di256" - "__builtin_ia32_vpcmov_v8si256" - "__builtin_ia32_vpcmov_v16hi256" - "__builtin_ia32_vpcmov_v32qi256" - "__builtin_ia32_vpcmov_v4df256" - "__builtin_ia32_vpcmov_v8sf256" - "__builtin_ia32_vpcomeqb" - "__builtin_ia32_vpcomeqw" - "__builtin_ia32_vpcomeqd" - "__builtin_ia32_vpcomeqq" - "__builtin_ia32_vpcomequb" - "__builtin_ia32_vpcomequd" - "__builtin_ia32_vpcomequq" - "__builtin_ia32_vpcomequw" - "__builtin_ia32_vpcomfalseb" - "__builtin_ia32_vpcomfalsed" - "__builtin_ia32_vpcomfalseq" - "__builtin_ia32_vpcomfalseub" - "__builtin_ia32_vpcomfalseud" - "__builtin_ia32_vpcomfalseuq" - "__builtin_ia32_vpcomfalseuw" - "__builtin_ia32_vpcomfalsew" - "__builtin_ia32_vpcomgeb" - "__builtin_ia32_vpcomged" - "__builtin_ia32_vpcomgeq" - "__builtin_ia32_vpcomgeub" - "__builtin_ia32_vpcomgeud" - "__builtin_ia32_vpcomgeuq" - "__builtin_ia32_vpcomgeuw" - "__builtin_ia32_vpcomgew" - "__builtin_ia32_vpcomgtb" - "__builtin_ia32_vpcomgtd" - "__builtin_ia32_vpcomgtq" - "__builtin_ia32_vpcomgtub" - "__builtin_ia32_vpcomgtud" - "__builtin_ia32_vpcomgtuq" - "__builtin_ia32_vpcomgtuw" - "__builtin_ia32_vpcomgtw" - "__builtin_ia32_vpcomleb" - "__builtin_ia32_vpcomled" - "__builtin_ia32_vpcomleq" - "__builtin_ia32_vpcomleub" - "__builtin_ia32_vpcomleud" - "__builtin_ia32_vpcomleuq" - "__builtin_ia32_vpcomleuw" - "__builtin_ia32_vpcomlew" - "__builtin_ia32_vpcomltb" - "__builtin_ia32_vpcomltd" - "__builtin_ia32_vpcomltq" - "__builtin_ia32_vpcomltub" - "__builtin_ia32_vpcomltud" - "__builtin_ia32_vpcomltuq" - "__builtin_ia32_vpcomltuw" - "__builtin_ia32_vpcomltw" - "__builtin_ia32_vpcomneb" - "__builtin_ia32_vpcomned" - "__builtin_ia32_vpcomneq" - "__builtin_ia32_vpcomneub" - "__builtin_ia32_vpcomneud" - "__builtin_ia32_vpcomneuq" - "__builtin_ia32_vpcomneuw" - "__builtin_ia32_vpcomnew" - "__builtin_ia32_vpcomtrueb" - "__builtin_ia32_vpcomtrued" - "__builtin_ia32_vpcomtrueq" - "__builtin_ia32_vpcomtrueub" - "__builtin_ia32_vpcomtrueud" - "__builtin_ia32_vpcomtrueuq" - "__builtin_ia32_vpcomtrueuw" - "__builtin_ia32_vpcomtruew" - "__builtin_ia32_vphaddbd" - "__builtin_ia32_vphaddbq" - "__builtin_ia32_vphaddbw" - "__builtin_ia32_vphadddq" - "__builtin_ia32_vphaddubd" - "__builtin_ia32_vphaddubq" - "__builtin_ia32_vphaddubw" - "__builtin_ia32_vphaddudq" - "__builtin_ia32_vphadduwd" - "__builtin_ia32_vphadduwq" - "__builtin_ia32_vphaddwd" - "__builtin_ia32_vphaddwq" - "__builtin_ia32_vphsubbw" - "__builtin_ia32_vphsubdq" - "__builtin_ia32_vphsubwd" - "__builtin_ia32_vpmacsdd" - "__builtin_ia32_vpmacsdqh" - "__builtin_ia32_vpmacsdql" - "__builtin_ia32_vpmacssdd" - "__builtin_ia32_vpmacssdqh" - "__builtin_ia32_vpmacssdql" - "__builtin_ia32_vpmacsswd" - "__builtin_ia32_vpmacssww" - "__builtin_ia32_vpmacswd" - "__builtin_ia32_vpmacsww" - "__builtin_ia32_vpmadcsswd" - "__builtin_ia32_vpmadcswd" - "__builtin_ia32_vpperm" - "__builtin_ia32_vprotb" - "__builtin_ia32_vprotd" - "__builtin_ia32_vprotq" - "__builtin_ia32_vprotw" - "__builtin_ia32_vpshab" - "__builtin_ia32_vpshad" - "__builtin_ia32_vpshaq" - "__builtin_ia32_vpshaw" - "__builtin_ia32_vpshlb" - "__builtin_ia32_vpshld" - "__builtin_ia32_vpshlq" - "__builtin_ia32_vpshlw" - "__builtin_ia32_vfmaddpd" - "__builtin_ia32_vfmaddps" - "__builtin_ia32_vfmaddsd" - "__builtin_ia32_vfmaddss" - "__builtin_ia32_vfmsubpd" - "__builtin_ia32_vfmsubps" - "__builtin_ia32_vfmsubsd" - "__builtin_ia32_vfmsubss" - "__builtin_ia32_vfnmaddpd" - "__builtin_ia32_vfnmaddps" - "__builtin_ia32_vfnmaddsd" - "__builtin_ia32_vfnmaddss" - "__builtin_ia32_vfnmsubpd" - "__builtin_ia32_vfnmsubps" - "__builtin_ia32_vfnmsubsd" - "__builtin_ia32_vfnmsubss" - "__builtin_ia32_vfmaddpd256" - "__builtin_ia32_vfmaddps256" - "__builtin_ia32_vfmsubpd256" - "__builtin_ia32_vfmsubps256" - "__builtin_ia32_vfnmaddpd256" - "__builtin_ia32_vfnmaddps256" - "__builtin_ia32_vfnmsubpd256" - "__builtin_ia32_vfnmsubps256" - "__builtin_ia32_vfmaddsubpd256" - "__builtin_ia32_vfmaddsubps256" - "__builtin_ia32_vfmsubaddpd256" - "__builtin_ia32_vfmsubaddps256" - "__builtin_ia32_llwpcb16" - "__builtin_ia32_llwpcb32" - "__builtin_ia32_llwpcb64" - "__builtin_ia32_lwpval16" - "__builtin_ia32_lwpval32" - "__builtin_ia32_lwpval64" - "__builtin_ia32_lwpins16" - "__builtin_ia32_lwpins32" - "__builtin_ia32_lwpins64" - "__builtin_ia32_bextr_u64" - "__builtin_ia32_lzcnt_u64" - "__builtin_ia32_fxsave" - "__builtin_ia32_fxrstor" - "__builtin_ia32_fxsave64" - "__builtin_ia32_fxrstor64" - "__builtin_ia32_xsave" - "__builtin_ia32_xrstor" - "__builtin_ia32_xsave64" - "__builtin_ia32_xrstor64" - "__builtin_ia32_xsaveopt" - "__builtin_ia32_xsaveopt64" - "__builtin_ia32_bextri_u32" - "__builtin_ia32_bextri_u64" - "__builtin_ia32_femms" - "__builtin_ia32_pavgusb" - "__builtin_ia32_pf2id" - "__builtin_ia32_pfacc" - "__builtin_ia32_pfadd" - "__builtin_ia32_pfcmpeq" - "__builtin_ia32_pfcmpge" - "__builtin_ia32_pfcmpgt" - "__builtin_ia32_pfmax" - "__builtin_ia32_pfmin" - "__builtin_ia32_pfmul" - "__builtin_ia32_pfrcp" - "__builtin_ia32_pfrcpit1" - "__builtin_ia32_pfrcpit2" - "__builtin_ia32_pfrsqrt" - "__builtin_ia32_pfsub" - "__builtin_ia32_pfsubr" - "__builtin_ia32_pi2fd" - "__builtin_ia32_pmulhrw" - "__builtin_ia32_pf2iw" - "__builtin_ia32_pfnacc" - "__builtin_ia32_pfpnacc" - "__builtin_ia32_pi2fw" - "__builtin_ia32_pswapdsf" - "__builtin_ia32_pswapdsi" - "__builtin_ia32_xbegin" - "__builtin_ia32_xend" - "__builtin_ia32_xabort" - "__builtin_ia32_xtest" - "__builtin_ia32_monitorx" - "__builtin_ia32_mwaitx" - "__builtin_ia32_wrpkru" - "__builtin_ia32_rdpkru" - "__builtin_ia32_rdsspd" - "__builtin_ia32_rdsspq" - "__builtin_ia32_incsspd" - "__builtin_ia32_incsspq")) + '("__builtin_ia32_pmovmskb128")) (gxx-builtin-type-traits '("__has_nothrow_assign" @@ -1304,10 +198,6 @@ "EXPROPRIATE" "YOINK" "STATIC_YOINK" - "STATIC_YOINK_SOURCE" - "STATIC_STACK_ADDR" - "STATIC_STACK_SIZE" - "STATIC_SYMBOL" "PYTHON_YOINK" "PYTHON_PROVIDE" "STRINGIFY"))