feat(libc): implement __fpclassifyf

This commit is contained in:
Hannah Lyons
2026-10-08 23:39:16 -04:00
parent 8b393b6e9a
commit eb20ba1aaa
2 changed files with 16 additions and 0 deletions
+10
View File
@@ -105,6 +105,16 @@ short APS5_VABI _FDtest_nid_postfix(const float* value) {
return Finite;
}
int APS5_VABI __isnanf_nid_postfix(float x) { return std::isnan(x) ? 1 : 0; }
int APS5_VABI __fpclassifyf_nid_postfix(float x) {
constexpr int Infinite = 0x01, NotANumber = 0x02, Normal = 0x04, Subnormal = 0x08, Zero = 0x10;
std::uint32_t bits;
std::memcpy(&bits, &x, sizeof(bits));
const auto exponent = bits & 0x7f800000u;
const auto fraction = bits & 0x007fffffu;
if (exponent == 0) return fraction != 0 ? Subnormal : Zero;
if (exponent == 0x7f800000u) return fraction != 0 ? NotANumber : Infinite;
return Normal;
}
int APS5_VABI __signbitf_nid_postfix(float x) { return std::signbit(x) ? 1 : 0; }
static std::mutex g_randLock;
+6
View File
@@ -20,6 +20,7 @@ struct LibcFloatConstant { std::uint32_t bits[4]; };
extern LibcFloatConstant _FInf_nid_postfix;
extern LibcFloatConstant _FNan_nid_postfix;
short APS5_VABI _FDtest_nid_postfix(const float*);
int APS5_VABI __fpclassifyf_nid_postfix(float);
float APS5_VABI fmodf_nid_postfix(float, float);
float APS5_VABI asinf_nid_postfix(float);
float APS5_VABI acosf_nid_postfix(float);
@@ -155,6 +156,11 @@ static void CheckFloatClassification() {
std::fprintf(stderr, "Guest _FDtest failed for %08x\n", test.bits);
std::abort();
}
const int fpclass = test.code == 0 ? 0x10 : test.code == -2 ? 0x08 : test.code == -1 ? 0x04 : test.code == 1 ? 0x01 : 0x02;
if (__fpclassifyf_nid_postfix(value) != fpclass) {
std::fprintf(stderr, "Guest __fpclassifyf failed for %08x\n", test.bits);
std::abort();
}
}
Require(_FDtest_nid_postfix(reinterpret_cast<const float*>(&_FInf_nid_postfix)) == 1);
Require(_FDtest_nid_postfix(reinterpret_cast<const float*>(&_FNan_nid_postfix)) == 2);