1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

Userland+Tests: Add initial riscv64 support

This commit is contained in:
Sönke Holz 2023-09-18 12:56:39 +02:00 committed by Andrew Kaster
parent c6b2a07326
commit 6824d2a788
23 changed files with 262 additions and 34 deletions

View file

@ -9,7 +9,7 @@
#include <AK/BuiltinWrappers.h>
#include <AK/FloatingPoint.h>
#if !ARCH(AARCH64)
#if ARCH(X86_64)
# include <AK/FPControl.h>
#endif
#include <AK/Math.h>
@ -363,7 +363,7 @@ MAKE_AK_BACKED2(remainder);
long double truncl(long double x) NOEXCEPT
{
#if !ARCH(AARCH64)
#if ARCH(X86_64)
if (fabsl(x) < LONG_LONG_MAX) {
// This is 1.6 times faster than the implementation using the "internal_to_integer"
// helper (on x86_64)
@ -383,7 +383,7 @@ long double truncl(long double x) NOEXCEPT
double trunc(double x) NOEXCEPT
{
#if !ARCH(AARCH64)
#if ARCH(X86_64)
if (fabs(x) < LONG_LONG_MAX) {
u64 temp;
asm(
@ -400,7 +400,7 @@ double trunc(double x) NOEXCEPT
float truncf(float x) NOEXCEPT
{
#if !ARCH(AARCH64)
#if ARCH(X86_64)
if (fabsf(x) < LONG_LONG_MAX) {
u64 temp;
asm(
@ -420,13 +420,18 @@ long double rintl(long double value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long double res;
asm(
"frndint\n"
: "=t"(res)
: "0"(value));
return res;
#else
# error "Unknown architecture"
#endif
}
double rint(double value)
@ -434,13 +439,18 @@ double rint(double value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
double res;
asm(
"frndint\n"
: "=t"(res)
: "0"(value));
return res;
#else
# error "Unknown architecture"
#endif
}
float rintf(float value)
@ -448,13 +458,18 @@ float rintf(float value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
float res;
asm(
"frndint\n"
: "=t"(res)
: "0"(value));
return res;
#else
# error "Unknown architecture"
#endif
}
@ -463,7 +478,10 @@ long lrintl(long double value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long res;
asm(
"fistpl %0\n"
@ -471,6 +489,8 @@ long lrintl(long double value)
: "t"(value)
: "st");
return res;
#else
# error "Unknown architecture"
#endif
}
long lrint(double value)
@ -478,7 +498,10 @@ long lrint(double value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long res;
asm(
"fistpl %0\n"
@ -486,6 +509,8 @@ long lrint(double value)
: "t"(value)
: "st");
return res;
#else
# error "Unknown architecture"
#endif
}
long lrintf(float value)
@ -493,7 +518,10 @@ long lrintf(float value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long res;
asm(
"fistpl %0\n"
@ -501,6 +529,8 @@ long lrintf(float value)
: "t"(value)
: "st");
return res;
#else
# error "Unknown architecture"
#endif
}
@ -509,7 +539,10 @@ long long llrintl(long double value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long long res;
asm(
"fistpq %0\n"
@ -517,6 +550,8 @@ long long llrintl(long double value)
: "t"(value)
: "st");
return res;
#else
# error "Unknown architecture"
#endif
}
long long llrint(double value)
@ -524,7 +559,10 @@ long long llrint(double value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long long res;
asm(
"fistpq %0\n"
@ -532,6 +570,8 @@ long long llrint(double value)
: "t"(value)
: "st");
return res;
#else
# error "Unknown architecture"
#endif
}
long long llrintf(float value)
@ -539,7 +579,10 @@ long long llrintf(float value)
#if ARCH(AARCH64)
(void)value;
TODO_AARCH64();
#else
#elif ARCH(RISCV64)
(void)value;
TODO_RISCV64();
#elif ARCH(X86_64)
long long res;
asm(
"fistpq %0\n"
@ -547,6 +590,8 @@ long long llrintf(float value)
: "t"(value)
: "st");
return res;
#else
# error "Unknown architecture"
#endif
}