Make further progress on non-x86 support

This commit is contained in:
Justine Tunney 2023-05-08 21:38:30 -07:00
parent aef9a69a60
commit 036b9a0002
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
155 changed files with 2307 additions and 653 deletions

View file

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

View file

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

View file

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

View file

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

View file

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