diff --git a/core/libs/prx/libc/Export.cpp b/core/libs/prx/libc/Export.cpp index fb67f24bbb9a..91248c84d4a7 100644 --- a/core/libs/prx/libc/Export.cpp +++ b/core/libs/prx/libc/Export.cpp @@ -61,11 +61,7 @@ std::uint64_t APS5_VABI _Iswctype_nid_postfix() { return 0; } -APS5_EXPORT("H+8UBOwfScI", libcCyberUnknown08); -std::uint64_t APS5_VABI libcCyberUnknown08(void) { - NotImplemented_nid_no_patch("H+8UBOwfScI"); - return 0; -} +APS5_EXPORT("H+8UBOwfScI", __powidf2_nid_postfix); std::uint64_t APS5_VABI _WStoul_nid_postfix() { NotImplemented_nid_no_patch(__func__); diff --git a/core/libs/prx/libc/src/Math.cpp b/core/libs/prx/libc/src/Math.cpp index 2828d8ed42cc..4632df975505 100644 --- a/core/libs/prx/libc/src/Math.cpp +++ b/core/libs/prx/libc/src/Math.cpp @@ -71,6 +71,18 @@ float APS5_VABI atanf_nid_postfix(float x) { return std::atan(x); } double APS5_VABI atan2_nid_postfix(double y, double x) { return std::atan2(y, x); } float APS5_VABI powf_nid_postfix(float base, float exp) { return std::pow(base, exp); } double APS5_VABI pow_nid_postfix(double base, double exp) { return std::pow(base, exp); } + +double APS5_VABI __powidf2_nid_postfix(double base, int exp) { + const int recip = exp < 0; + double result = 1; + while (true) { + if ((exp & 1) != 0) result *= base; + exp /= 2; + if (exp == 0) break; + base *= base; + } + return recip != 0 ? 1 / result : result; +} float APS5_VABI expf_nid_postfix(float x) { return std::exp(x); } float APS5_VABI exp2f_nid_postfix(float x) { return std::exp2(x); } float APS5_VABI logf_nid_postfix(float x) { return std::log(x); } diff --git a/core/libs/tests/GuestMath.cpp b/core/libs/tests/GuestMath.cpp index ee0b4d20ff24..f0d485cf767d 100644 --- a/core/libs/tests/GuestMath.cpp +++ b/core/libs/tests/GuestMath.cpp @@ -51,8 +51,10 @@ int APS5_VABI __isnormalf_nid_postfix(float); int APS5_VABI __isinff_nid_postfix(float); std::lldiv_t APS5_VABI lldiv_nid_postfix(long long, long long); std::lldiv_t APS5_VABI ldiv_nid_postfix(std::int64_t, std::int64_t); +double APS5_VABI __powidf2_nid_postfix(double, int); } static void Require(bool value) { if (!value) std::abort(); } +static void CheckPowi(); static void CheckIntegerConversions() { for (const long long numerator : {4294967301LL, -4294967301LL}) { @@ -201,6 +203,7 @@ static void CheckFloatClassification() { int main() { CheckFloatClassification(); CheckIntegerConversions(); + CheckPowi(); Require(atof_nid_postfix(" -12.5tail") == -12.5); char* end = nullptr; const char input[] = "0x1.8p+2 remainder"; @@ -269,3 +272,24 @@ int main() { const auto minimum = div_nid_postfix(std::numeric_limits::min(), 10); Require(minimum.quot == -214748364 && minimum.rem == -8); } + +static void CheckPowi() { + Require(__powidf2_nid_postfix(2.0, 10) == 1024.0); + Require(__powidf2_nid_postfix(2.0, -3) == 0.125); + Require(__powidf2_nid_postfix(-2.0, 3) == -8.0); + Require(__powidf2_nid_postfix(3.0, 5) == 243.0); + Require(__powidf2_nid_postfix(5.0, 0) == 1.0); + Require(__powidf2_nid_postfix(std::numeric_limits::quiet_NaN(), 0) == 1.0); + Require(__powidf2_nid_postfix(std::numeric_limits::infinity(), 0) == 1.0); + Require(__powidf2_nid_postfix(0.0, 5) == 0.0); + Require(__powidf2_nid_postfix(0.0, -1) == std::numeric_limits::infinity()); + Require(__powidf2_nid_postfix(-0.0, -1) == -std::numeric_limits::infinity()); + Require(__powidf2_nid_postfix(0.5, std::numeric_limits::min()) == std::numeric_limits::infinity()); + Require(__powidf2_nid_postfix(2.0, std::numeric_limits::min()) == 0.0); + Require(__powidf2_nid_postfix(-1.0, std::numeric_limits::min()) == 1.0); + Require(__powidf2_nid_postfix(-1.0, std::numeric_limits::max()) == -1.0); + Require(__powidf2_nid_postfix(1.5, std::numeric_limits::max()) == std::numeric_limits::infinity()); + Require(std::bit_cast(__powidf2_nid_postfix(-2.0, 3)) == UINT64_C(0xc020000000000000)); + Require(std::abs(__powidf2_nid_postfix(10.0, -5) - 0.00001) < 1e-20); + Require(std::abs(__powidf2_nid_postfix(1.1, 13) - std::pow(1.1, 13)) < 1e-12); +} diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 4656d0fbbc31..da79c5f0d729 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -242,6 +242,7 @@ Throughout the project, every function at every stage either **does exactly what - [sceRtcFormatRFC2822, sceRtcFormatRFC2822LocalTime, sceRtcFormatRFC3339LocalTime](../../core/libs/prx/libSceRtc/Export.cpp) (libSceRtc) - only shadPS4 (PS4) has bodies. A null tick returns `INVALID_POINTER` like the existing `sceRtcFormatRFC3339`, where shadPS4 formats the current time instead; offsets outside ±1439 minutes return `INVALID_VALUE` like `sceRtcFormatRFC3339`; the local-time variants use the host's offset at the given instant (shadPS4 uses `sceKernelGettimezone`, the current offset) - [snwprintf_s](../../core/libs/prx/libc/src/FormattingWide.cpp) (libc) - follows C11 K.3.9.1.3 with `RSIZE_MAX` assumed to be `SIZE_MAX >> 1`. A runtime-constraint violation only returns a negative value: `set_constraint_handler_s` is not exported and the console's default handler is unknown. An invalid multibyte `%s` argument is copied byte by byte instead of being reported as an encoding error, as in `vswprintf` - [libSceUlt ulthreads](../../core/libs/prx/libSceUlt/Export.cpp) - `_sceUltUlthreadRuntimeOptParamInitialize`, `_sceUltUlthreadRuntimeCreate` and `_sceUltUlthreadCreate` are assumed to take the same arguments as the existing exports without the underscore, including the trailing build version. `sceUltUlthreadTryJoin` is assumed to return `ULT_ERROR_BUSY` while the ulthread runs, and `sceUltUlthreadRuntimeDestroy` to return `ULT_ERROR_BUSY` while an ulthread created on the runtime is not joined. Neither error has been confirmed on PS5 hardware +- [`__powidf2`](../../core/libs/prx/libc/src/Math.cpp) (libc) - the integer-power compiler helper, implemented as LLVM compiler-rt writes it. Exported under the hashed NID `H+8UBOwfScI` that Cyberpunk 2077 imports (listed in #2010); the console's `libc.prx` behavior for this export is unverified - [libSceUlt queues](../../core/libs/prx/libSceUlt/Export.cpp) - the added `sceUltQueuePop`, `sceUltQueueTryPush`, `sceUltQueueDestroy` and `sceUltQueueDataResourcePoolDestroy` signatures are inferred from the existing push/pop and object APIs. Queue destruction is assumed to reject blocked callers with `ULT_ERROR_BUSY` and otherwise discard queued data; pool exhaustion returns `ULT_ERROR_AGAIN`. These rules, alignment checks and shared slot limits have not been confirmed on PS5 hardware or a title. Non-null queue and data-pool option parameters throw because their layouts are unknown. - [AC1FtjqMCL0](../../core/libs/prx/libkernel/Unimplemented.cpp) (libkernel) - unknown name, signature - [0iEKNAvT600](../../core/libs/prx/libkernel/Unimplemented.cpp) (libkernel) - unknown name, signature