mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Make further progress on non-x86 support
This commit is contained in:
parent
aef9a69a60
commit
036b9a0002
155 changed files with 2307 additions and 653 deletions
|
@ -1,40 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2022 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/fmt/fmt.h"
|
||||
#include "libc/fmt/nf32.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(EncodeNf32, test) {
|
||||
char b[21];
|
||||
EncodeNf32(b, 31337);
|
||||
ASSERT_STREQ("-,--%", b);
|
||||
}
|
||||
|
||||
TEST(EncodeNf32, roundTrip) {
|
||||
int i;
|
||||
char b[21];
|
||||
uint32_t x, y;
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
x = lemur64();
|
||||
EncodeNf32(b, x);
|
||||
y = DecodeNf32(b, 0);
|
||||
ASSERT_EQ(x, y);
|
||||
}
|
||||
}
|
|
@ -134,42 +134,42 @@ BENCH(strlen, bench) {
|
|||
memset(b, -1, sizeof(b) - 1);
|
||||
memset(c, -1, sizeof(c) - 1);
|
||||
memset(d, -1, sizeof(d) - 1);
|
||||
EZBENCH2("strlen_sse 1", donothing, strlen_(""));
|
||||
EZBENCH2("strlen_swar 1", donothing, strlen_pure_(""));
|
||||
EZBENCH2("strlen_sse 2", donothing, strlen_("1"));
|
||||
EZBENCH2("strlen_swar 2", donothing, strlen_pure_("1"));
|
||||
EZBENCH2("strlen_sse 3", donothing, strlen_("11"));
|
||||
EZBENCH2("strlen_swar 3", donothing, strlen_pure_("11"));
|
||||
EZBENCH2("strlen_sse 4", donothing, strlen_("113"));
|
||||
EZBENCH2("strlen_swar 4", donothing, strlen_pure_("113"));
|
||||
EZBENCH2("strlen_sse 7", donothing, strlen_("123456"));
|
||||
EZBENCH2("strlen_swar 7", donothing, strlen_pure_("123456"));
|
||||
EZBENCH2("strlen_sse 8", donothing, strlen_("1234567"));
|
||||
EZBENCH2("strlen_swar 8", donothing, strlen_pure_("1234567"));
|
||||
EZBENCH2("strlen_sse 9", donothing, strlen_("12345678"));
|
||||
EZBENCH2("strlen_swar 9", donothing, strlen_pure_("12345678"));
|
||||
EZBENCH2("strlen_sse 11", donothing, strlen_("12345678aa"));
|
||||
EZBENCH2("strlen_swar 11", donothing, strlen_pure_("12345678aa"));
|
||||
EZBENCH2("strlen_sse 13", donothing, strlen_("12345678aabb"));
|
||||
EZBENCH2("strlen_swar 13", donothing, strlen_pure_("12345678aabb"));
|
||||
EZBENCH2("strlen_sse 16", donothing, strlen_("123456781234567"));
|
||||
EZBENCH2("strlen_swar 16", donothing, strlen_pure_("123456781234567"));
|
||||
EZBENCH2("strlen_sse 17", donothing, strlen_("123456781234567e"));
|
||||
EZBENCH2("strlen_swar 17", donothing, strlen_pure_("123456781234567e"));
|
||||
EZBENCH2("strlen_sse 34", donothing,
|
||||
EZBENCH2("strlen 1", donothing, strlen_(""));
|
||||
EZBENCH2("strlen_pure 1", donothing, strlen_pure_(""));
|
||||
EZBENCH2("strlen 2", donothing, strlen_("1"));
|
||||
EZBENCH2("strlen_pure 2", donothing, strlen_pure_("1"));
|
||||
EZBENCH2("strlen 3", donothing, strlen_("11"));
|
||||
EZBENCH2("strlen_pure 3", donothing, strlen_pure_("11"));
|
||||
EZBENCH2("strlen 4", donothing, strlen_("113"));
|
||||
EZBENCH2("strlen_pure 4", donothing, strlen_pure_("113"));
|
||||
EZBENCH2("strlen 7", donothing, strlen_("123456"));
|
||||
EZBENCH2("strlen_pure 7", donothing, strlen_pure_("123456"));
|
||||
EZBENCH2("strlen 8", donothing, strlen_("1234567"));
|
||||
EZBENCH2("strlen_pure 8", donothing, strlen_pure_("1234567"));
|
||||
EZBENCH2("strlen 9", donothing, strlen_("12345678"));
|
||||
EZBENCH2("strlen_pure 9", donothing, strlen_pure_("12345678"));
|
||||
EZBENCH2("strlen 11", donothing, strlen_("12345678aa"));
|
||||
EZBENCH2("strlen_pure 11", donothing, strlen_pure_("12345678aa"));
|
||||
EZBENCH2("strlen 13", donothing, strlen_("12345678aabb"));
|
||||
EZBENCH2("strlen_pure 13", donothing, strlen_pure_("12345678aabb"));
|
||||
EZBENCH2("strlen 16", donothing, strlen_("123456781234567"));
|
||||
EZBENCH2("strlen_pure 16", donothing, strlen_pure_("123456781234567"));
|
||||
EZBENCH2("strlen 17", donothing, strlen_("123456781234567e"));
|
||||
EZBENCH2("strlen_pure 17", donothing, strlen_pure_("123456781234567e"));
|
||||
EZBENCH2("strlen 34", donothing,
|
||||
strlen_("123456781234567e123456781234567ee"));
|
||||
EZBENCH2("strlen_swar 34", donothing,
|
||||
EZBENCH2("strlen_pure 34", donothing,
|
||||
strlen_pure_("123456781234567e123456781234567ee"));
|
||||
EZBENCH2("strlen_sse 68", donothing,
|
||||
EZBENCH2("strlen 68", donothing,
|
||||
strlen_("123456781234567e123456781234567ee123456781234567e1234567812"
|
||||
"34567eee"));
|
||||
EZBENCH2("strlen_swar 68", donothing,
|
||||
EZBENCH2("strlen_pure 68", donothing,
|
||||
strlen_pure_("123456781234567e123456781234567ee123456781234567e12345"
|
||||
"6781234567eee"));
|
||||
EZBENCH2("strlen_sse 256", donothing, strlen_(d));
|
||||
EZBENCH2("strlen_swar 256", donothing, strlen_pure_(d));
|
||||
EZBENCH2("strlen_sse 512", donothing, strlen_(c));
|
||||
EZBENCH2("strlen_swar 512", donothing, strlen_pure_(c));
|
||||
EZBENCH2("strlen_sse 2048", donothing, strlen_(b));
|
||||
EZBENCH2("strlen_swar 2048", donothing, strlen_pure_(b));
|
||||
EZBENCH2("strlen 256", donothing, strlen_(d));
|
||||
EZBENCH2("strlen_pure 256", donothing, strlen_pure_(d));
|
||||
EZBENCH2("strlen 512", donothing, strlen_(c));
|
||||
EZBENCH2("strlen_pure 512", donothing, strlen_pure_(c));
|
||||
EZBENCH2("strlen 2048", donothing, strlen_(b));
|
||||
EZBENCH2("strlen_pure 2048", donothing, strlen_pure_(b));
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ BENCH(ceill, bench) {
|
|||
double _ceil(double) asm("ceil");
|
||||
float _ceilf(float) asm("ceilf");
|
||||
long double _ceill(long double) asm("ceill");
|
||||
EZBENCH2("ceil", donothing, _ceil(.7)); /* ~3ns */
|
||||
EZBENCH2("ceil", donothing, _ceil(.7)); /* ~1ns */
|
||||
EZBENCH2("ceilf", donothing, _ceilf(.7)); /* ~3ns */
|
||||
EZBENCH2("ceill", donothing, _ceill(.7)); /* ~9ns */
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
@ -56,3 +57,12 @@ TEST(fabs, stuff) {
|
|||
EXPECT_EQ(1, !!isnan(fabs(-NAN)));
|
||||
EXPECT_EQ(0, !!signbit(fabs(-NAN)));
|
||||
}
|
||||
|
||||
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("fabsf", donothing, _fabsf(.7)); /* ~5ns */
|
||||
EZBENCH2("fabsl", donothing, _fabsl(.7)); /* ~28ns */
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ BENCH(floorl, bench) {
|
|||
double _floor(double) asm("floor");
|
||||
float _floorf(float) asm("floorf");
|
||||
long double _floorl(long double) asm("floorl");
|
||||
EZBENCH2("floor", donothing, _floor(.7)); /* ~3ns */
|
||||
EZBENCH2("floor", donothing, _floor(.7)); /* ~1ns */
|
||||
EZBENCH2("floorf", donothing, _floorf(.7)); /* ~3ns */
|
||||
EZBENCH2("floorl", donothing, _floorl(.7)); /* ~9ns */
|
||||
}
|
||||
|
|
|
@ -103,7 +103,6 @@ TEST(ldexp, stuff) {
|
|||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", ldexpl(pi, twopow))));
|
||||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalb(pi, twopow))));
|
||||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbf(pi, twopow))));
|
||||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", scalbl(pi, twopow))));
|
||||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbn(pi, twopow))));
|
||||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2f", scalbnf(pi, twopow))));
|
||||
ASSERT_STREQ("100.48", _gc(xasprintf("%.2Lf", scalbnl(pi, twopow))));
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/math.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
|
@ -124,6 +125,28 @@ TEST(rint, test) {
|
|||
EXPECT_STREQ("2", gc(xdtoa(rint(2.5))));
|
||||
}
|
||||
|
||||
TEST(lrint, test) {
|
||||
EXPECT_EQ(-2, lrint(-2.5));
|
||||
EXPECT_EQ(-2, lrint(-1.5));
|
||||
EXPECT_EQ(-0, lrint(-.5));
|
||||
EXPECT_EQ(-0, lrint(-.4));
|
||||
EXPECT_EQ(0, lrint(.4));
|
||||
EXPECT_EQ(0, lrint(.5));
|
||||
EXPECT_EQ(2, lrint(1.5));
|
||||
EXPECT_EQ(2, lrint(2.5));
|
||||
}
|
||||
|
||||
TEST(lrintf, test) {
|
||||
EXPECT_EQ(-2, lrintf(-2.5));
|
||||
EXPECT_EQ(-2, lrintf(-1.5));
|
||||
EXPECT_EQ(-0, lrintf(-.5));
|
||||
EXPECT_EQ(-0, lrintf(-.4));
|
||||
EXPECT_EQ(0, lrintf(.4));
|
||||
EXPECT_EQ(0, lrintf(.5));
|
||||
EXPECT_EQ(2, lrintf(1.5));
|
||||
EXPECT_EQ(2, lrintf(2.5));
|
||||
}
|
||||
|
||||
TEST(rintf, test) {
|
||||
EXPECT_STREQ("-2", gc(xdtoa(rintf(-2.5))));
|
||||
EXPECT_STREQ("-2", gc(xdtoa(rintf(-1.5))));
|
||||
|
@ -185,3 +208,22 @@ TEST(lroundl, test) {
|
|||
EXPECT_EQ(2, lroundl(1.5));
|
||||
EXPECT_EQ(3, lroundl(2.5));
|
||||
}
|
||||
|
||||
BENCH(round, bench) {
|
||||
EZBENCH2("double+.5", donothing, EXPROPRIATE(VEIL("x", (double)(-3.5)) + .5));
|
||||
EZBENCH2("float+.5f", donothing, EXPROPRIATE(VEIL("x", (float)(-3.5)) + .5));
|
||||
EZBENCH2("ldbl+.5l", donothing,
|
||||
EXPROPRIATE(VEIL("t", (long double)(-3.5)) + .5));
|
||||
double _round(double) asm("round");
|
||||
float _roundf(float) asm("roundf");
|
||||
long double _roundl(long double) asm("roundl");
|
||||
EZBENCH2("-round", donothing, _round(.7)); /* ~4ns */
|
||||
EZBENCH2("-roundf", donothing, _roundf(.7)); /* ~3ns */
|
||||
EZBENCH2("-roundl", donothing, _roundl(.7)); /* ~8ns */
|
||||
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 */
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue