Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/libs/prx/libSceLibcInternal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ if(BUILD_TESTING)
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
endif()
endif()
target_sources(libSceLibcInternal PRIVATE ScaledPow.cpp)
if(BUILD_TESTING)
add_test_executable(guest_libc_internal_scaled_pow_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalScaledPow.cpp)
target_include_directories(guest_libc_internal_scaled_pow_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_internal_scaled_pow_tests PRIVATE libSceLibcInternal libkernel libc)
configure_windows_unwind(guest_libc_internal_scaled_pow_tests)
add_test(NAME guest_libc_internal_scaled_pow COMMAND guest_libc_internal_scaled_pow_tests)
set_tests_properties(guest_libc_internal_scaled_pow PROPERTIES TIMEOUT 20)
if(WIN32)
set_tests_properties(guest_libc_internal_scaled_pow PROPERTIES ENVIRONMENT_MODIFICATION
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libSceLibcInternal>")
endif()
endif()
target_sources(libSceLibcInternal PRIVATE HalfPrecision.cpp)
if(BUILD_TESTING)
add_test_executable(guest_libc_internal_half_precision_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcInternalHalfPrecision.cpp)
Expand Down
15 changes: 0 additions & 15 deletions core/libs/prx/libSceLibcInternal/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,11 +727,6 @@ int APS5_VABI _FLogpoly_nid_postfix() {
return 0;
}

int APS5_VABI _FPow_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI _FQuad_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand Down Expand Up @@ -922,11 +917,6 @@ int APS5_VABI _LLogpoly_nid_postfix() {
return 0;
}

int APS5_VABI _LPow_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI _LQuad_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand Down Expand Up @@ -1017,11 +1007,6 @@ int APS5_VABI _Nnl_nid_postfix() {
return 0;
}

int APS5_VABI _Pow_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
}

