Perform some code cleanup

This commit is contained in:
Justine Tunney 2023-05-15 16:32:10 -07:00
parent cc1732bc42
commit 210187cf77
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
205 changed files with 1748 additions and 2595 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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_

View file

@ -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) {

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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";

View file

@ -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) {

View file

@ -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) {

View file

@ -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;

View file

@ -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';

View file

@ -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";

View file

@ -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),

View file

@ -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";

View file

@ -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";

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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

View file

@ -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);
}

View file

@ -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";

View file

@ -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";

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;

View file

@ -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) */

View file

@ -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];

View file

@ -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)) ||

View file

@ -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";

View file

@ -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";

View file

@ -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;

View file

@ -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";

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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";

View file

@ -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)) ||

View file

@ -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);
}

View file

@ -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.

View file

@ -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

View file

@ -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 */

View file

@ -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"

View file

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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__ */

View file

@ -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);
}

View file

@ -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"
/**

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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 */

View file

@ -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

View file

@ -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);

View file

@ -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 */

View file

@ -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

View file

@ -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
}

View file

@ -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

View file

@ -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] = {

View file

View file

@ -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

View file

@ -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"

View file

@ -34,5 +34,5 @@ dontdiscard char *testlib_formatint(intptr_t x) {
}
*p++ = ')';
*p++ = '\0';
return str;
return strdup(str);
}

View file

@ -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

View file

@ -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 <das@FreeBSD.ORG>.
*/
/**
* 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 */

View file

@ -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

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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 */

View file

@ -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 <das@FreeBSD.ORG>.
*/
#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 */

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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 */

View file

@ -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

View file

@ -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 */

View file

@ -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 */

View file

@ -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)));
}

View file

@ -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

View file

@ -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 𝑥.

View file

@ -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 */

Some files were not shown because too many files have changed in this diff Show more