mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(libc): implement __fpclassifyf
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user