int APS5_VABI _Printf_nid_postfix() {
NotImplemented_nid_no_patch(__func__);
return 0;
Expand Down
22 changes: 22 additions & 0 deletions core/libs/prx/libSceLibcInternal/ScaledPow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "prx/libSceLibcInternal/include/MathInternals.hpp"
#include "prx/libc/include/Api.hpp"
#include "prx/libc/include/General.hpp"

extern "C" {

double APS5_VABI _Pow_nid_postfix(double x, double y, short* exponent) {
if (exponent != nullptr) NotImplemented_nid_no_patch("_Pow: a non-null exponent pointer");
return pow_nid_postfix(x, y);
}

float APS5_VABI _FPow_nid_postfix(float x, float y, short* exponent) {
if (exponent != nullptr) NotImplemented_nid_no_patch("_FPow: a non-null exponent pointer");
return powf_nid_postfix(x, y);
}

long double APS5_VABI _LPow_nid_postfix(long double x, long double y, short* exponent) {
if (exponent != nullptr) NotImplemented_nid_no_patch("_LPow: a non-null exponent pointer");
return powl_nid_postfix(x, y);
}

}
6 changes: 3 additions & 3 deletions core/libs/prx/libSceLibcInternal/include/MathInternals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ float APS5_VABI _FDtento_nid_postfix(float* value, std::int64_t power, int* erro
int APS5_VABI _FErfc_nid_postfix();
int APS5_VABI _FHypot_nid_postfix();
int APS5_VABI _FLogpoly_nid_postfix();
int APS5_VABI _FPow_nid_postfix();
float APS5_VABI _FPow_nid_postfix(float x, float y, short* exponent);
int APS5_VABI _FQuad_nid_postfix();
int APS5_VABI _FQuadph_nid_postfix();
int APS5_VABI _FRint_nid_postfix();
Expand All @@ -40,7 +40,7 @@ long double APS5_VABI _LDtento_nid_postfix(long double* value, std::int64_t powe
int APS5_VABI _LErfc_nid_postfix();
int APS5_VABI _LHypot_nid_postfix();
int APS5_VABI _LLogpoly_nid_postfix();
int APS5_VABI _LPow_nid_postfix();
long double APS5_VABI _LPow_nid_postfix(long double x, long double y, short* exponent);
int APS5_VABI _LQuad_nid_postfix();
int APS5_VABI _LQuadph_nid_postfix();
int APS5_VABI _LRint_nid_postfix();
Expand All @@ -61,7 +61,7 @@ long double* APS5_VABI _LXp_sqrtx_nid_postfix(long double* p, int n, long double
long double* APS5_VABI _LXp_subx_nid_postfix(long double* p, int n, const long double* q, int m);
int APS5_VABI _Logpoly_nid_postfix();
int APS5_VABI _Nnl_nid_postfix();
int APS5_VABI _Pow_nid_postfix();
double APS5_VABI _Pow_nid_postfix(double x, double y, short* exponent);
int APS5_VABI _Quad_nid_postfix();
int APS5_VABI _Quadph_nid_postfix();
double APS5_VABI _Xp_getw_nid_postfix(const double* p, int n);
Expand Down
48 changes: 48 additions & 0 deletions core/libs/tests/GuestLibcInternalScaledPow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "prx/libSceLibcInternal/include/MathInternals.hpp"
#include "prx/libc/include/Api.hpp"

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <limits>

namespace {

void Require(bool condition, const char* message) {
if (condition) return;
std::fprintf(stderr, "libc internal scaled pow: %s\n", message);
std::abort();
}

template <typename T>
bool Same(T left, T right) {
if (std::isnan(left) && std::isnan(right)) return true;
return left == right && std::signbit(left) == std::signbit(right);
}

void TestNullExponent() {
const double infinity = std::numeric_limits<double>::infinity();
const double nan = std::numeric_limits<double>::quiet_NaN();
const double pairs[][2] = {
{2.0, 10.0}, {2.0, 0.5}, {-8.0, 1.0 / 3.0}, {-2.0, 3.0}, {-0.0, -1.0}, {0.0, -2.0}, {10.0, 400.0}, {10.0, -400.0},
{1.0, nan}, {nan, 0.0}, {-1.0, infinity}, {0.5, -infinity}, {infinity, -0.5}, {-infinity, 3.0}, {1.0000001, 1e9}, {3.7, -2.25}};
for (const auto& pair : pairs) {
Require(Same(_Pow_nid_postfix(pair[0], pair[1], nullptr), pow_nid_postfix(pair[0], pair[1])), "_Pow with a null exponent is pow");
const float fx = static_cast<float>(pair[0]);
const float fy = static_cast<float>(pair[1]);
Require(Same(_FPow_nid_postfix(fx, fy, nullptr), powf_nid_postfix(fx, fy)), "_FPow with a null exponent is powf");
const long double lx = pair[0];
const long double ly = pair[1];
Require(Same(_LPow_nid_postfix(lx, ly, nullptr), powl_nid_postfix(lx, ly)), "_LPow with a null exponent is powl");
}
Require(_Pow_nid_postfix(2.0, 10.0, nullptr) == 1024.0, "_Pow 2 10");
Require(_FPow_nid_postfix(3.0f, 2.0f, nullptr) == 9.0f, "_FPow 3 2");
Require(_LPow_nid_postfix(2.0L, -2.0L, nullptr) == 0.25L, "_LPow 2 -2");
}

}

int main() {
TestNullExponent();
return 0;
}
5 changes: 5 additions & 0 deletions docs/dev/debt/changes/feat-libsce-libcinternal-pow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# libSceLibcInternal

## add Functional

- [_Pow, _FPow and _LPow](../../../core/libs/prx/libSceLibcInternal/ScaledPow.cpp) (libSceLibcInternal) - not measured on the console; only a null `short*` exponent, the argument Dinkumware's `pow` passes, is implemented, and returns libc's `pow`, `powf` or `powl`. A non-null exponent throws: what the module writes through it, and how it scales the result, is unknown. Results come from libc's msun functions, not Dinkumware's, so last bits can differ. The `(x, y, short* pex)` prototype and the `pow(x, y)` call `_Pow(x, y, 0)` are Dinkumware V6.50's ([xxpow.h](https://github.com/bergsteiger/realwork/blob/19b446ce8ad2adf82ab8ce7988bc003221accad2/common/components/rtl/external/Embarcadero/DelphiBerlin/cpprtl/Source/dinkumware64/source/xxpow.h)). Closes when: the module is measured with a non-null exponent.
Loading