Get LIBC_TESTLIB building on AARCH64

This commit is contained in:
Justine Tunney 2023-05-11 19:56:33 -07:00
parent 95fab334e4
commit 5e2f7f7ced
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
46 changed files with 975 additions and 1174 deletions

View file

@ -49,8 +49,8 @@
#include "third_party/dlmalloc/dlmalloc.h" #include "third_party/dlmalloc/dlmalloc.h"
#ifdef __x86_64__ #ifdef __x86_64__
STATIC_YOINK("_init_asan"); STATIC_YOINK("_init_asan");
#endif
#if IsModeDbg() #if IsModeDbg()
// MODE=dbg // MODE=dbg
@ -159,6 +159,11 @@ static struct AsanMorgue {
_Atomic(void *) p[ASAN_MORGUE_ITEMS]; _Atomic(void *) p[ASAN_MORGUE_ITEMS];
} __asan_morgue; } __asan_morgue;
int __asan_option_detect_stack_use_after_return = 0;
void __asan_version_mismatch_check_v8(void) {
}
static bool __asan_once(void) { static bool __asan_once(void) {
bool want = false; bool want = false;
static atomic_int once; static atomic_int once;
@ -1463,8 +1468,7 @@ static textstartup void __asan_shadow_existing_mappings(void) {
__asan_poison((void *)GetStackAddr(), GUARDSIZE, kAsanStackOverflow); __asan_poison((void *)GetStackAddr(), GUARDSIZE, kAsanStackOverflow);
} }
__attribute__((__constructor__)) void __asan_init(int argc, char **argv, void __asan_init(int argc, char **argv, char **envp, intptr_t *auxv) {
char **envp, intptr_t *auxv) {
static bool once; static bool once;
if (!_cmpxchg(&once, false, true)) return; if (!_cmpxchg(&once, false, true)) return;
if (IsWindows() && NtGetVersion() < kNtVersionWindows10) { if (IsWindows() && NtGetVersion() < kNtVersionWindows10) {
@ -1499,5 +1503,3 @@ __attribute__((__constructor__)) void __asan_init(int argc, char **argv,
STRACE("/_/ \\_\\____/_/ \\_\\_| \\_|"); STRACE("/_/ \\_\\____/_/ \\_\\_| \\_|");
STRACE("cosmopolitan memory safety module initialized"); STRACE("cosmopolitan memory safety module initialized");
} }
#endif /* __x86_64__ */

View file

@ -18,9 +18,14 @@
*/ */
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
// Delegates to free(). .init.start 303,_init_asan
// push %rdi
// @note reduces make dependency toil caused by macros push %rsi
testlib_free: mov %r12,%rdi
jmp free mov %r13,%rsi
.endfn testlib_free,globl mov %r14,%rdx
mov %r15,%rcx
call __asan_init
pop %rsi
pop %rdi
.init.end 303,_init_asan

173
libc/intrin/asanthunk.c Normal file
View file

@ -0,0 +1,173 @@
/*-*- 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.
*/
void __asan_report_load(void *, int);
void __asan_report_store(void *, int);
void *__asan_stack_malloc(size_t, int);
void __asan_stack_free(char *, size_t, int);
void __asan_report_load1(void *p) {
__asan_report_load(p, 1);
}
void __asan_report_load2(void *p) {
__asan_report_load(p, 2);
}
void __asan_report_load4(void *p) {
__asan_report_load(p, 4);
}
void __asan_report_load8(void *p) {
__asan_report_load(p, 8);
}
void __asan_report_load16(void *p) {
__asan_report_load(p, 16);
}
void __asan_report_load32(void *p) {
__asan_report_load(p, 32);
}
void __asan_report_load_n(void *p, int n) {
__asan_report_load(p, n);
}
void __asan_report_store1(void *p) {
__asan_report_store(p, 1);
}
void __asan_report_store2(void *p) {
__asan_report_store(p, 2);
}
void __asan_report_store4(void *p) {
__asan_report_store(p, 4);
}
void __asan_report_store8(void *p) {
__asan_report_store(p, 8);
}
void __asan_report_store16(void *p) {
__asan_report_store(p, 16);
}
void __asan_report_store32(void *p) {
__asan_report_store(p, 32);
}
void __asan_report_store_n(void *p, int n) {
__asan_report_store(p, n);
}
void *__asan_stack_malloc_0(size_t n) {
return __asan_stack_malloc(n, 0);
}
void *__asan_stack_malloc_1(size_t n) {
return __asan_stack_malloc(n, 1);
}
void *__asan_stack_malloc_2(size_t n) {
return __asan_stack_malloc(n, 2);
}
void *__asan_stack_malloc_3(size_t n) {
return __asan_stack_malloc(n, 3);
}
void *__asan_stack_malloc_4(size_t n) {
return __asan_stack_malloc(n, 4);
}
void *__asan_stack_malloc_5(size_t n) {
return __asan_stack_malloc(n, 5);
}
void *__asan_stack_malloc_6(size_t n) {
return __asan_stack_malloc(n, 6);
}
void *__asan_stack_malloc_7(size_t n) {
return __asan_stack_malloc(n, 7);
}
void *__asan_stack_malloc_8(size_t n) {
return __asan_stack_malloc(n, 8);
}
void *__asan_stack_malloc_9(size_t n) {
return __asan_stack_malloc(n, 9);
}
void *__asan_stack_malloc_10(size_t n) {
return __asan_stack_malloc(n, 10);
}
void __asan_stack_free_0(char *p, size_t n) {
__asan_stack_free(p, n, 0);
}
void __asan_stack_free_1(char *p, size_t n) {
__asan_stack_free(p, n, 1);
}
void __asan_stack_free_2(char *p, size_t n) {
__asan_stack_free(p, n, 2);
}
void __asan_stack_free_3(char *p, size_t n) {
__asan_stack_free(p, n, 3);
}
void __asan_stack_free_4(char *p, size_t n) {
__asan_stack_free(p, n, 4);
}
void __asan_stack_free_5(char *p, size_t n) {
__asan_stack_free(p, n, 5);
}
void __asan_stack_free_6(char *p, size_t n) {
__asan_stack_free(p, n, 6);
}
void __asan_stack_free_7(char *p, size_t n) {
__asan_stack_free(p, n, 7);
}
void __asan_stack_free_8(char *p, size_t n) {
__asan_stack_free(p, n, 8);
}
void __asan_stack_free_9(char *p, size_t n) {
__asan_stack_free(p, n, 9);
}
void __asan_stack_free_10(char *p, size_t n) {
__asan_stack_free(p, n, 10);
}
void __asan_load1() {
__builtin_trap();
}
void __asan_load2() {
__builtin_trap();
}
void __asan_load4() {
__builtin_trap();
}
void __asan_load8() {
__builtin_trap();
}
void __asan_load16() {
__builtin_trap();
}
void __asan_load32() {
__builtin_trap();
}
void __asan_store1() {
__builtin_trap();
}
void __asan_store2() {
__builtin_trap();
}
void __asan_store4() {
__builtin_trap();
}
void __asan_store8() {
__builtin_trap();
}
void __asan_store16() {
__builtin_trap();
}
void __asan_store32() {
__builtin_trap();
}

View file

@ -1,269 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.rodata.cst4
__asan_option_detect_stack_use_after_return:
.long 0
.endobj __asan_option_detect_stack_use_after_return,globl
.previous
__asan_report_load1:
push $1
jmp 1f
.endfn __asan_report_load1,globl
__asan_report_load2:
push $2
jmp 1f
.endfn __asan_report_load2,globl
__asan_report_load4:
push $4
jmp 1f
.endfn __asan_report_load4,globl
__asan_report_load8:
push $8
jmp 1f
.endfn __asan_report_load8,globl
__asan_report_load16:
push $16
jmp 1f
.endfn __asan_report_load16,globl
__asan_report_load32:
push $32
1: pop %rsi
0: jmp __asan_report_load
.endfn __asan_report_load32,globl
__asan_report_load_n:
jmp 0b
.endfn __asan_report_load_n,globl
__asan_report_store1:
push $1
jmp 1f
.endfn __asan_report_store1,globl
__asan_report_store2:
push $2
jmp 1f
.endfn __asan_report_store2,globl
__asan_report_store4:
push $4
jmp 1f
.endfn __asan_report_store4,globl
__asan_report_store8:
push $8
jmp 1f
.endfn __asan_report_store8,globl
__asan_report_store16:
push $16
jmp 1f
.endfn __asan_report_store16,globl
__asan_report_store32:
push $32
1: pop %rsi
0: jmp __asan_report_store
.endfn __asan_report_store32,globl
__asan_report_store_n:
jmp 0b
.endfn __asan_report_store_n,globl
__asan_stack_free_0:
push $0
jmp 1f
.endfn __asan_stack_free_0,globl
__asan_stack_free_1:
push $1
jmp 1f
.endfn __asan_stack_free_1,globl
__asan_stack_free_2:
push $2
jmp 1f
.endfn __asan_stack_free_2,globl
__asan_stack_free_3:
push $3
jmp 1f
.endfn __asan_stack_free_3,globl
__asan_stack_free_4:
push $4
jmp 1f
.endfn __asan_stack_free_4,globl
__asan_stack_free_5:
push $5
.endfn __asan_stack_free_5,globl
__asan_stack_free_hop:
1: pop %rdx
jmp __asan_stack_free
.endfn __asan_report_store_n,globl
__asan_stack_free_6:
push $6
jmp 1b
.endfn __asan_stack_free_6,globl
__asan_stack_free_7:
push $7
jmp 1b
.endfn __asan_stack_free_7,globl
__asan_stack_free_8:
push $8
jmp 1b
.endfn __asan_stack_free_8,globl
__asan_stack_free_9:
push $9
jmp 1b
.endfn __asan_stack_free_9,globl
__asan_stack_free_10:
push $10
jmp 1b
.endfn __asan_stack_free_10,globl
__asan_stack_malloc_0:
push $0
jmp 1f
.endfn __asan_stack_malloc_0,globl
__asan_stack_malloc_1:
push $1
jmp 1f
.endfn __asan_stack_malloc_1,globl
__asan_stack_malloc_2:
push $2
jmp 1f
.endfn __asan_stack_malloc_2,globl
__asan_stack_malloc_3:
push $3
jmp 1f
.endfn __asan_stack_malloc_3,globl
__asan_stack_malloc_4:
push $4
jmp 1f
.endfn __asan_stack_malloc_4,globl
__asan_stack_malloc_5:
push $5
jmp 1f
.endfn __asan_stack_malloc_5,globl
__asan_stack_malloc_hop:
1: pop %rsi
jmp __asan_stack_malloc
.endfn __asan_report_store_n,globl
__asan_stack_malloc_6:
push $6
jmp 1b
.endfn __asan_stack_malloc_6,globl
__asan_stack_malloc_7:
push $7
jmp 1b
.endfn __asan_stack_malloc_7,globl
__asan_stack_malloc_8:
push $8
jmp 1b
.endfn __asan_stack_malloc_8,globl
__asan_stack_malloc_9:
push $9
jmp 1b
.endfn __asan_stack_malloc_9,globl
__asan_stack_malloc_10:
push $10
jmp 1b
.endfn __asan_stack_malloc_10,globl
__asan_version_mismatch_check_v8:
ret
.endfn __asan_version_mismatch_check_v8,globl
// Initializes Address Sanitizer runtime earlier if linked.
.init.start 303,_init_asan
push %rdi
push %rsi
mov %r12,%rdi
mov %r13,%rsi
mov %r14,%rdx
mov %r15,%rcx
call __asan_init
pop %rsi
pop %rdi
.init.end 303,_init_asan
__asan_load1:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_load1,globl
__asan_load2:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_load2,globl
__asan_load4:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_load4,globl
__asan_load8:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_load8,globl
__asan_load16:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_load16,globl
__asan_load32:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_load32,globl
__asan_store1:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_store1,globl
__asan_store2:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_store2,globl
__asan_store4:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_store4,globl
__asan_store8:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_store8,globl
__asan_store16:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_store16,globl
__asan_store32:
push %rbp
mov %rsp,%rbp
ud2
.endfn __asan_store32,globl

View file

@ -1,31 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/log/log.h"
#include "libc/macros.internal.h"
.bss
.balign 4
__log_level:
.long 0
.endobj __log_level,globl
.previous
.init.start 200,_init_log_level
movb $kLogInfo,__log_level(%rip)
.init.end 200,_init_log_level

View file

@ -1,7 +1,7 @@
/*-*- mode:asm; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney Copyright 2023 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the any purpose with or without fee is hereby granted, provided that the
@ -16,12 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/macros.internal.h" #include "libc/log/log.h"
.init.start 201,_init_getopt unsigned __log_level = kLogInfo;
push $1
pop %rax
mov %eax,opterr(%rip)
mov %eax,optind(%rip)
movl $kGetoptEmsg,getopt_place(%rip)
.init.end 201,_init_getopt

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/dce.h"
#include "libc/intrin/kprintf.h" #include "libc/intrin/kprintf.h"
#include "libc/intrin/strace.internal.h" #include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
@ -81,6 +82,10 @@ textstartup void cosmo(long *sp) {
argc = __strace_init(argc, argv, envp, auxv); argc = __strace_init(argc, argv, envp, auxv);
#endif #endif
#if IsAsan()
__asan_init(argc, argv, envp, auxv);
#endif
// set helpful globals // set helpful globals
__argc = argc; __argc = argc;
__argv = argv; __argv = argv;

View file

@ -35,6 +35,7 @@ void __enable_threads(void) _Hide;
void *__cxa_finalize(void *) _Hide; void *__cxa_finalize(void *) _Hide;
void __stack_chk_fail(void) wontreturn relegated; void __stack_chk_fail(void) wontreturn relegated;
void __stack_chk_fail_local(void) wontreturn relegated _Hide; void __stack_chk_fail_local(void) wontreturn relegated _Hide;
void __asan_init(int, char **, char **, intptr_t *) _Hide;
void _jmpstack(void *, void *, ...) _Hide wontreturn; void _jmpstack(void *, void *, ...) _Hide wontreturn;
long _setstack(void *, void *, ...) _Hide; long _setstack(void *, void *, ...) _Hide;
int GetDosArgv(const char16_t *, char *, size_t, char **, size_t); int GetDosArgv(const char16_t *, char *, size_t, char **, size_t);

View file

@ -71,6 +71,7 @@ o/$(MODE)/libc/runtime/ftracer.o: private \
-ffreestanding \ -ffreestanding \
-fno-sanitize=all -fno-sanitize=all
o/$(MODE)/libc/runtime/cosmo2.o \
o/$(MODE)/libc/runtime/fork-nt.o \ o/$(MODE)/libc/runtime/fork-nt.o \
o/$(MODE)/libc/runtime/printmemoryintervals.o \ o/$(MODE)/libc/runtime/printmemoryintervals.o \
o/$(MODE)/libc/runtime/arememoryintervalsok.o \ o/$(MODE)/libc/runtime/arememoryintervalsok.o \

View file

@ -45,6 +45,9 @@ $(LIBC_STR_A).pkg: \
$(LIBC_STR_A_OBJS) \ $(LIBC_STR_A_OBJS) \
$(foreach x,$(LIBC_STR_A_DIRECTDEPS),$($(x)_A).pkg) $(foreach x,$(LIBC_STR_A_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/libc/str/wow.o: private \
CC = gcc
o/$(MODE)/libc/str/wmemset.o \ o/$(MODE)/libc/str/wmemset.o \
o/$(MODE)/libc/str/memset16.o \ o/$(MODE)/libc/str/memset16.o \
o/$(MODE)/libc/str/dosdatetimetounix.o: private \ o/$(MODE)/libc/str/dosdatetimetounix.o: private \

View file

@ -20,6 +20,7 @@
#include "libc/macros.internal.h" #include "libc/macros.internal.h"
__polluteregisters: __polluteregisters:
#ifdef __x86_64__
.leafprologue .leafprologue
xor %eax,%eax xor %eax,%eax
xor %ecx,%ecx xor %ecx,%ecx
@ -48,6 +49,9 @@ __polluteregisters:
xorps %xmm6,%xmm6 xorps %xmm6,%xmm6
xorps %xmm7,%xmm7 xorps %xmm7,%xmm7
.leafepilogue .leafepilogue
#else
ret
#endif
.endfn __polluteregisters,globl .endfn __polluteregisters,globl
.end .end

View file

@ -32,10 +32,10 @@
const char *testlib_showerror_errno; const char *testlib_showerror_errno;
const char *testlib_showerror_file; const char *testlib_showerror_file;
const char *testlib_showerror_func; const char *testlib_showerror_func;
const char *testlib_showerror_isfatal;
const char *testlib_showerror_macro; const char *testlib_showerror_macro;
const char *testlib_showerror_symbol; const char *testlib_showerror_symbol;
// TODO(jart): Pay off tech debt re duplication
void testlib_showerror(const char *file, int line, const char *func, void testlib_showerror(const char *file, int line, const char *func,
const char *method, const char *symbol, const char *code, const char *method, const char *symbol, const char *code,
char *v1, char *v2) { char *v1, char *v2) {
@ -56,12 +56,14 @@ void testlib_showerror(const char *file, int line, const char *func,
free(v2); free(v2);
} }
/* TODO(jart): Pay off tech debt re duplication */ static void testlib_showerror_(int line, //
void testlib_showerror_(int line, const char *wantcode, const char *gotcode, const char *wantcode, //
char *FREED_want, char *FREED_got, const char *fmt, const char *gotcode, //
...) { char *FREED_want, //
char *FREED_got, //
const char *fmt, //
va_list va) {
int e; int e;
va_list va;
char hostname[128]; char hostname[128];
e = errno; e = errno;
if (gethostname(hostname, sizeof(hostname))) { if (gethostname(hostname, sizeof(hostname))) {
@ -81,9 +83,7 @@ void testlib_showerror_(int line, const char *wantcode, const char *gotcode,
} }
if (!isempty(fmt)) { if (!isempty(fmt)) {
kprintf("\t"); kprintf("\t");
va_start(va, fmt);
kvprintf(fmt, va); kvprintf(fmt, va);
va_end(va);
kprintf("\n"); kprintf("\n");
} }
kprintf("\t%s%s%s\n" kprintf("\t%s%s%s\n"
@ -93,7 +93,128 @@ void testlib_showerror_(int line, const char *wantcode, const char *gotcode,
free(FREED_want); free(FREED_want);
free(FREED_got); free(FREED_got);
++g_testlib_failed; ++g_testlib_failed;
if (testlib_showerror_isfatal) { }
testlib_abort();
} void testlib_showerror_assert_eq(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "ASSERT_EQ";
testlib_showerror_symbol = "=";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
testlib_abort();
}
void testlib_showerror_expect_eq(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "EXPECT_EQ";
testlib_showerror_symbol = "=";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
}
void testlib_showerror_assert_ne(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "ASSERT_NE";
testlib_showerror_symbol = "";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
testlib_abort();
}
void testlib_showerror_expect_ne(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "EXPECT_NE";
testlib_showerror_symbol = "";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
}
void testlib_showerror_assert_true(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "ASSERT_TRUE";
testlib_showerror_symbol = "";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
testlib_abort();
}
void testlib_showerror_expect_true(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "EXPECT_TRUE";
testlib_showerror_symbol = "";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
}
void testlib_showerror_assert_false(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "ASSERT_FALSE";
testlib_showerror_symbol = "!";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
testlib_abort();
}
void testlib_showerror_expect_false(int line, //
const char *wantcode, //
const char *gotcode, //
char *FREED_want, //
char *FREED_got, //
const char *fmt, //
...) {
va_list va;
testlib_showerror_macro = "EXPECT_FALSE";
testlib_showerror_symbol = "!";
va_start(va, fmt);
testlib_showerror_(line, wantcode, gotcode, FREED_want, FREED_got, fmt, va);
va_end(va);
} }

View file

@ -39,16 +39,6 @@ LIBC_TESTLIB_A_SRCS_S = \
libc/testlib/polluteregisters.S \ libc/testlib/polluteregisters.S \
libc/testlib/testcase.S \ libc/testlib/testcase.S \
libc/testlib/thrashcodecache.S \ libc/testlib/thrashcodecache.S \
libc/testlib/thunks/assert_eq.S \
libc/testlib/thunks/assert_false.S \
libc/testlib/thunks/assert_ne.S \
libc/testlib/thunks/assert_true.S \
libc/testlib/thunks/expect_eq.S \
libc/testlib/thunks/expect_false.S \
libc/testlib/thunks/expect_ne.S \
libc/testlib/thunks/expect_true.S \
libc/testlib/thunks/free.S \
libc/testlib/thunks/jump.S \
libc/testlib/viewables.S libc/testlib/viewables.S
LIBC_TESTLIB_A_SRCS_C = \ LIBC_TESTLIB_A_SRCS_C = \
@ -87,6 +77,7 @@ LIBC_TESTLIB_A_SRCS_C = \
libc/testlib/strequals.c \ libc/testlib/strequals.c \
libc/testlib/strerror.c \ libc/testlib/strerror.c \
libc/testlib/testrunner.c \ libc/testlib/testrunner.c \
libc/testlib/thunks.c \
libc/testlib/waitforexit.c \ libc/testlib/waitforexit.c \
libc/testlib/waitforterm.c \ libc/testlib/waitforterm.c \
libc/testlib/yield.c libc/testlib/yield.c
@ -118,6 +109,7 @@ LIBC_TESTLIB_A_DIRECTDEPS = \
LIBC_TINYMATH \ LIBC_TINYMATH \
LIBC_X \ LIBC_X \
LIBC_ZIPOS \ LIBC_ZIPOS \
THIRD_PARTY_COMPILER_RT \
THIRD_PARTY_DLMALLOC \ THIRD_PARTY_DLMALLOC \
THIRD_PARTY_GDTOA \ THIRD_PARTY_GDTOA \
THIRD_PARTY_XED THIRD_PARTY_XED
@ -139,6 +131,28 @@ o/$(MODE)/libc/testlib/viewables.o: libc/testlib/viewables.txt
o/$(MODE)/libc/testlib/hyperion.o: libc/testlib/hyperion.txt o/$(MODE)/libc/testlib/hyperion.o: libc/testlib/hyperion.txt
o/$(MODE)/libc/testlib/moby.o: libc/testlib/moby.txt o/$(MODE)/libc/testlib/moby.o: libc/testlib/moby.txt
# these assembly files are safe to build on aarch64
o/$(MODE)/libc/testlib/bench.o: libc/testlib/bench.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/blocktronics.o: libc/testlib/blocktronics.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/combo.o: libc/testlib/combo.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/fixture.o: libc/testlib/fixture.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/hyperion.o: libc/testlib/hyperion.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/moby.o: libc/testlib/moby.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/polluteregisters.o: libc/testlib/polluteregisters.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/testcase.o: libc/testlib/testcase.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/thrashcodecache.o: libc/testlib/thrashcodecache.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
o/$(MODE)/libc/testlib/viewables.o: libc/testlib/viewables.S
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
#─────────────────────────────────────────────────────────────────────────────── #───────────────────────────────────────────────────────────────────────────────
LIBC_TESTLIB_ARTIFACTS += LIBC_TESTLIB_RUNNER_A LIBC_TESTLIB_ARTIFACTS += LIBC_TESTLIB_RUNNER_A

View file

@ -21,6 +21,7 @@
// Empties L1 instruction cache. // Empties L1 instruction cache.
thrashcodecache: thrashcodecache:
#ifdef __x86_64__
.leafprologue .leafprologue
push %rbx push %rbx
xor %eax,%eax xor %eax,%eax
@ -42,4 +43,7 @@ thrashcodecache:
cpuid cpuid
pop %rbx pop %rbx
.leafepilogue .leafepilogue
#else
ret
#endif
.endfn thrashcodecache,globl .endfn thrashcodecache,globl

View file

@ -1,7 +1,7 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney Copyright 2023 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the any purpose with or without fee is hereby granted, provided that the
@ -16,13 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE. PERFORMANCE OF THIS SOFTWARE.
*/ */
#include "libc/macros.internal.h" #include "libc/mem/mem.h"
#include "libc/testlib/testlib.h"
.text.unlikely void testlib_free(void *p) {
testlib_showerror_assert_eq: free(p);
push $TRUE }
pushstr "ASSERT_EQ"
pushstr "="
jmp testlib_showerror_jump
.endfn testlib_showerror_assert_eq,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_assert_false:
push $TRUE
pushstr "ASSERT_FALSE"
pushstr "!"
jmp testlib_showerror_jump
.endfn testlib_showerror_assert_false,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_assert_ne:
push $TRUE
pushstr "ASSERT_NE"
pushstr ""
jmp testlib_showerror_jump
.endfn testlib_showerror_assert_ne,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_assert_true:
push $TRUE
pushstr "ASSERT_TRUE"
pushstr ""
jmp testlib_showerror_jump
.endfn testlib_showerror_assert_true,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_expect_eq:
push $FALSE
pushstr "EXPECT_EQ"
pushstr "="
jmp testlib_showerror_jump
.endfn testlib_showerror_expect_eq,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_expect_false:
push $FALSE
pushstr "EXPECT_FALSE"
pushstr "!"
jmp testlib_showerror_jump
.endfn testlib_showerror_expect_false,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_expect_ne:
push $FALSE
pushstr "EXPECT_NE"
pushstr ""
jmp testlib_showerror_jump
.endfn testlib_showerror_expect_ne,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_expect_true:
push $FALSE
pushstr "EXPECT_TRUE"
pushstr ""
jmp testlib_showerror_jump
.endfn testlib_showerror_expect_true,globl,hidden
.previous

View file

@ -1,28 +0,0 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 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/macros.internal.h"
.text.unlikely
testlib_showerror_jump:
popstr testlib_showerror_symbol(%rip)
popstr testlib_showerror_macro(%rip)
pop testlib_showerror_isfatal(%rip)
jmp testlib_showerror_
.endfn testlib_showerror_jump,globl,hidden
.previous

View file

@ -54,6 +54,16 @@ float roundf(float x)
asm("frinta\t%s0,%s1" : "=w"(x) : "w"(x)); asm("frinta\t%s0,%s1" : "=w"(x) : "w"(x));
return x; return x;
#elif defined(__powerpc64__) && defined(_ARCH_PWR5X)
asm("frin\t%0,%1" : "=f"(x) : "f"(x));
return x;
#elif defined(__s390x__) && (defined(__HTM__) || __ARCH__ >= 9)
asm("fiebra\t%0,1,%1,4" : "=f"(x) : "f"(x));
return x;
#else #else
union {float f; uint32_t i;} u = {x}; union {float f; uint32_t i;} u = {x};

View file

@ -29,6 +29,8 @@
#include "libc/calls/struct/iovec.internal.h" #include "libc/calls/struct/iovec.internal.h"
#include "libc/vga/vga.internal.h" #include "libc/vga/vga.internal.h"
#ifdef __x86_64__
ssize_t sys_readv_vga(struct Fd *fd, const struct iovec *iov, int iovlen) { ssize_t sys_readv_vga(struct Fd *fd, const struct iovec *iov, int iovlen) {
/* /*
* NOTE: this routine is always non-blocking. * NOTE: this routine is always non-blocking.
@ -52,3 +54,5 @@ ssize_t sys_readv_vga(struct Fd *fd, const struct iovec *iov, int iovlen) {
if (!redd) return res; if (!redd) return res;
return redd; return redd;
} }
#endif /* __x86_64__ */

View file

@ -30,6 +30,8 @@
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/vga/vga.internal.h" #include "libc/vga/vga.internal.h"
#ifdef __x86_64__
/* /*
* @fileoverview Instantiation of routines for emergency or system console * @fileoverview Instantiation of routines for emergency or system console
* output in graphical video modes. * output in graphical video modes.
@ -95,3 +97,5 @@ privileged void _klog_vga(const char *b, size_t n) {
klog_y = _TtyGetY(&tty); klog_y = _TtyGetY(&tty);
klog_x = _TtyGetX(&tty); klog_x = _TtyGetX(&tty);
} }
#endif /* __x86_64__ */

View file

@ -29,6 +29,8 @@
#include "libc/str/str.h" #include "libc/str/str.h"
#include "libc/vga/vga.internal.h" #include "libc/vga/vga.internal.h"
#ifdef __x86_64__
struct Tty _vga_tty; struct Tty _vga_tty;
void _vga_reinit(struct Tty *tty, unsigned short starty, unsigned short startx, void _vga_reinit(struct Tty *tty, unsigned short starty, unsigned short startx,
@ -70,3 +72,5 @@ textstartup void _vga_init(void) {
_vga_reinit(&_vga_tty, starty, startx, 0); _vga_reinit(&_vga_tty, starty, startx, 0);
} }
} }
#endif /* __x86_64__ */

View file

@ -30,6 +30,8 @@
#include "libc/dce.h" #include "libc/dce.h"
#include "libc/vga/vga.internal.h" #include "libc/vga/vga.internal.h"
#ifdef __x86_64__
ssize_t sys_writev_vga(struct Fd *fd, const struct iovec *iov, int iovlen) { ssize_t sys_writev_vga(struct Fd *fd, const struct iovec *iov, int iovlen) {
size_t i, wrote = 0; size_t i, wrote = 0;
ssize_t res = 0; ssize_t res = 0;
@ -44,3 +46,5 @@ ssize_t sys_writev_vga(struct Fd *fd, const struct iovec *iov, int iovlen) {
if (!wrote) return res; if (!wrote) return res;
return wrote; return wrote;
} }
#endif /* __x86_64__ */

View file

@ -21,36 +21,36 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define acoshl(x) acoshl(VEIL("t", (long double)(x))) double _acosh(double) asm("acosh");
#define acosh(x) acosh(VEIL("x", (double)(x))) float _acoshf(float) asm("acoshf");
#define acoshf(x) acoshf(VEIL("x", (float)(x))) long double _acoshl(long double) asm("acoshl");
TEST(acosh, test) { TEST(acosh, test) {
EXPECT_STREQ(".962423650119207", gc(xdtoa(acosh(1.5)))); EXPECT_STREQ(".962423650119207", gc(xdtoa(_acosh(1.5))));
EXPECT_STREQ("0", gc(xdtoa(acosh(1)))); EXPECT_STREQ("0", gc(xdtoa(_acosh(1))));
EXPECT_TRUE(isnan(acosh(NAN))); EXPECT_TRUE(isnan(_acosh(NAN)));
EXPECT_TRUE(isnan(acosh(.5))); EXPECT_TRUE(isnan(_acosh(.5)));
EXPECT_TRUE(isnan(acosh(-.5))); EXPECT_TRUE(isnan(_acosh(-.5)));
EXPECT_TRUE(isnan(acosh(-1.5))); EXPECT_TRUE(isnan(_acosh(-1.5)));
EXPECT_STREQ("INFINITY", gc(xdtoa(acosh(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_acosh(INFINITY))));
} }
TEST(acoshf, test) { TEST(acoshf, test) {
EXPECT_STREQ(".962424", gc(xdtoaf(acoshf(1.5)))); EXPECT_STREQ(".962424", gc(xdtoaf(_acoshf(1.5))));
EXPECT_STREQ("0", gc(xdtoaf(acoshf(1)))); EXPECT_STREQ("0", gc(xdtoaf(_acoshf(1))));
EXPECT_TRUE(isnan(acoshf(NAN))); EXPECT_TRUE(isnan(_acoshf(NAN)));
EXPECT_TRUE(isnan(acoshf(.5))); EXPECT_TRUE(isnan(_acoshf(.5)));
EXPECT_TRUE(isnan(acoshf(-.5))); EXPECT_TRUE(isnan(_acoshf(-.5)));
EXPECT_TRUE(isnan(acoshf(-1.5))); EXPECT_TRUE(isnan(_acoshf(-1.5)));
EXPECT_STREQ("INFINITY", gc(xdtoaf(acoshf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_acoshf(INFINITY))));
} }
TEST(acoshl, test) { TEST(acoshl, test) {
EXPECT_STREQ(".9624236501192069", gc(xdtoal(acoshl(1.5)))); EXPECT_STREQ(".9624236501192069", gc(xdtoal(_acoshl(1.5))));
EXPECT_STREQ("0", gc(xdtoal(acoshl(1)))); EXPECT_STREQ("0", gc(xdtoal(_acoshl(1))));
EXPECT_TRUE(isnan(acoshl(NAN))); EXPECT_TRUE(isnan(_acoshl(NAN)));
EXPECT_TRUE(isnan(acoshl(.5))); EXPECT_TRUE(isnan(_acoshl(.5)));
EXPECT_TRUE(isnan(acoshl(-.5))); EXPECT_TRUE(isnan(_acoshl(-.5)));
EXPECT_TRUE(isnan(acoshl(-1.5))); EXPECT_TRUE(isnan(_acoshl(-1.5)));
EXPECT_STREQ("INFINITY", gc(xdtoal(acoshl(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_acoshl(INFINITY))));
} }

View file

@ -22,32 +22,32 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "libc/x/xasprintf.h" #include "libc/x/xasprintf.h"
#define asinhl(x) asinhl(VEIL("t", (long double)(x))) double _asinh(double) asm("asinh");
#define asinh(x) asinh(VEIL("x", (double)(x))) float _asinhf(float) asm("asinhf");
#define asinhf(x) asinhf(VEIL("x", (float)(x))) long double _asinhl(long double) asm("asinhl");
TEST(asinh, test) { TEST(asinh, test) {
EXPECT_STREQ(".481211825059603", _gc(xdtoa(asinh(+.5)))); EXPECT_STREQ(".481211825059603", _gc(xdtoa(_asinh(+.5))));
EXPECT_STREQ("-.481211825059603", _gc(xdtoa(asinh(-.5)))); EXPECT_STREQ("-.481211825059603", _gc(xdtoa(_asinh(-.5))));
EXPECT_STREQ("0", _gc(xdtoa(asinh(0)))); EXPECT_STREQ("0", _gc(xdtoa(_asinh(0))));
EXPECT_STREQ("NAN", _gc(xdtoa(asinh(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoa(_asinh(NAN))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(asinh(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoa(_asinh(INFINITY))));
EXPECT_STREQ("-2.1073424255447e-08", EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", asinh(-2.1073424255447e-08)))); _gc(xasprintf("%.15g", _asinh(-2.1073424255447e-08))));
} }
TEST(asinhf, test) { TEST(asinhf, test) {
EXPECT_STREQ(".481212", _gc(xdtoaf(asinhf(+.5)))); EXPECT_STREQ(".481212", _gc(xdtoaf(_asinhf(+.5))));
EXPECT_STREQ("-.481212", _gc(xdtoaf(asinhf(-.5)))); EXPECT_STREQ("-.481212", _gc(xdtoaf(_asinhf(-.5))));
EXPECT_STREQ("0", _gc(xdtoaf(asinhf(0)))); EXPECT_STREQ("0", _gc(xdtoaf(_asinhf(0))));
EXPECT_STREQ("NAN", _gc(xdtoaf(asinhf(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoaf(_asinhf(NAN))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(asinhf(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoaf(_asinhf(INFINITY))));
} }
TEST(asinhl, test) { TEST(asinhl, test) {
EXPECT_STREQ(".4812118250596034", _gc(xdtoal(asinhl(+.5)))); EXPECT_STREQ(".4812118250596034", _gc(xdtoal(_asinhl(+.5))));
EXPECT_STREQ("-.4812118250596034", _gc(xdtoal(asinhl(-.5)))); EXPECT_STREQ("-.4812118250596034", _gc(xdtoal(_asinhl(-.5))));
EXPECT_STREQ("0", _gc(xdtoal(asinhl(0)))); EXPECT_STREQ("0", _gc(xdtoal(_asinhl(0))));
EXPECT_STREQ("NAN", _gc(xdtoal(asinhl(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoal(_asinhl(NAN))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(asinhl(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoal(_asinhl(INFINITY))));
} }

View file

@ -23,48 +23,48 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "libc/x/xasprintf.h" #include "libc/x/xasprintf.h"
#define atanhl(x) atanhl(VEIL("t", (long double)(x))) double _atanh(double) asm("atanh");
#define atanh(x) atanh(VEIL("x", (double)(x))) float _atanhf(float) asm("atanhf");
#define atanhf(x) atanhf(VEIL("x", (float)(x))) long double _atanhl(long double) asm("atanhl");
TEST(atanh, test) { TEST(atanh, test) {
EXPECT_STREQ("0", _gc(xdtoa(atanh(0)))); EXPECT_STREQ("0", _gc(xdtoa(_atanh(0))));
EXPECT_STREQ("-0", _gc(xdtoa(atanh(-0.)))); EXPECT_STREQ("-0", _gc(xdtoa(_atanh(-0.))));
EXPECT_STREQ(".549306144334055", _gc(xdtoa(atanh(.5)))); EXPECT_STREQ(".549306144334055", _gc(xdtoa(_atanh(.5))));
EXPECT_STREQ("-.549306144334055", _gc(xdtoa(atanh(-.5)))); EXPECT_STREQ("-.549306144334055", _gc(xdtoa(_atanh(-.5))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(atanh(+1)))); EXPECT_STREQ("INFINITY", _gc(xdtoa(_atanh(+1))));
EXPECT_STREQ("-INFINITY", _gc(xdtoa(atanh(-1)))); EXPECT_STREQ("-INFINITY", _gc(xdtoa(_atanh(-1))));
EXPECT_TRUE(isnan(atanh(+1.1))); EXPECT_TRUE(isnan(_atanh(+1.1)));
EXPECT_TRUE(isnan(atanh(-1.1))); EXPECT_TRUE(isnan(_atanh(-1.1)));
EXPECT_STREQ("-2.1073424255447e-08", EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", atanh(-2.1073424255447e-08)))); _gc(xasprintf("%.15g", _atanh(-2.1073424255447e-08))));
} }
TEST(atanhl, test) { TEST(atanhl, test) {
EXPECT_STREQ("0", _gc(xdtoal(atanhl(0)))); EXPECT_STREQ("0", _gc(xdtoal(_atanhl(0))));
EXPECT_STREQ("-0", _gc(xdtoal(atanhl(-0.)))); EXPECT_STREQ("-0", _gc(xdtoal(_atanhl(-0.))));
EXPECT_STREQ(".5493061443340548", _gc(xdtoal(atanhl(.5)))); EXPECT_STREQ(".5493061443340548", _gc(xdtoal(_atanhl(.5))));
EXPECT_STREQ("-.5493061443340548", _gc(xdtoal(atanhl(-.5)))); EXPECT_STREQ("-.5493061443340548", _gc(xdtoal(_atanhl(-.5))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(atanhl(+1)))); EXPECT_STREQ("INFINITY", _gc(xdtoal(_atanhl(+1))));
EXPECT_STREQ("-INFINITY", _gc(xdtoal(atanhl(-1)))); EXPECT_STREQ("-INFINITY", _gc(xdtoal(_atanhl(-1))));
EXPECT_TRUE(isnan(atanhl(+1.1))); EXPECT_TRUE(isnan(_atanhl(+1.1)));
EXPECT_TRUE(isnan(atanhl(-1.1))); EXPECT_TRUE(isnan(_atanhl(-1.1)));
} }
TEST(atanhf, test) { TEST(atanhf, test) {
EXPECT_STREQ("0", _gc(xdtoaf(atanhf(0)))); EXPECT_STREQ("0", _gc(xdtoaf(_atanhf(0))));
EXPECT_STREQ("-0", _gc(xdtoaf(atanhf(-0.)))); EXPECT_STREQ("-0", _gc(xdtoaf(_atanhf(-0.))));
EXPECT_STREQ(".549306", _gc(xdtoaf(atanhf(.5)))); EXPECT_STREQ(".549306", _gc(xdtoaf(_atanhf(.5))));
EXPECT_STREQ("-.549306", _gc(xdtoaf(atanhf(-.5)))); EXPECT_STREQ("-.549306", _gc(xdtoaf(_atanhf(-.5))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(atanhf(+1)))); EXPECT_STREQ("INFINITY", _gc(xdtoaf(_atanhf(+1))));
EXPECT_STREQ("-INFINITY", _gc(xdtoaf(atanhf(-1)))); EXPECT_STREQ("-INFINITY", _gc(xdtoaf(_atanhf(-1))));
EXPECT_TRUE(isnan(atanhf(+1.1))); EXPECT_TRUE(isnan(_atanhf(+1.1)));
EXPECT_TRUE(isnan(atanhf(-1.1))); EXPECT_TRUE(isnan(_atanhf(-1.1)));
} }
BENCH(atanh, bench) { BENCH(_atanh, bench) {
volatile double a = .5; volatile double a = .5;
EZBENCH2("atanhf", donothing, EXPROPRIATE(atanhf(a))); EZBENCH2("atanhf", donothing, EXPROPRIATE(_atanhf(a)));
EZBENCH2("atanh", donothing, EXPROPRIATE(atanh(a))); EZBENCH2("atanh", donothing, EXPROPRIATE(_atanh(a)));
EZBENCH2("atanhl", donothing, EXPROPRIATE(atanhl(a))); EZBENCH2("atanhl", donothing, EXPROPRIATE(_atanhl(a)));
} }

View file

@ -21,42 +21,42 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define coshl(x) coshl(VEIL("t", (long double)(x))) double _cosh(double) asm("cosh");
#define cosh(x) cosh(VEIL("x", (double)(x))) float _coshf(float) asm("coshf");
#define coshf(x) coshf(VEIL("x", (float)(x))) long double _coshl(long double) asm("coshl");
TEST(coshl, test) { TEST(coshl, test) {
EXPECT_STREQ("1.127625965206381", gc(xdtoal(coshl(+.5)))); EXPECT_STREQ("1.127625965206381", gc(xdtoal(_coshl(+.5))));
EXPECT_STREQ("1.127625965206381", gc(xdtoal(coshl(-.5)))); EXPECT_STREQ("1.127625965206381", gc(xdtoal(_coshl(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoal(coshl(30000)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_coshl(30000))));
EXPECT_STREQ("INFINITY", gc(xdtoal(coshl(-30000)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_coshl(-30000))));
EXPECT_STREQ("1", gc(xdtoal(coshl(+0.)))); EXPECT_STREQ("1", gc(xdtoal(_coshl(+0.))));
EXPECT_STREQ("1", gc(xdtoal(coshl(-0.)))); EXPECT_STREQ("1", gc(xdtoal(_coshl(-0.))));
EXPECT_TRUE(isnan(coshl(NAN))); EXPECT_TRUE(isnan(_coshl(NAN)));
EXPECT_STREQ("INFINITY", gc(xdtoal(coshl(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_coshl(INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoal(coshl(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_coshl(-INFINITY))));
} }
TEST(cosh, test) { TEST(cosh, test) {
EXPECT_STREQ("1.12762596520638", gc(xdtoa(cosh(+.5)))); EXPECT_STREQ("1.12762596520638", gc(xdtoa(_cosh(+.5))));
EXPECT_STREQ("1.12762596520638", gc(xdtoa(cosh(-.5)))); EXPECT_STREQ("1.12762596520638", gc(xdtoa(_cosh(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoa(cosh(30000)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_cosh(30000))));
EXPECT_STREQ("INFINITY", gc(xdtoa(cosh(-30000)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_cosh(-30000))));
EXPECT_STREQ("1", gc(xdtoa(cosh(+0.)))); EXPECT_STREQ("1", gc(xdtoa(_cosh(+0.))));
EXPECT_STREQ("1", gc(xdtoa(cosh(-0.)))); EXPECT_STREQ("1", gc(xdtoa(_cosh(-0.))));
EXPECT_TRUE(isnan(cosh(NAN))); EXPECT_TRUE(isnan(_cosh(NAN)));
EXPECT_STREQ("INFINITY", gc(xdtoa(cosh(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_cosh(INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoa(cosh(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_cosh(-INFINITY))));
} }
TEST(coshf, test) { TEST(coshf, test) {
EXPECT_STREQ("1.12763", gc(xdtoaf(coshf(+.5)))); EXPECT_STREQ("1.12763", gc(xdtoaf(_coshf(+.5))));
EXPECT_STREQ("1.12763", gc(xdtoaf(coshf(-.5)))); EXPECT_STREQ("1.12763", gc(xdtoaf(_coshf(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(coshf(30000)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_coshf(30000))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(coshf(-30000)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_coshf(-30000))));
EXPECT_STREQ("1", gc(xdtoaf(coshf(+0.)))); EXPECT_STREQ("1", gc(xdtoaf(_coshf(+0.))));
EXPECT_STREQ("1", gc(xdtoaf(coshf(-0.)))); EXPECT_STREQ("1", gc(xdtoaf(_coshf(-0.))));
EXPECT_TRUE(isnan(coshf(NAN))); EXPECT_TRUE(isnan(_coshf(NAN)));
EXPECT_STREQ("INFINITY", gc(xdtoaf(coshf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_coshf(INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(coshf(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_coshf(-INFINITY))));
} }

View file

@ -21,39 +21,39 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define exp10l(x) exp10l(VEIL("t", (long double)(x))) double _exp10(double) asm("exp10");
#define exp10(x) exp10(VEIL("x", (double)(x))) float _exp10f(float) asm("exp10f");
#define exp10f(x) exp10f(VEIL("x", (float)(x))) long double _exp10l(long double) asm("exp10l");
TEST(exp10l, test) { TEST(exp10l, test) {
EXPECT_STREQ("1", gc(xdtoal(exp10l(0)))); EXPECT_STREQ("1", gc(xdtoal(_exp10l(0))));
EXPECT_STREQ("1", gc(xdtoal(exp10l(-0.)))); EXPECT_STREQ("1", gc(xdtoal(_exp10l(-0.))));
EXPECT_STREQ(".01", gc(xdtoal(exp10l(-2.)))); EXPECT_STREQ(".01", gc(xdtoal(_exp10l(-2.))));
EXPECT_STREQ("INFINITY", gc(xdtoal(exp10l(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_exp10l(INFINITY))));
EXPECT_STREQ("0", gc(xdtoal(exp10l(-INFINITY)))); EXPECT_STREQ("0", gc(xdtoal(_exp10l(-INFINITY))));
EXPECT_STREQ("NAN", gc(xdtoal(exp10l(NAN)))); EXPECT_STREQ("NAN", gc(xdtoal(_exp10l(NAN))));
EXPECT_STREQ("0", gc(xdtoal(exp10l(-132098844872390)))); EXPECT_STREQ("0", gc(xdtoal(_exp10l(-132098844872390))));
EXPECT_STREQ("INFINITY", gc(xdtoal(exp10l(132098844872390)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_exp10l(132098844872390))));
} }
TEST(exp10, test) { TEST(exp10, test) {
EXPECT_STREQ("1", gc(xdtoa(exp10(0)))); EXPECT_STREQ("1", gc(xdtoa(_exp10(0))));
EXPECT_STREQ("1", gc(xdtoa(exp10(-0.)))); EXPECT_STREQ("1", gc(xdtoa(_exp10(-0.))));
EXPECT_STREQ(".01", gc(xdtoa(exp10(-2.)))); EXPECT_STREQ(".01", gc(xdtoa(_exp10(-2.))));
EXPECT_STREQ("INFINITY", gc(xdtoa(exp10(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_exp10(INFINITY))));
EXPECT_STREQ("0", gc(xdtoa(exp10(-INFINITY)))); EXPECT_STREQ("0", gc(xdtoa(_exp10(-INFINITY))));
EXPECT_STREQ("NAN", gc(xdtoa(exp10(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_exp10(NAN))));
EXPECT_STREQ("0", gc(xdtoa(exp10(-132098844872390)))); EXPECT_STREQ("0", gc(xdtoa(_exp10(-132098844872390))));
EXPECT_STREQ("INFINITY", gc(xdtoa(exp10(132098844872390)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_exp10(132098844872390))));
} }
TEST(exp10f, test) { TEST(exp10f, test) {
EXPECT_STREQ("1", gc(xdtoaf(exp10f(0)))); EXPECT_STREQ("1", gc(xdtoaf(_exp10f(0))));
EXPECT_STREQ("1", gc(xdtoaf(exp10f(-0.)))); EXPECT_STREQ("1", gc(xdtoaf(_exp10f(-0.))));
EXPECT_STREQ(".01", gc(xdtoaf(exp10f(-2.)))); EXPECT_STREQ(".01", gc(xdtoaf(_exp10f(-2.))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp10f(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_exp10f(INFINITY))));
EXPECT_STREQ("0", gc(xdtoaf(exp10f(-INFINITY)))); EXPECT_STREQ("0", gc(xdtoaf(_exp10f(-INFINITY))));
EXPECT_STREQ("NAN", gc(xdtoaf(exp10f(NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_exp10f(NAN))));
EXPECT_STREQ("0", gc(xdtoaf(exp10f(-132098844872390)))); EXPECT_STREQ("0", gc(xdtoaf(_exp10f(-132098844872390))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp10f(132098844872390)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_exp10f(132098844872390))));
} }

View file

@ -22,44 +22,41 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define exp2l(x) exp2l(VEIL("t", (long double)(x))) double _exp2(double) asm("exp2");
#define exp2(x) exp2(VEIL("x", (double)(x))) float _exp2f(float) asm("exp2f");
#define exp2f(x) exp2f(VEIL("x", (float)(x))) long double _exp2l(long double) asm("exp2l");
TEST(exp2l, test) { TEST(exp2l, test) {
EXPECT_STREQ("1", gc(xdtoal(exp2l(0)))); EXPECT_STREQ("1", gc(xdtoal(_exp2l(0))));
EXPECT_STREQ("1", gc(xdtoal(exp2l(-0.)))); EXPECT_STREQ("1", gc(xdtoal(_exp2l(-0.))));
EXPECT_STREQ("INFINITY", gc(xdtoal(exp2l(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_exp2l(INFINITY))));
EXPECT_STREQ("0", gc(xdtoal(exp2l(-INFINITY)))); EXPECT_STREQ("0", gc(xdtoal(_exp2l(-INFINITY))));
EXPECT_STREQ("NAN", gc(xdtoal(exp2l(NAN)))); EXPECT_STREQ("NAN", gc(xdtoal(_exp2l(NAN))));
EXPECT_STREQ("0", gc(xdtoal(exp2l(-132098844872390)))); EXPECT_STREQ("0", gc(xdtoal(_exp2l(-132098844872390))));
EXPECT_STREQ("INFINITY", gc(xdtoal(exp2l(132098844872390)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_exp2l(132098844872390))));
} }
TEST(exp2, test) { TEST(exp2, test) {
EXPECT_STREQ("1", gc(xdtoa(exp2(0)))); EXPECT_STREQ("1", gc(xdtoa(_exp2(0))));
EXPECT_STREQ("1", gc(xdtoa(exp2(-0.)))); EXPECT_STREQ("1", gc(xdtoa(_exp2(-0.))));
EXPECT_STREQ("INFINITY", gc(xdtoa(exp2(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_exp2(INFINITY))));
EXPECT_STREQ("0", gc(xdtoa(exp2(-INFINITY)))); EXPECT_STREQ("0", gc(xdtoa(_exp2(-INFINITY))));
EXPECT_STREQ("NAN", gc(xdtoa(exp2(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_exp2(NAN))));
EXPECT_STREQ("0", gc(xdtoa(exp2(-132098844872390)))); EXPECT_STREQ("0", gc(xdtoa(_exp2(-132098844872390))));
EXPECT_STREQ("INFINITY", gc(xdtoa(exp2(132098844872390)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_exp2(132098844872390))));
} }
TEST(exp2f, test) { TEST(exp2f, test) {
EXPECT_STREQ("1", gc(xdtoaf(exp2f(0)))); EXPECT_STREQ("1", gc(xdtoaf(_exp2f(0))));
EXPECT_STREQ("1", gc(xdtoaf(exp2f(-0.)))); EXPECT_STREQ("1", gc(xdtoaf(_exp2f(-0.))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp2f(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_exp2f(INFINITY))));
EXPECT_STREQ("0", gc(xdtoaf(exp2f(-INFINITY)))); EXPECT_STREQ("0", gc(xdtoaf(_exp2f(-INFINITY))));
EXPECT_STREQ("NAN", gc(xdtoaf(exp2f(NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_exp2f(NAN))));
EXPECT_STREQ("0", gc(xdtoaf(exp2f(-132098844872390)))); EXPECT_STREQ("0", gc(xdtoaf(_exp2f(-132098844872390))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(exp2f(132098844872390)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_exp2f(132098844872390))));
} }
BENCH(exp2l, bench) { BENCH(_exp2l, bench) {
double _exp2(double) asm("exp2");
float _exp2f(float) asm("exp2f");
long double _exp2l(long double) asm("exp2l");
EZBENCH2("exp2", donothing, _exp2(.7)); /* ~6ns */ EZBENCH2("exp2", donothing, _exp2(.7)); /* ~6ns */
EZBENCH2("exp2f", donothing, _exp2f(.7)); /* ~5ns */ EZBENCH2("exp2f", donothing, _exp2f(.7)); /* ~5ns */
EZBENCH2("exp2l", donothing, _exp2l(.7)); /* ~30ns */ EZBENCH2("exp2l", donothing, _exp2l(.7)); /* ~30ns */

View file

@ -24,50 +24,47 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "libc/x/xasprintf.h" #include "libc/x/xasprintf.h"
#define expl(x) expl(VEIL("t", (long double)(x))) double _exp(double) asm("exp");
#define exp(x) exp(VEIL("x", (double)(x))) float _expf(float) asm("expf");
#define expf(x) expf(VEIL("x", (float)(x))) long double _expl(long double) asm("expl");
TEST(expl, test) { TEST(expl, test) {
EXPECT_STREQ("1", _gc(xdtoal(expl(0)))); EXPECT_STREQ("1", _gc(xdtoal(_expl(0))));
EXPECT_STREQ("1", _gc(xdtoal(expl(-0.)))); EXPECT_STREQ("1", _gc(xdtoal(_expl(-0.))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(expl(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoal(_expl(INFINITY))));
EXPECT_STREQ("0", _gc(xdtoal(expl(-INFINITY)))); EXPECT_STREQ("0", _gc(xdtoal(_expl(-INFINITY))));
EXPECT_STREQ("NAN", _gc(xdtoal(expl(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoal(_expl(NAN))));
EXPECT_STREQ("0", _gc(xdtoal(expl(-132098844872390)))); EXPECT_STREQ("0", _gc(xdtoal(_expl(-132098844872390))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(expl(132098844872390)))); EXPECT_STREQ("INFINITY", _gc(xdtoal(_expl(132098844872390))));
} }
TEST(exp, test) { TEST(exp, test) {
EXPECT_STREQ("1", _gc(xdtoa(exp(0)))); EXPECT_STREQ("1", _gc(xdtoa(_exp(0))));
EXPECT_STREQ("1", _gc(xdtoa(exp(-0.)))); EXPECT_STREQ("1", _gc(xdtoa(_exp(-0.))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(exp(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoa(_exp(INFINITY))));
EXPECT_STREQ("0", _gc(xdtoa(exp(-INFINITY)))); EXPECT_STREQ("0", _gc(xdtoa(_exp(-INFINITY))));
EXPECT_STREQ("NAN", _gc(xdtoa(exp(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoa(_exp(NAN))));
EXPECT_STREQ("0", _gc(xdtoa(exp(-132098844872390)))); EXPECT_STREQ("0", _gc(xdtoa(_exp(-132098844872390))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(exp(132098844872390)))); EXPECT_STREQ("INFINITY", _gc(xdtoa(_exp(132098844872390))));
} }
TEST(expf, test) { TEST(expf, test) {
EXPECT_STREQ("1", _gc(xdtoaf(expf(0)))); EXPECT_STREQ("1", _gc(xdtoaf(_expf(0))));
EXPECT_STREQ("1", _gc(xdtoaf(expf(-0.)))); EXPECT_STREQ("1", _gc(xdtoaf(_expf(-0.))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(expf(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoaf(_expf(INFINITY))));
EXPECT_STREQ("0", _gc(xdtoaf(expf(-INFINITY)))); EXPECT_STREQ("0", _gc(xdtoaf(_expf(-INFINITY))));
EXPECT_STREQ("NAN", _gc(xdtoaf(expf(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoaf(_expf(NAN))));
EXPECT_STREQ("0", _gc(xdtoaf(expf(-132098844872390)))); EXPECT_STREQ("0", _gc(xdtoaf(_expf(-132098844872390))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(expf(132098844872390)))); EXPECT_STREQ("INFINITY", _gc(xdtoaf(_expf(132098844872390))));
} }
TEST(exp, fun) { TEST(exp, fun) {
ASSERT_STREQ("7.389056", _gc(xasprintf("%f", exp(2.0)))); ASSERT_STREQ("7.389056", _gc(xasprintf("%f", _exp(2.0))));
ASSERT_STREQ("6.389056", _gc(xasprintf("%f", expm1(2.0)))); ASSERT_STREQ("6.389056", _gc(xasprintf("%f", expm1(2.0))));
ASSERT_STREQ("6.389056", _gc(xasprintf("%f", exp(2.0) - 1.0))); ASSERT_STREQ("6.389056", _gc(xasprintf("%f", _exp(2.0) - 1.0)));
} }
BENCH(expl, bench) { BENCH(_expl, bench) {
double _exp(double) asm("exp");
float _expf(float) asm("expf");
long double _expl(long double) asm("expl");
EZBENCH2("exp", donothing, _exp(.7)); /* ~6ns */ EZBENCH2("exp", donothing, _exp(.7)); /* ~6ns */
EZBENCH2("expf", donothing, _expf(.7)); /* ~5ns */ EZBENCH2("expf", donothing, _expf(.7)); /* ~5ns */
EZBENCH2("expl", donothing, _expl(.7)); /* ~20ns */ EZBENCH2("expl", donothing, _expl(.7)); /* ~20ns */

View file

@ -22,54 +22,54 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "libc/x/xasprintf.h" #include "libc/x/xasprintf.h"
#define expm1l(x) expm1l(VEIL("t", (long double)(x))) double _expm1(double) asm("expm1");
#define expm1(x) expm1(VEIL("x", (double)(x))) float _expm1f(float) asm("expm1f");
#define expm1f(x) expm1f(VEIL("x", (float)(x))) long double _expm1l(long double) asm("expm1l");
TEST(expm1, test) { TEST(expm1, test) {
EXPECT_STREQ("0", _gc(xdtoa(expm1(0)))); EXPECT_STREQ("0", _gc(xdtoa(_expm1(0))));
EXPECT_STREQ("-0", _gc(xdtoa(expm1(-0.)))); EXPECT_STREQ("-0", _gc(xdtoa(_expm1(-0.))));
EXPECT_STREQ("NAN", _gc(xdtoa(expm1(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoa(_expm1(NAN))));
EXPECT_STREQ("-1", _gc(xdtoa(expm1(-INFINITY)))); EXPECT_STREQ("-1", _gc(xdtoa(_expm1(-INFINITY))));
EXPECT_STREQ("INFINITY", _gc(xdtoa(expm1(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoa(_expm1(INFINITY))));
/* EXPECT_STREQ("-INFINITY", _gc(xdtoa(expm1(-132098844872390)))); */ /* EXPECT_STREQ("-INFINITY", _gc(xdtoa(_expm1(-132098844872390)))); */
/* EXPECT_STREQ("INFINITY", _gc(xdtoa(expm1(132098844872390)))); */ /* EXPECT_STREQ("INFINITY", _gc(xdtoa(_expm1(132098844872390)))); */
EXPECT_STREQ("0", _gc(xasprintf("%.15g", expm1(0.)))); EXPECT_STREQ("0", _gc(xasprintf("%.15g", _expm1(0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", expm1(-0.)))); EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _expm1(-0.))));
EXPECT_STREQ("0.648721270700128", _gc(xasprintf("%.15g", expm1(.5)))); EXPECT_STREQ("0.648721270700128", _gc(xasprintf("%.15g", _expm1(.5))));
EXPECT_STREQ("-0.393469340287367", _gc(xasprintf("%.15g", expm1(-.5)))); EXPECT_STREQ("-0.393469340287367", _gc(xasprintf("%.15g", _expm1(-.5))));
EXPECT_STREQ("1.71828182845905", _gc(xasprintf("%.15g", expm1(1.)))); EXPECT_STREQ("1.71828182845905", _gc(xasprintf("%.15g", _expm1(1.))));
EXPECT_STREQ("-0.632120558828558", _gc(xasprintf("%.15g", expm1(-1.)))); EXPECT_STREQ("-0.632120558828558", _gc(xasprintf("%.15g", _expm1(-1.))));
EXPECT_STREQ("3.48168907033806", _gc(xasprintf("%.15g", expm1(1.5)))); EXPECT_STREQ("3.48168907033806", _gc(xasprintf("%.15g", _expm1(1.5))));
EXPECT_STREQ("-0.77686983985157", _gc(xasprintf("%.15g", expm1(-1.5)))); EXPECT_STREQ("-0.77686983985157", _gc(xasprintf("%.15g", _expm1(-1.5))));
EXPECT_STREQ("6.38905609893065", _gc(xasprintf("%.15g", expm1(2.)))); EXPECT_STREQ("6.38905609893065", _gc(xasprintf("%.15g", _expm1(2.))));
EXPECT_TRUE(isnan(expm1(NAN))); EXPECT_TRUE(isnan(_expm1(NAN)));
EXPECT_TRUE(isnan(expm1(-NAN))); EXPECT_TRUE(isnan(_expm1(-NAN)));
EXPECT_STREQ("inf", _gc(xasprintf("%.15g", expm1(INFINITY)))); EXPECT_STREQ("inf", _gc(xasprintf("%.15g", _expm1(INFINITY))));
EXPECT_STREQ("-1", _gc(xasprintf("%.15g", expm1(-INFINITY)))); EXPECT_STREQ("-1", _gc(xasprintf("%.15g", _expm1(-INFINITY))));
EXPECT_STREQ("2.2250738585072e-308", EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", expm1(__DBL_MIN__)))); _gc(xasprintf("%.15g", _expm1(__DBL_MIN__))));
EXPECT_STREQ("inf", _gc(xasprintf("%.15g", expm1(__DBL_MAX__)))); EXPECT_STREQ("inf", _gc(xasprintf("%.15g", _expm1(__DBL_MAX__))));
} }
TEST(expm1l, test) { TEST(expm1l, test) {
EXPECT_STREQ("1.718281828459045", _gc(xdtoal(expm1l(1)))); EXPECT_STREQ("1.718281828459045", _gc(xdtoal(_expm1l(1))));
EXPECT_STREQ("1.718281828459045", _gc(xdtoal(expl(1) - 1))); EXPECT_STREQ("1.718281828459045", _gc(xdtoal(expl(1) - 1)));
EXPECT_STREQ("0", _gc(xdtoal(expm1l(0)))); EXPECT_STREQ("0", _gc(xdtoal(_expm1l(0))));
EXPECT_STREQ("-0", _gc(xdtoal(expm1l(-0.)))); EXPECT_STREQ("-0", _gc(xdtoal(_expm1l(-0.))));
EXPECT_STREQ("NAN", _gc(xdtoal(expm1l(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoal(_expm1l(NAN))));
EXPECT_STREQ("-1", _gc(xdtoal(expm1l(-INFINITY)))); EXPECT_STREQ("-1", _gc(xdtoal(_expm1l(-INFINITY))));
EXPECT_STREQ("INFINITY", _gc(xdtoal(expm1l(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoal(_expm1l(INFINITY))));
/* EXPECT_STREQ("-INFINITY", _gc(xdtoal(expm1l(-132098844872390)))); */ /* EXPECT_STREQ("-INFINITY", _gc(xdtoal(_expm1l(-132098844872390)))); */
/* EXPECT_STREQ("INFINITY", _gc(xdtoal(expm1l(132098844872390)))); */ /* EXPECT_STREQ("INFINITY", _gc(xdtoal(_expm1l(132098844872390)))); */
} }
TEST(expm1f, test) { TEST(expm1f, test) {
EXPECT_STREQ("0", _gc(xdtoaf(expm1f(0)))); EXPECT_STREQ("0", _gc(xdtoaf(_expm1f(0))));
EXPECT_STREQ("-0", _gc(xdtoaf(expm1f(-0.)))); EXPECT_STREQ("-0", _gc(xdtoaf(_expm1f(-0.))));
EXPECT_STREQ("NAN", _gc(xdtoaf(expm1f(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoaf(_expm1f(NAN))));
EXPECT_STREQ("-1", _gc(xdtoaf(expm1f(-INFINITY)))); EXPECT_STREQ("-1", _gc(xdtoaf(_expm1f(-INFINITY))));
EXPECT_STREQ("INFINITY", _gc(xdtoaf(expm1f(INFINITY)))); EXPECT_STREQ("INFINITY", _gc(xdtoaf(_expm1f(INFINITY))));
/* EXPECT_STREQ("-INFINITY", _gc(xdtoaf(expm1f(-132098844872390)))); */ /* EXPECT_STREQ("-INFINITY", _gc(xdtoaf(_expm1f(-132098844872390)))); */
/* EXPECT_STREQ("INFINITY", _gc(xdtoaf(expm1f(132098844872390)))); */ /* EXPECT_STREQ("INFINITY", _gc(xdtoaf(_expm1f(132098844872390)))); */
} }

View file

@ -22,46 +22,43 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define fabsl(x) fabsl(VEIL("t", (long double)(x))) double _fabs(double) asm("fabs");
#define fabs(x) fabs(VEIL("x", (double)(x))) float _fabsf(float) asm("fabsf");
#define fabsf(x) fabsf(VEIL("x", (float)(x))) long double _fabsl(long double) asm("fabsl");
TEST(fabsl, test) { TEST(fabsl, test) {
EXPECT_STREQ("0", gc(xdtoal(fabsl(-0.)))); EXPECT_STREQ("0", gc(xdtoal(_fabsl(-0.))));
EXPECT_STREQ("0", gc(xdtoal(fabsl(-0.)))); EXPECT_STREQ("0", gc(xdtoal(_fabsl(-0.))));
EXPECT_STREQ("NAN", gc(xdtoal(fabsl(NAN)))); EXPECT_STREQ("NAN", gc(xdtoal(_fabsl(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(fabsl(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_fabsl(INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoal(fabsl(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_fabsl(-INFINITY))));
} }
TEST(fabs, test) { TEST(fabs, test) {
EXPECT_STREQ("0", gc(xdtoa(fabs(-0.)))); EXPECT_STREQ("0", gc(xdtoa(_fabs(-0.))));
EXPECT_STREQ("0", gc(xdtoa(fabs(-0.)))); EXPECT_STREQ("0", gc(xdtoa(_fabs(-0.))));
EXPECT_STREQ("NAN", gc(xdtoa(fabs(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_fabs(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(fabs(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_fabs(INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoa(fabs(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_fabs(-INFINITY))));
} }
TEST(fabsf, test) { TEST(fabsf, test) {
EXPECT_STREQ("0", gc(xdtoaf(fabsf(-0.)))); EXPECT_STREQ("0", gc(xdtoaf(_fabsf(-0.))));
EXPECT_STREQ("0", gc(xdtoaf(fabsf(-0.)))); EXPECT_STREQ("0", gc(xdtoaf(_fabsf(-0.))));
EXPECT_STREQ("NAN", gc(xdtoaf(fabsf(NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_fabsf(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(fabsf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_fabsf(INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(fabsf(-INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_fabsf(-INFINITY))));
} }
TEST(fabs, stuff) { TEST(fabs, stuff) {
EXPECT_LDBL_EQ(3.14, fabs(3.14)); EXPECT_LDBL_EQ(3.14, _fabs(3.14));
EXPECT_LDBL_EQ(3.14, fabs(-3.14)); EXPECT_LDBL_EQ(3.14, _fabs(-3.14));
EXPECT_EQ(1, !!isnan(fabs(NAN))); EXPECT_EQ(1, !!isnan(_fabs(NAN)));
EXPECT_EQ(1, !!isnan(fabs(-NAN))); EXPECT_EQ(1, !!isnan(_fabs(-NAN)));
EXPECT_EQ(0, !!signbit(fabs(-NAN))); EXPECT_EQ(0, !!signbit(_fabs(-NAN)));
} }
BENCH(fabs, bench) { BENCH(fabs, bench) {
double _fabs(double) asm("fabs");
float _fabsf(float) asm("fabsf");
long double _fabsl(long double) asm("fabsl");
EZBENCH2("fabs", donothing, _fabs(.7)); /* ~6ns */ EZBENCH2("fabs", donothing, _fabs(.7)); /* ~6ns */
EZBENCH2("fabsf", donothing, _fabsf(.7)); /* ~5ns */ EZBENCH2("fabsf", donothing, _fabsf(.7)); /* ~5ns */
EZBENCH2("fabsl", donothing, _fabsl(.7)); /* ~28ns */ EZBENCH2("fabsl", donothing, _fabsl(.7)); /* ~28ns */

View file

@ -22,106 +22,106 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define hypotl(x, y) \ double _hypot(double, double) asm("hypot");
hypotl(VEIL("t", (long double)(x)), VEIL("t", (long double)(y))) float _hypotf(float, float) asm("hypotf");
#define hypot(x, y) hypot(VEIL("x", (double)(x)), VEIL("x", (double)(y))) long double _hypotl(long double, long double) asm("hypotl");
#define hypotf(x, y) hypotf(VEIL("x", (float)(x)), VEIL("x", (float)(y)))
TEST(hypot, test) { TEST(hypot, test) {
EXPECT_STREQ("0", gc(xdtoa(hypot(0, 0)))); EXPECT_STREQ("0", gc(xdtoa(_hypot(0, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypot(3, 0)))); EXPECT_STREQ("3", gc(xdtoa(_hypot(3, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypot(0, 3)))); EXPECT_STREQ("3", gc(xdtoa(_hypot(0, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypot(3, 4)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(3, 4))));
EXPECT_STREQ("5", gc(xdtoa(hypot(4, 3)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(4, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypot(3, -4)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypot(-4, 3)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(-4, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypot(-3, 4)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(-3, 4))));
EXPECT_STREQ("5", gc(xdtoa(hypot(4, -3)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(4, -3))));
EXPECT_STREQ("5", gc(xdtoa(hypot(-3, -4)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(-3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypot(-4, -3)))); EXPECT_STREQ("5", gc(xdtoa(_hypot(-4, -3))));
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(1, 1)))); EXPECT_STREQ("1.4142135623731", gc(xdtoa(_hypot(1, 1))));
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(1, -1)))); EXPECT_STREQ("1.4142135623731", gc(xdtoa(_hypot(1, -1))));
EXPECT_STREQ("1.4142135623731", gc(xdtoa(hypot(-1, 1)))); EXPECT_STREQ("1.4142135623731", gc(xdtoa(_hypot(-1, 1))));
EXPECT_STREQ("1.41421362601271", gc(xdtoa(hypot(1.0000001, .99999999)))); EXPECT_STREQ("1.41421362601271", gc(xdtoa(_hypot(1.0000001, .99999999))));
EXPECT_STREQ("1.41421362601271", gc(xdtoa(hypot(.99999999, 1.0000001)))); EXPECT_STREQ("1.41421362601271", gc(xdtoa(_hypot(.99999999, 1.0000001))));
EXPECT_STREQ("1.4142135623731e+154", gc(xdtoa(hypot(1e154, 1e154)))); EXPECT_STREQ("1.4142135623731e+154", gc(xdtoa(_hypot(1e154, 1e154))));
EXPECT_STREQ("NAN", gc(xdtoa(hypot(0, NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_hypot(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoa(hypot(NAN, 0)))); EXPECT_STREQ("NAN", gc(xdtoa(_hypot(NAN, 0))));
EXPECT_STREQ("NAN", gc(xdtoa(hypot(NAN, NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_hypot(NAN, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypot(INFINITY, 0)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_hypot(INFINITY, 0))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypot(0, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_hypot(0, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypot(INFINITY, NAN)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_hypot(INFINITY, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypot(NAN, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_hypot(NAN, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoa(hypot(INFINITY, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_hypot(INFINITY, INFINITY))));
} }
TEST(hypotf, test) { TEST(hypotf, test) {
EXPECT_STREQ("0", gc(xdtoa(hypotf(0, 0)))); EXPECT_STREQ("0", gc(xdtoa(_hypotf(0, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypotf(3, 0)))); EXPECT_STREQ("3", gc(xdtoa(_hypotf(3, 0))));
EXPECT_STREQ("3", gc(xdtoa(hypotf(0, 3)))); EXPECT_STREQ("3", gc(xdtoa(_hypotf(0, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(3, 4)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(3, 4))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(4, 3)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(4, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(3, -4)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(-4, 3)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(-4, 3))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(-3, 4)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(-3, 4))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(4, -3)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(4, -3))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(-3, -4)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(-3, -4))));
EXPECT_STREQ("5", gc(xdtoa(hypotf(-4, -3)))); EXPECT_STREQ("5", gc(xdtoa(_hypotf(-4, -3))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1, 1)))); EXPECT_STREQ("1.41421", gc(xdtoaf(_hypotf(1, 1))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1, -1)))); EXPECT_STREQ("1.41421", gc(xdtoaf(_hypotf(1, -1))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(-1, 1)))); EXPECT_STREQ("1.41421", gc(xdtoaf(_hypotf(-1, 1))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(1.000001, 0.999999)))); EXPECT_STREQ("1.41421", gc(xdtoaf(_hypotf(1.000001, 0.999999))));
EXPECT_STREQ("1.41421", gc(xdtoaf(hypotf(0.999999, 1.000001)))); EXPECT_STREQ("1.41421", gc(xdtoaf(_hypotf(0.999999, 1.000001))));
EXPECT_STREQ("1.41421e+38", gc(xdtoaf(hypotf(1e38, 1e38)))); EXPECT_STREQ("1.41421e+38", gc(xdtoaf(_hypotf(1e38, 1e38))));
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(0, NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_hypotf(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(NAN, 0)))); EXPECT_STREQ("NAN", gc(xdtoaf(_hypotf(NAN, 0))));
EXPECT_STREQ("NAN", gc(xdtoaf(hypotf(NAN, NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_hypotf(NAN, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(hypotf(INFINITY, 0)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_hypotf(INFINITY, 0))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(hypotf(0, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_hypotf(0, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(hypotf(INFINITY, NAN)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_hypotf(INFINITY, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(hypotf(NAN, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_hypotf(NAN, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(hypotf(INFINITY, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_hypotf(INFINITY, INFINITY))));
} }
TEST(hypotll, test) { TEST(hypotll, test) {
EXPECT_STREQ("0", gc(xdtoal(hypotl(0, 0)))); EXPECT_STREQ("0", gc(xdtoal(_hypotl(0, 0))));
EXPECT_STREQ("3", gc(xdtoal(hypotl(3, 0)))); EXPECT_STREQ("3", gc(xdtoal(_hypotl(3, 0))));
EXPECT_STREQ("3", gc(xdtoal(hypotl(0, 3)))); EXPECT_STREQ("3", gc(xdtoal(_hypotl(0, 3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(3, 4)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(3, 4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(4, 3)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(4, 3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(3, -4)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(3, -4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-4, 3)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(-4, 3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-3, 4)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(-3, 4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(4, -3)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(4, -3))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-3, -4)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(-3, -4))));
EXPECT_STREQ("5", gc(xdtoal(hypotl(-4, -3)))); EXPECT_STREQ("5", gc(xdtoal(_hypotl(-4, -3))));
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(1, 1)))); EXPECT_STREQ("1.414213562373095", gc(xdtoal(_hypotl(1, 1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(1, -1)))); EXPECT_STREQ("1.414213562373095", gc(xdtoal(_hypotl(1, -1))));
EXPECT_STREQ("1.414213562373095", gc(xdtoal(hypotl(-1, 1)))); EXPECT_STREQ("1.414213562373095", gc(xdtoal(_hypotl(-1, 1))));
EXPECT_STREQ("1.414213626012708", gc(xdtoal(hypotl(1.0000001, .99999999)))); EXPECT_STREQ("1.414213626012708", gc(xdtoal(_hypotl(1.0000001, .99999999))));
EXPECT_STREQ("1.414213626012708", gc(xdtoal(hypotl(.99999999, 1.0000001)))); EXPECT_STREQ("1.414213626012708", gc(xdtoal(_hypotl(.99999999, 1.0000001))));
EXPECT_STREQ("1.414213562373095e+4931", gc(xdtoal(hypotl(1e4931L, 1e4931L)))); EXPECT_STREQ("1.414213562373095e+4931",
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(0, NAN)))); gc(xdtoal(_hypotl(1e4931L, 1e4931L))));
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(NAN, 0)))); EXPECT_STREQ("NAN", gc(xdtoal(_hypotl(0, NAN))));
EXPECT_STREQ("NAN", gc(xdtoal(hypotl(NAN, NAN)))); EXPECT_STREQ("NAN", gc(xdtoal(_hypotl(NAN, 0))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, 0)))); EXPECT_STREQ("NAN", gc(xdtoal(_hypotl(NAN, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(0, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_hypotl(INFINITY, 0))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, NAN)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_hypotl(0, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(NAN, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_hypotl(INFINITY, NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(hypotl(INFINITY, INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_hypotl(NAN, INFINITY))));
EXPECT_STREQ("INFINITY", gc(xdtoal(_hypotl(INFINITY, INFINITY))));
} }
/* /*
hypot (musl) l: 53𝑐 17𝑛𝑠 m: 85𝑐 27𝑛𝑠 _hypot (musl) l: 53𝑐 17𝑛𝑠 m: 85𝑐 27𝑛𝑠
hypot l: 39𝑐 13𝑛𝑠 m: 66𝑐 21𝑛𝑠 _hypot l: 39𝑐 13𝑛𝑠 m: 66𝑐 21𝑛𝑠
hypotf l: 25𝑐 8𝑛𝑠 m: 55𝑐 18𝑛𝑠 _hypotf l: 25𝑐 8𝑛𝑠 m: 55𝑐 18𝑛𝑠
hypotl l: 43𝑐 14𝑛𝑠 m: 74𝑐 24𝑛𝑠 _hypotl l: 43𝑐 14𝑛𝑠 m: 74𝑐 24𝑛𝑠
*/ */
BENCH(hypot, bench) { BENCH(_hypot, bench) {
volatile double a = 2; volatile double a = 2;
volatile double b = 3; volatile double b = 3;
EZBENCH2("hypotf", donothing, EXPROPRIATE(hypotf(a, b))); EZBENCH2("hypotf", donothing, EXPROPRIATE(_hypotf(a, b)));
EZBENCH2("hypot", donothing, EXPROPRIATE(hypot(a, b))); EZBENCH2("hypot", donothing, EXPROPRIATE(_hypot(a, b)));
EZBENCH2("hypotl", donothing, EXPROPRIATE(hypotl(a, b))); EZBENCH2("hypotl", donothing, EXPROPRIATE(_hypotl(a, b)));
} }

View file

@ -24,61 +24,69 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define roundl(x) roundl(VEIL("t", (long double)(x))) double _round(double) asm("round");
#define round(x) round(VEIL("x", (double)(x))) float _roundf(float) asm("roundf");
#define roundf(x) roundf(VEIL("x", (float)(x))) long double _roundl(long double) asm("roundl");
long _lround(double) asm("lround");
long _lroundf(float) asm("lroundf");
long _lroundl(long double) asm("lroundl");
long _lrint(double) asm("lrint");
long _lrintf(float) asm("lrintf");
long _lrintl(long double) asm("lrintl");
FIXTURE(intrin, disableHardwareExtensions) { FIXTURE(intrin, disableHardwareExtensions) {
memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids)); memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids));
} }
TEST(round, testCornerCases) { TEST(round, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(round(-0.0)))); EXPECT_STREQ("-0", gc(xdtoa(_round(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(round(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_round(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(round(-NAN)))); EXPECT_STREQ("-NAN", gc(xdtoa(_round(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(round(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_round(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(round(-INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(_round(-INFINITY))));
} }
TEST(roundl, testCornerCases) { TEST(roundl, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(roundl(-0.0)))); EXPECT_STREQ("-0", gc(xdtoa(_roundl(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(roundl(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_roundl(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(roundl(-NAN)))); EXPECT_STREQ("-NAN", gc(xdtoa(_roundl(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(roundl(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_roundl(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(roundl(-INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(_roundl(-INFINITY))));
} }
TEST(round, test) { TEST(round, test) {
EXPECT_STREQ("-3", gc(xdtoa(round(-2.5)))); EXPECT_STREQ("-3", gc(xdtoa(_round(-2.5))));
EXPECT_STREQ("-2", gc(xdtoa(round(-1.5)))); EXPECT_STREQ("-2", gc(xdtoa(_round(-1.5))));
EXPECT_STREQ("-1", gc(xdtoa(round(-.5)))); EXPECT_STREQ("-1", gc(xdtoa(_round(-.5))));
EXPECT_STREQ("-0", gc(xdtoa(round(-.4)))); EXPECT_STREQ("-0", gc(xdtoa(_round(-.4))));
EXPECT_STREQ("0", gc(xdtoa(round(.4)))); EXPECT_STREQ("0", gc(xdtoa(_round(.4))));
EXPECT_STREQ("1", gc(xdtoa(round(.5)))); EXPECT_STREQ("1", gc(xdtoa(_round(.5))));
EXPECT_STREQ("2", gc(xdtoa(round(1.5)))); EXPECT_STREQ("2", gc(xdtoa(_round(1.5))));
EXPECT_STREQ("3", gc(xdtoa(round(2.5)))); EXPECT_STREQ("3", gc(xdtoa(_round(2.5))));
} }
TEST(roundf, test) { TEST(roundf, test) {
EXPECT_STREQ("-3", gc(xdtoa(roundf(-2.5)))); EXPECT_STREQ("-3", gc(xdtoa(_roundf(-2.5))));
EXPECT_STREQ("-2", gc(xdtoa(roundf(-1.5)))); EXPECT_STREQ("-2", gc(xdtoa(_roundf(-1.5))));
EXPECT_STREQ("-1", gc(xdtoa(roundf(-.5)))); EXPECT_STREQ("-1", gc(xdtoa(_roundf(-.5))));
EXPECT_STREQ("-0", gc(xdtoa(roundf(-.4)))); EXPECT_STREQ("-0", gc(xdtoa(_roundf(-.4))));
EXPECT_STREQ("0", gc(xdtoa(roundf(.4)))); EXPECT_STREQ("0", gc(xdtoa(_roundf(.4))));
EXPECT_STREQ("1", gc(xdtoa(roundf(.5)))); EXPECT_STREQ("1", gc(xdtoa(_roundf(.5))));
EXPECT_STREQ("2", gc(xdtoa(roundf(1.5)))); EXPECT_STREQ("2", gc(xdtoa(_roundf(1.5))));
EXPECT_STREQ("3", gc(xdtoa(roundf(2.5)))); EXPECT_STREQ("3", gc(xdtoa(_roundf(2.5))));
} }
TEST(roundl, test) { TEST(roundl, test) {
EXPECT_STREQ("-3", gc(xdtoa(roundl(-2.5)))); EXPECT_STREQ("-3", gc(xdtoa(_roundl(-2.5))));
EXPECT_STREQ("-2", gc(xdtoa(roundl(-1.5)))); EXPECT_STREQ("-2", gc(xdtoa(_roundl(-1.5))));
EXPECT_STREQ("-1", gc(xdtoa(roundl(-.5)))); EXPECT_STREQ("-1", gc(xdtoa(_roundl(-.5))));
EXPECT_STREQ("-0", gc(xdtoa(roundl(-.4)))); EXPECT_STREQ("-0", gc(xdtoa(_roundl(-.4))));
EXPECT_STREQ("0", gc(xdtoa(roundl(.4)))); EXPECT_STREQ("0", gc(xdtoa(_roundl(.4))));
EXPECT_STREQ("1", gc(xdtoa(roundl(.5)))); EXPECT_STREQ("1", gc(xdtoa(_roundl(.5))));
EXPECT_STREQ("2", gc(xdtoa(roundl(1.5)))); EXPECT_STREQ("2", gc(xdtoa(_roundl(1.5))));
EXPECT_STREQ("3", gc(xdtoa(roundl(2.5)))); EXPECT_STREQ("3", gc(xdtoa(_roundl(2.5))));
} }
TEST(nearbyint, test) { TEST(nearbyint, test) {
@ -126,25 +134,25 @@ TEST(rint, test) {
} }
TEST(lrint, test) { TEST(lrint, test) {
EXPECT_EQ(-2, lrint(-2.5)); EXPECT_EQ(-2, _lrint(-2.5));
EXPECT_EQ(-2, lrint(-1.5)); EXPECT_EQ(-2, _lrint(-1.5));
EXPECT_EQ(-0, lrint(-.5)); EXPECT_EQ(-0, _lrint(-.5));
EXPECT_EQ(-0, lrint(-.4)); EXPECT_EQ(-0, _lrint(-.4));
EXPECT_EQ(0, lrint(.4)); EXPECT_EQ(0, _lrint(.4));
EXPECT_EQ(0, lrint(.5)); EXPECT_EQ(0, _lrint(.5));
EXPECT_EQ(2, lrint(1.5)); EXPECT_EQ(2, _lrint(1.5));
EXPECT_EQ(2, lrint(2.5)); EXPECT_EQ(2, _lrint(2.5));
} }
TEST(lrintf, test) { TEST(lrintf, test) {
EXPECT_EQ(-2, lrintf(-2.5)); EXPECT_EQ(-2, _lrintf(-2.5));
EXPECT_EQ(-2, lrintf(-1.5)); EXPECT_EQ(-2, _lrintf(-1.5));
EXPECT_EQ(-0, lrintf(-.5)); EXPECT_EQ(-0, _lrintf(-.5));
EXPECT_EQ(-0, lrintf(-.4)); EXPECT_EQ(-0, _lrintf(-.4));
EXPECT_EQ(0, lrintf(.4)); EXPECT_EQ(0, _lrintf(.4));
EXPECT_EQ(0, lrintf(.5)); EXPECT_EQ(0, _lrintf(.5));
EXPECT_EQ(2, lrintf(1.5)); EXPECT_EQ(2, _lrintf(1.5));
EXPECT_EQ(2, lrintf(2.5)); EXPECT_EQ(2, _lrintf(2.5));
} }
TEST(rintf, test) { TEST(rintf, test) {
@ -170,43 +178,43 @@ TEST(rintl, test) {
} }
TEST(roundf, testCornerCases) { TEST(roundf, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(roundf(-0.0)))); EXPECT_STREQ("-0", gc(xdtoa(_roundf(-0.0))));
EXPECT_STREQ("NAN", gc(xdtoa(roundf(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_roundf(NAN))));
EXPECT_STREQ("-NAN", gc(xdtoa(roundf(-NAN)))); EXPECT_STREQ("-NAN", gc(xdtoa(_roundf(-NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(roundf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_roundf(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(roundf(-INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(_roundf(-INFINITY))));
} }
TEST(lroundf, test) { TEST(lroundf, test) {
EXPECT_EQ(-3, lroundf(-2.5)); EXPECT_EQ(-3, _lroundf(-2.5));
EXPECT_EQ(-2, lroundf(-1.5)); EXPECT_EQ(-2, _lroundf(-1.5));
EXPECT_EQ(-1, lroundf(-.5)); EXPECT_EQ(-1, _lroundf(-.5));
EXPECT_EQ(0, lroundf(-.0)); EXPECT_EQ(0, _lroundf(-.0));
EXPECT_EQ(1, lroundf(.5)); EXPECT_EQ(1, _lroundf(.5));
EXPECT_EQ(2, lroundf(1.5)); EXPECT_EQ(2, _lroundf(1.5));
EXPECT_EQ(3, lroundf(2.5)); EXPECT_EQ(3, _lroundf(2.5));
} }
TEST(lround, test) { TEST(lround, test) {
EXPECT_EQ(-3, lround(-2.5)); EXPECT_EQ(-3, _lround(-2.5));
EXPECT_EQ(-2, lround(-1.5)); EXPECT_EQ(-2, _lround(-1.5));
EXPECT_EQ(-1, lround(-.5)); EXPECT_EQ(-1, _lround(-.5));
EXPECT_EQ(-0, lround(-.4)); EXPECT_EQ(-0, _lround(-.4));
EXPECT_EQ(0, lround(.4)); EXPECT_EQ(0, _lround(.4));
EXPECT_EQ(1, lround(.5)); EXPECT_EQ(1, _lround(.5));
EXPECT_EQ(2, lround(1.5)); EXPECT_EQ(2, _lround(1.5));
EXPECT_EQ(3, lround(2.5)); EXPECT_EQ(3, _lround(2.5));
} }
TEST(lroundl, test) { TEST(lroundl, test) {
EXPECT_EQ(-3, lroundl(-2.5)); EXPECT_EQ(-3, _lroundl(-2.5));
EXPECT_EQ(-2, lroundl(-1.5)); EXPECT_EQ(-2, _lroundl(-1.5));
EXPECT_EQ(-1, lroundl(-.5)); EXPECT_EQ(-1, _lroundl(-.5));
EXPECT_EQ(-0, lroundl(-.4)); EXPECT_EQ(-0, _lroundl(-.4));
EXPECT_EQ(0, lroundl(.4)); EXPECT_EQ(0, _lroundl(.4));
EXPECT_EQ(1, lroundl(.5)); EXPECT_EQ(1, _lroundl(.5));
EXPECT_EQ(2, lroundl(1.5)); EXPECT_EQ(2, _lroundl(1.5));
EXPECT_EQ(3, lroundl(2.5)); EXPECT_EQ(3, _lroundl(2.5));
} }
BENCH(round, bench) { BENCH(round, bench) {
@ -214,16 +222,10 @@ BENCH(round, bench) {
EZBENCH2("float+.5f", donothing, EXPROPRIATE(VEIL("x", (float)(-3.5)) + .5)); EZBENCH2("float+.5f", donothing, EXPROPRIATE(VEIL("x", (float)(-3.5)) + .5));
EZBENCH2("ldbl+.5l", donothing, EZBENCH2("ldbl+.5l", donothing,
EXPROPRIATE(VEIL("t", (long double)(-3.5)) + .5)); EXPROPRIATE(VEIL("t", (long double)(-3.5)) + .5));
double _round(double) asm("round"); EZBENCH2("round", donothing, _round(.7)); /* ~4ns */
float _roundf(float) asm("roundf"); EZBENCH2("roundf", donothing, _roundf(.7)); /* ~3ns */
long double _roundl(long double) asm("roundl"); EZBENCH2("roundl", donothing, _roundl(.7)); /* ~8ns */
EZBENCH2("-round", donothing, _round(.7)); /* ~4ns */ EZBENCH2("lrint", donothing, _lrint(.7)); /* ~1ns */
EZBENCH2("-roundf", donothing, _roundf(.7)); /* ~3ns */ EZBENCH2("lrintf", donothing, _lrintf(.7)); /* ~1ns */
EZBENCH2("-roundl", donothing, _roundl(.7)); /* ~8ns */ EZBENCH2("lrintl", donothing, _lrintl(.7)); /* ~78ns */
double _lrint(double) asm("lrint");
float _lrintf(float) asm("lrintf");
long double _lrintl(long double) asm("lrintl");
EZBENCH2("-lrint", donothing, _lrint(.7)); /* ~1ns */
EZBENCH2("-lrintf", donothing, _lrintf(.7)); /* ~1ns */
EZBENCH2("-lrintl", donothing, _lrintl(.7)); /* ~78ns */
} }

View file

@ -23,61 +23,58 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "libc/x/xasprintf.h" #include "libc/x/xasprintf.h"
#define sinl(x) sinl(VEIL("t", (long double)(x))) double _sin(double) asm("sin");
#define sin(x) sin(VEIL("x", (double)(x))) float _sinf(float) asm("sinf");
#define sinf(x) sinf(VEIL("x", (float)(x))) long double _sinl(long double) asm("sinl");
TEST(sinl, test) { TEST(sinl, test) {
EXPECT_STREQ("NAN", _gc(xdtoal(sinl(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoal(_sinl(NAN))));
EXPECT_STREQ("-NAN", _gc(xdtoal(sinl(+INFINITY)))); EXPECT_STREQ("-NAN", _gc(xdtoal(_sinl(+INFINITY))));
EXPECT_STREQ("-NAN", _gc(xdtoal(sinl(-INFINITY)))); EXPECT_STREQ("-NAN", _gc(xdtoal(_sinl(-INFINITY))));
EXPECT_STREQ(".479425538604203", _gc(xdtoal(sinl(.5)))); EXPECT_STREQ(".479425538604203", _gc(xdtoal(_sinl(.5))));
EXPECT_STREQ("-.479425538604203", _gc(xdtoal(sinl(-.5)))); EXPECT_STREQ("-.479425538604203", _gc(xdtoal(_sinl(-.5))));
EXPECT_STREQ(".8414709794048734", _gc(xdtoal(sinl(.99999999)))); EXPECT_STREQ(".8414709794048734", _gc(xdtoal(_sinl(.99999999))));
/* EXPECT_STREQ("-.998836772397", _gc(xdtoal(sinl(555555555555)))); */ /* EXPECT_STREQ("-.998836772397", _gc(xdtoal(_sinl(555555555555)))); */
/* EXPECT_STREQ("1", _gc(xdtoal(sinl(5.319372648326541e+255L)))); */ /* EXPECT_STREQ("1", _gc(xdtoal(_sinl(5.319372648326541e+255L)))); */
} }
TEST(sin, test) { TEST(sin, test) {
EXPECT_STREQ("0", _gc(xasprintf("%.15g", sin(0.)))); EXPECT_STREQ("0", _gc(xasprintf("%.15g", _sin(0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", sin(-0.)))); EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _sin(-0.))));
EXPECT_STREQ("0.0998334166468282", _gc(xasprintf("%.15g", sin(.1)))); EXPECT_STREQ("0.0998334166468282", _gc(xasprintf("%.15g", _sin(.1))));
EXPECT_STREQ("-0.0998334166468282", _gc(xasprintf("%.15g", sin(-.1)))); EXPECT_STREQ("-0.0998334166468282", _gc(xasprintf("%.15g", _sin(-.1))));
EXPECT_STREQ("0.479425538604203", _gc(xasprintf("%.15g", sin(.5)))); EXPECT_STREQ("0.479425538604203", _gc(xasprintf("%.15g", _sin(.5))));
EXPECT_STREQ("-0.479425538604203", _gc(xasprintf("%.15g", sin(-.5)))); EXPECT_STREQ("-0.479425538604203", _gc(xasprintf("%.15g", _sin(-.5))));
EXPECT_STREQ("0.841470984807897", _gc(xasprintf("%.15g", sin(1.)))); EXPECT_STREQ("0.841470984807897", _gc(xasprintf("%.15g", _sin(1.))));
EXPECT_STREQ("-0.841470984807897", _gc(xasprintf("%.15g", sin(-1.)))); EXPECT_STREQ("-0.841470984807897", _gc(xasprintf("%.15g", _sin(-1.))));
EXPECT_STREQ("0.997494986604054", _gc(xasprintf("%.15g", sin(1.5)))); EXPECT_STREQ("0.997494986604054", _gc(xasprintf("%.15g", _sin(1.5))));
EXPECT_STREQ("-0.997494986604054", _gc(xasprintf("%.15g", sin(-1.5)))); EXPECT_STREQ("-0.997494986604054", _gc(xasprintf("%.15g", _sin(-1.5))));
EXPECT_STREQ("0.909297426825682", _gc(xasprintf("%.15g", sin(2.)))); EXPECT_STREQ("0.909297426825682", _gc(xasprintf("%.15g", _sin(2.))));
EXPECT_TRUE(isnan(sin(NAN))); EXPECT_TRUE(isnan(_sin(NAN)));
EXPECT_TRUE(isnan(sin(-NAN))); EXPECT_TRUE(isnan(_sin(-NAN)));
EXPECT_TRUE(isnan(sin(INFINITY))); EXPECT_TRUE(isnan(_sin(INFINITY)));
EXPECT_TRUE(isnan(sin(-INFINITY))); EXPECT_TRUE(isnan(_sin(-INFINITY)));
EXPECT_STREQ("2.2250738585072e-308", EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", sin(__DBL_MIN__)))); _gc(xasprintf("%.15g", _sin(__DBL_MIN__))));
EXPECT_STREQ("0.00496195478918406", EXPECT_STREQ("0.00496195478918406",
_gc(xasprintf("%.15g", sin(__DBL_MAX__)))); _gc(xasprintf("%.15g", _sin(__DBL_MAX__))));
EXPECT_STREQ("-0.841470984807897", EXPECT_STREQ("-0.841470984807897",
_gc(xasprintf("%.15g", sin(-1.0000000000000002)))); _gc(xasprintf("%.15g", _sin(-1.0000000000000002))));
EXPECT_STREQ("-2.1073424255447e-08", EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", sin(-2.1073424255447e-08)))); _gc(xasprintf("%.15g", _sin(-2.1073424255447e-08))));
} }
TEST(sinf, test) { TEST(sinf, test) {
EXPECT_TRUE(isnan(sinf(NAN))); EXPECT_TRUE(isnan(_sinf(NAN)));
EXPECT_TRUE(isnan(sinf(+INFINITY))); EXPECT_TRUE(isnan(_sinf(+INFINITY)));
EXPECT_TRUE(isnan(sinf(-INFINITY))); EXPECT_TRUE(isnan(_sinf(-INFINITY)));
EXPECT_STREQ("NAN", _gc(xdtoaf(sinf(NAN)))); EXPECT_STREQ("NAN", _gc(xdtoaf(_sinf(NAN))));
EXPECT_STARTSWITH(".479426", _gc(xdtoaf(sinf(.5f)))); EXPECT_STARTSWITH(".479426", _gc(xdtoaf(_sinf(.5f))));
EXPECT_STARTSWITH("-.479426", _gc(xdtoaf(sinf(-.5f)))); EXPECT_STARTSWITH("-.479426", _gc(xdtoaf(_sinf(-.5f))));
EXPECT_STARTSWITH(".873283", _gc(xdtoaf(sinf(555)))); EXPECT_STARTSWITH(".873283", _gc(xdtoaf(_sinf(555))));
} }
BENCH(sin, bench) { BENCH(_sin, bench) {
double _sin(double) asm("sin");
float _sinf(float) asm("sinf");
long double _sinl(long double) asm("sinl");
EZBENCH2("sin", donothing, _sin(.7)); /* ~5ns */ EZBENCH2("sin", donothing, _sin(.7)); /* ~5ns */
EZBENCH2("sinf", donothing, _sinf(.7)); /* ~5ns */ EZBENCH2("sinf", donothing, _sinf(.7)); /* ~5ns */
EZBENCH2("sinl", donothing, _sinl(.7)); /* ~28ns */ EZBENCH2("sinl", donothing, _sinl(.7)); /* ~28ns */

View file

@ -21,42 +21,42 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define sinhl(x) sinhl(VEIL("t", (long double)(x))) double _sinh(double) asm("sinh");
#define sinh(x) sinh(VEIL("x", (double)(x))) float _sinhf(float) asm("sinhf");
#define sinhf(x) sinhf(VEIL("x", (float)(x))) long double _sinhl(long double) asm("sinhl");
TEST(sinh, test) { TEST(sinh, test) {
EXPECT_STREQ(".521095305493747", gc(xdtoa(sinh(+.5)))); EXPECT_STREQ(".521095305493747", gc(xdtoa(_sinh(+.5))));
EXPECT_STREQ("-.521095305493747", gc(xdtoa(sinh(-.5)))); EXPECT_STREQ("-.521095305493747", gc(xdtoa(_sinh(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoa(sinh(30000)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_sinh(30000))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(sinh(-30000)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(_sinh(-30000))));
EXPECT_STREQ("0", gc(xdtoa(sinh(0)))); EXPECT_STREQ("0", gc(xdtoa(_sinh(0))));
EXPECT_STREQ("-0", gc(xdtoa(sinh(-0.)))); EXPECT_STREQ("-0", gc(xdtoa(_sinh(-0.))));
EXPECT_STREQ("NAN", gc(xdtoa(sinh(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_sinh(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoa(sinh(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_sinh(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoa(sinh(-INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoa(_sinh(-INFINITY))));
} }
TEST(sinhl, test) { TEST(sinhl, test) {
EXPECT_STREQ(".5210953054937474", gc(xdtoal(sinhl(+.5)))); EXPECT_STREQ(".5210953054937474", gc(xdtoal(_sinhl(+.5))));
EXPECT_STREQ("-.5210953054937474", gc(xdtoal(sinhl(-.5)))); EXPECT_STREQ("-.5210953054937474", gc(xdtoal(_sinhl(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoal(sinhl(30000)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_sinhl(30000))));
EXPECT_STREQ("-INFINITY", gc(xdtoal(sinhl(-30000)))); EXPECT_STREQ("-INFINITY", gc(xdtoal(_sinhl(-30000))));
EXPECT_STREQ("0", gc(xdtoal(sinhl(0)))); EXPECT_STREQ("0", gc(xdtoal(_sinhl(0))));
EXPECT_STREQ("-0", gc(xdtoal(sinhl(-0.)))); EXPECT_STREQ("-0", gc(xdtoal(_sinhl(-0.))));
EXPECT_STREQ("NAN", gc(xdtoal(sinhl(NAN)))); EXPECT_STREQ("NAN", gc(xdtoal(_sinhl(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoal(sinhl(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_sinhl(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoal(sinhl(-INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoal(_sinhl(-INFINITY))));
} }
TEST(sinhf, test) { TEST(sinhf, test) {
EXPECT_STREQ(".521095", gc(xdtoaf(sinhf(+.5)))); EXPECT_STREQ(".521095", gc(xdtoaf(_sinhf(+.5))));
EXPECT_STREQ("-.521095", gc(xdtoaf(sinhf(-.5)))); EXPECT_STREQ("-.521095", gc(xdtoaf(_sinhf(-.5))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(sinhf(30000)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_sinhf(30000))));
EXPECT_STREQ("-INFINITY", gc(xdtoaf(sinhf(-30000)))); EXPECT_STREQ("-INFINITY", gc(xdtoaf(_sinhf(-30000))));
EXPECT_STREQ("0", gc(xdtoaf(sinhf(0)))); EXPECT_STREQ("0", gc(xdtoaf(_sinhf(0))));
EXPECT_STREQ("-0", gc(xdtoaf(sinhf(-0.)))); EXPECT_STREQ("-0", gc(xdtoaf(_sinhf(-0.))));
EXPECT_STREQ("NAN", gc(xdtoaf(sinhf(NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_sinhf(NAN))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(sinhf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_sinhf(INFINITY))));
EXPECT_STREQ("-INFINITY", gc(xdtoaf(sinhf(-INFINITY)))); EXPECT_STREQ("-INFINITY", gc(xdtoaf(_sinhf(-INFINITY))));
} }

View file

@ -22,39 +22,36 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#include "libc/x/x.h" #include "libc/x/x.h"
#define sqrtl(x) sqrtl(VEIL("t", (long double)(x))) double _sqrt(double) asm("sqrt");
#define sqrt(x) sqrt(VEIL("x", (double)(x))) float _sqrtf(float) asm("sqrtf");
#define sqrtf(x) sqrtf(VEIL("x", (float)(x))) long double _sqrtl(long double) asm("sqrtl");
TEST(sqrtl, test) { TEST(sqrtl, test) {
EXPECT_STREQ("7", gc(xdtoal(sqrtl(7 * 7)))); EXPECT_STREQ("7", gc(xdtoal(_sqrtl(7 * 7))));
EXPECT_STREQ("NAN", gc(xdtoal(sqrtl(NAN)))); EXPECT_STREQ("NAN", gc(xdtoal(_sqrtl(NAN))));
EXPECT_STREQ("0", gc(xdtoal(sqrtl(0)))); EXPECT_STREQ("0", gc(xdtoal(_sqrtl(0))));
EXPECT_STREQ("INFINITY", gc(xdtoal(sqrtl(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoal(_sqrtl(INFINITY))));
EXPECT_STREQ("-NAN", gc(xdtoal(sqrtl(-1)))); EXPECT_STREQ("-NAN", gc(xdtoal(_sqrtl(-1))));
} }
TEST(sqrt, test) { TEST(sqrt, test) {
EXPECT_STREQ("7", gc(xdtoa(sqrt(7 * 7)))); EXPECT_STREQ("7", gc(xdtoa(_sqrt(7 * 7))));
EXPECT_STREQ("NAN", gc(xdtoa(sqrt(NAN)))); EXPECT_STREQ("NAN", gc(xdtoa(_sqrt(NAN))));
EXPECT_STREQ("0", gc(xdtoa(sqrt(0)))); EXPECT_STREQ("0", gc(xdtoa(_sqrt(0))));
EXPECT_STREQ("INFINITY", gc(xdtoa(sqrt(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoa(_sqrt(INFINITY))));
EXPECT_STREQ("-NAN", gc(xdtoa(sqrt(-1)))); EXPECT_STREQ("-NAN", gc(xdtoa(_sqrt(-1))));
} }
TEST(sqrtf, test) { TEST(sqrtf, test) {
EXPECT_STREQ("7", gc(xdtoaf(sqrtf(7 * 7)))); EXPECT_STREQ("7", gc(xdtoaf(_sqrtf(7 * 7))));
EXPECT_STREQ("NAN", gc(xdtoaf(sqrtf(NAN)))); EXPECT_STREQ("NAN", gc(xdtoaf(_sqrtf(NAN))));
EXPECT_STREQ("0", gc(xdtoaf(sqrtf(0)))); EXPECT_STREQ("0", gc(xdtoaf(_sqrtf(0))));
EXPECT_STREQ("INFINITY", gc(xdtoaf(sqrtf(INFINITY)))); EXPECT_STREQ("INFINITY", gc(xdtoaf(_sqrtf(INFINITY))));
EXPECT_STREQ("-NAN", gc(xdtoaf(sqrtf(-1)))); EXPECT_STREQ("-NAN", gc(xdtoaf(_sqrtf(-1))));
} }
BENCH(sqrt, bench) { BENCH(_sqrt, bench) {
double _sqrt(double) asm("sqrt"); EZBENCH2("sqrt", donothing, _sqrt(.7)); /* ~2ns */
float _sqrtf(float) asm("sqrtf"); EZBENCH2("sqrtf", donothing, _sqrtf(.7)); /* ~1ns */
long double _sqrtl(long double) asm("sqrtl"); EZBENCH2("sqrtl", donothing, _sqrtl(.7)); /* ~9ns */
EZBENCH2("sqrt", donothing, _sqrt(.7)); /* ~5ns */
EZBENCH2("sqrtf", donothing, _sqrtf(.7)); /* ~5ns */
EZBENCH2("sqrtl", donothing, _sqrtl(.7)); /* ~28ns */
} }

View file

@ -22,51 +22,51 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "libc/x/xasprintf.h" #include "libc/x/xasprintf.h"
#define tanhl(x) tanhl(VEIL("t", (long double)(x))) double _tanh(double) asm("tanh");
#define tanh(x) tanh(VEIL("x", (double)(x))) float _tanhf(float) asm("tanhf");
#define tanhf(x) tanhf(VEIL("x", (float)(x))) long double _tanhl(long double) asm("tanhl");
TEST(tanhl, test) { TEST(_tanhl, test) {
EXPECT_STREQ(".09966799462495582", _gc(xdtoal(tanhl(+.1)))); EXPECT_STREQ(".09966799462495582", _gc(xdtoal(_tanhl(+.1))));
EXPECT_STREQ("-.09966799462495582", _gc(xdtoal(tanhl(-.1)))); EXPECT_STREQ("-.09966799462495582", _gc(xdtoal(_tanhl(-.1))));
EXPECT_STREQ("0", _gc(xdtoal(tanhl(0)))); EXPECT_STREQ("0", _gc(xdtoal(_tanhl(0))));
EXPECT_STREQ("-0", _gc(xdtoal(tanhl(-0.)))); EXPECT_STREQ("-0", _gc(xdtoal(_tanhl(-0.))));
EXPECT_TRUE(isnan(tanhl(NAN))); EXPECT_TRUE(isnan(_tanhl(NAN)));
EXPECT_STREQ("1", _gc(xdtoal(tanhl(INFINITY)))); EXPECT_STREQ("1", _gc(xdtoal(_tanhl(INFINITY))));
EXPECT_STREQ("-1", _gc(xdtoal(tanhl(-INFINITY)))); EXPECT_STREQ("-1", _gc(xdtoal(_tanhl(-INFINITY))));
} }
TEST(tanh, test) { TEST(_tanh, test) {
EXPECT_STREQ("0", _gc(xasprintf("%.15g", tanh(0.)))); EXPECT_STREQ("0", _gc(xasprintf("%.15g", _tanh(0.))));
EXPECT_STREQ("-0", _gc(xasprintf("%.15g", tanh(-0.)))); EXPECT_STREQ("-0", _gc(xasprintf("%.15g", _tanh(-0.))));
EXPECT_STREQ("0.0996679946249558", _gc(xasprintf("%.15g", tanh(.1)))); EXPECT_STREQ("0.0996679946249558", _gc(xasprintf("%.15g", _tanh(.1))));
EXPECT_STREQ("-0.0996679946249558", _gc(xasprintf("%.15g", tanh(-.1)))); EXPECT_STREQ("-0.0996679946249558", _gc(xasprintf("%.15g", _tanh(-.1))));
EXPECT_STREQ("0.46211715726001", _gc(xasprintf("%.15g", tanh(.5)))); EXPECT_STREQ("0.46211715726001", _gc(xasprintf("%.15g", _tanh(.5))));
EXPECT_STREQ("-0.46211715726001", _gc(xasprintf("%.15g", tanh(-.5)))); EXPECT_STREQ("-0.46211715726001", _gc(xasprintf("%.15g", _tanh(-.5))));
EXPECT_STREQ("0.761594155955765", _gc(xasprintf("%.15g", tanh(1.)))); EXPECT_STREQ("0.761594155955765", _gc(xasprintf("%.15g", _tanh(1.))));
EXPECT_STREQ("-0.761594155955765", _gc(xasprintf("%.15g", tanh(-1.)))); EXPECT_STREQ("-0.761594155955765", _gc(xasprintf("%.15g", _tanh(-1.))));
EXPECT_STREQ("0.905148253644866", _gc(xasprintf("%.15g", tanh(1.5)))); EXPECT_STREQ("0.905148253644866", _gc(xasprintf("%.15g", _tanh(1.5))));
EXPECT_STREQ("-0.905148253644866", _gc(xasprintf("%.15g", tanh(-1.5)))); EXPECT_STREQ("-0.905148253644866", _gc(xasprintf("%.15g", _tanh(-1.5))));
EXPECT_STREQ("0.964027580075817", _gc(xasprintf("%.15g", tanh(2.)))); EXPECT_STREQ("0.964027580075817", _gc(xasprintf("%.15g", _tanh(2.))));
EXPECT_TRUE(isnan(tanh(NAN))); EXPECT_TRUE(isnan(_tanh(NAN)));
EXPECT_TRUE(isnan(tanh(-NAN))); EXPECT_TRUE(isnan(_tanh(-NAN)));
EXPECT_STREQ("1", _gc(xasprintf("%.15g", tanh(INFINITY)))); EXPECT_STREQ("1", _gc(xasprintf("%.15g", _tanh(INFINITY))));
EXPECT_STREQ("-1", _gc(xasprintf("%.15g", tanh(-INFINITY)))); EXPECT_STREQ("-1", _gc(xasprintf("%.15g", _tanh(-INFINITY))));
EXPECT_STREQ("2.2250738585072e-308", EXPECT_STREQ("2.2250738585072e-308",
_gc(xasprintf("%.15g", tanh(__DBL_MIN__)))); _gc(xasprintf("%.15g", _tanh(__DBL_MIN__))));
EXPECT_STREQ("1", _gc(xasprintf("%.15g", tanh(__DBL_MAX__)))); EXPECT_STREQ("1", _gc(xasprintf("%.15g", _tanh(__DBL_MAX__))));
EXPECT_STREQ("-0.761594155955765", EXPECT_STREQ("-0.761594155955765",
_gc(xasprintf("%.15g", tanh(-1.0000000000000002)))); _gc(xasprintf("%.15g", _tanh(-1.0000000000000002))));
EXPECT_STREQ("-2.1073424255447e-08", EXPECT_STREQ("-2.1073424255447e-08",
_gc(xasprintf("%.15g", tanh(-2.1073424255447e-08)))); _gc(xasprintf("%.15g", _tanh(-2.1073424255447e-08))));
} }
TEST(tanhf, test) { TEST(_tanhf, test) {
EXPECT_STREQ(".099668", _gc(xdtoaf(tanhf(+.1)))); EXPECT_STREQ(".099668", _gc(xdtoaf(_tanhf(+.1))));
EXPECT_STREQ("-.099668", _gc(xdtoaf(tanhf(-.1)))); EXPECT_STREQ("-.099668", _gc(xdtoaf(_tanhf(-.1))));
EXPECT_STREQ("0", _gc(xdtoaf(tanhf(0)))); EXPECT_STREQ("0", _gc(xdtoaf(_tanhf(0))));
EXPECT_STREQ("-0", _gc(xdtoaf(tanhf(-0.)))); EXPECT_STREQ("-0", _gc(xdtoaf(_tanhf(-0.))));
EXPECT_TRUE(isnan(tanhf(NAN))); EXPECT_TRUE(isnan(_tanhf(NAN)));
EXPECT_STREQ("1", _gc(xdtoaf(tanhf(INFINITY)))); EXPECT_STREQ("1", _gc(xdtoaf(_tanhf(INFINITY))));
EXPECT_STREQ("-1", _gc(xdtoaf(tanhf(-INFINITY)))); EXPECT_STREQ("-1", _gc(xdtoaf(_tanhf(-INFINITY))));
} }

View file

@ -40,8 +40,6 @@ getopt (BSD-3)\\n\
Copyright 1987, 1993, 1994 The Regents of the University of California\""); Copyright 1987, 1993, 1994 The Regents of the University of California\"");
asm(".include \"libc/disclaimer.inc\""); asm(".include \"libc/disclaimer.inc\"");
STATIC_YOINK("_init_getopt");
#define BADCH (int)'?' #define BADCH (int)'?'
#define BADARG (int)':' #define BADARG (int)':'
@ -75,8 +73,8 @@ int optreset;
*/ */
char *optarg; char *optarg;
_Hide char *getopt_place; char *getopt_place;
_Hide char kGetoptEmsg[1]; static char kGetoptEmsg[1];
static void getopt_print_badch(const char *s) { static void getopt_print_badch(const char *s) {
char b1[512]; char b1[512];
@ -117,6 +115,13 @@ static void getopt_print_badch(const char *s) {
*/ */
int getopt(int nargc, char *const nargv[], const char *ostr) { int getopt(int nargc, char *const nargv[], const char *ostr) {
char *oli; /* option letter list index */ char *oli; /* option letter list index */
static bool once;
if (!once) {
opterr = 1;
optind = 1;
getopt_place = kGetoptEmsg;
once = true;
}
/* /*
* Some programs like cvs expect optind = 0 to trigger * Some programs like cvs expect optind = 0 to trigger
* a reset of getopt. * a reset of getopt.

View file

@ -8,16 +8,8 @@ THIRD_PARTY_GETOPT = $(THIRD_PARTY_GETOPT_A_DEPS) $(THIRD_PARTY_GETOPT_A)
THIRD_PARTY_GETOPT_A = o/$(MODE)/third_party/getopt/getopt.a THIRD_PARTY_GETOPT_A = o/$(MODE)/third_party/getopt/getopt.a
THIRD_PARTY_GETOPT_A_FILES := $(wildcard third_party/getopt/*) THIRD_PARTY_GETOPT_A_FILES := $(wildcard third_party/getopt/*)
THIRD_PARTY_GETOPT_A_HDRS = $(filter %.h,$(THIRD_PARTY_GETOPT_A_FILES)) THIRD_PARTY_GETOPT_A_HDRS = $(filter %.h,$(THIRD_PARTY_GETOPT_A_FILES))
THIRD_PARTY_GETOPT_A_SRCS_S = $(filter %.S,$(THIRD_PARTY_GETOPT_A_FILES)) THIRD_PARTY_GETOPT_A_SRCS = $(filter %.c,$(THIRD_PARTY_GETOPT_A_FILES))
THIRD_PARTY_GETOPT_A_SRCS_C = $(filter %.c,$(THIRD_PARTY_GETOPT_A_FILES)) THIRD_PARTY_GETOPT_A_OBJS = $(THIRD_PARTY_GETOPT_A_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_GETOPT_A_SRCS = \
$(THIRD_PARTY_GETOPT_A_SRCS_S) \
$(THIRD_PARTY_GETOPT_A_SRCS_C)
THIRD_PARTY_GETOPT_A_OBJS = \
$(THIRD_PARTY_GETOPT_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(THIRD_PARTY_GETOPT_A_SRCS_C:%.c=o/$(MODE)/%.o)
THIRD_PARTY_GETOPT_A_CHECKS = \ THIRD_PARTY_GETOPT_A_CHECKS = \
$(THIRD_PARTY_GETOPT_A).pkg \ $(THIRD_PARTY_GETOPT_A).pkg \

View file

@ -8,16 +8,8 @@ THIRD_PARTY_ZLIB = $(THIRD_PARTY_ZLIB_A_DEPS) $(THIRD_PARTY_ZLIB_A)
THIRD_PARTY_ZLIB_A = o/$(MODE)/third_party/zlib/zlib.a THIRD_PARTY_ZLIB_A = o/$(MODE)/third_party/zlib/zlib.a
THIRD_PARTY_ZLIB_A_FILES := $(wildcard third_party/zlib/*) THIRD_PARTY_ZLIB_A_FILES := $(wildcard third_party/zlib/*)
THIRD_PARTY_ZLIB_A_HDRS = $(filter %.h,$(THIRD_PARTY_ZLIB_A_FILES)) THIRD_PARTY_ZLIB_A_HDRS = $(filter %.h,$(THIRD_PARTY_ZLIB_A_FILES))
THIRD_PARTY_ZLIB_A_SRCS_S = $(filter %.S,$(THIRD_PARTY_ZLIB_A_FILES)) THIRD_PARTY_ZLIB_A_SRCS = $(filter %.c,$(THIRD_PARTY_ZLIB_A_FILES))
THIRD_PARTY_ZLIB_A_SRCS_C = $(filter %.c,$(THIRD_PARTY_ZLIB_A_FILES)) THIRD_PARTY_ZLIB_A_OBJS = $(THIRD_PARTY_ZLIB_A_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_ZLIB_A_SRCS = \
$(THIRD_PARTY_ZLIB_A_SRCS_S) \
$(THIRD_PARTY_ZLIB_A_SRCS_C)
THIRD_PARTY_ZLIB_A_OBJS = \
$(THIRD_PARTY_ZLIB_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(THIRD_PARTY_ZLIB_A_SRCS_C:%.c=o/$(MODE)/%.o)
THIRD_PARTY_ZLIB_A_CHECKS = \ THIRD_PARTY_ZLIB_A_CHECKS = \
$(THIRD_PARTY_ZLIB_A).pkg \ $(THIRD_PARTY_ZLIB_A).pkg \