Merge pull request #4037 from Nixitov/feat/libc-divti3
feat(libc): implement __divti3
This commit is contained in:
commit
baee04e810
|
|
@ -195,6 +195,19 @@ inline unsigned __int128 SonyUdivti3(unsigned __int128 dividend, unsigned __int1
|
|||
return quotient;
|
||||
}
|
||||
|
||||
inline __int128 SonyDivti3(__int128 dividend, __int128 divisor) {
|
||||
if (divisor == 0) throw std::runtime_error("__divti3: integer divide by zero");
|
||||
const bool negative = (dividend < 0) != (divisor < 0);
|
||||
const unsigned __int128 magnitudeDividend = dividend < 0
|
||||
? (unsigned __int128)0 - (unsigned __int128)dividend
|
||||
: (unsigned __int128)dividend;
|
||||
const unsigned __int128 magnitudeDivisor = divisor < 0
|
||||
? (unsigned __int128)0 - (unsigned __int128)divisor
|
||||
: (unsigned __int128)divisor;
|
||||
const unsigned __int128 magnitude = SonyUdivti3(magnitudeDividend, magnitudeDivisor);
|
||||
return (__int128)(negative ? (unsigned __int128)0 - magnitude : magnitude);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -180,6 +180,10 @@ void APS5_VABI _Unlocksyslock_nid_postfix() {
|
|||
g_sysLock.unlock();
|
||||
}
|
||||
|
||||
__int128 APS5_VABI __divti3_nid_postfix(__int128 dividend, __int128 divisor) {
|
||||
return SonyDivti3(dividend, divisor);
|
||||
}
|
||||
|
||||
unsigned __int128 APS5_VABI __udivti3_nid_postfix(unsigned __int128 dividend, unsigned __int128 divisor) {
|
||||
return SonyUdivti3(dividend, divisor);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ std::size_t APS5_VABI mbstowcs_nid_postfix(std::uint16_t* dest, const char* src,
|
|||
char* APS5_VABI strtok_s_nid_postfix(char* str, const char* delim, char** context);
|
||||
int APS5_VABI __fpclassifyd_nid_postfix(double value);
|
||||
unsigned __int128 APS5_VABI __udivti3_nid_postfix(unsigned __int128 dividend, unsigned __int128 divisor);
|
||||
__int128 APS5_VABI __divti3_nid_postfix(__int128 dividend, __int128 divisor);
|
||||
SonyLconv* APS5_VABI localeconv_nid_postfix(void);
|
||||
int APS5_VABI sceAmprFpclassifyd(double value);
|
||||
unsigned int APS5_VABI _ZSt14_Random_devicev_nid_postfix();
|
||||
|
|
@ -85,6 +86,29 @@ int main() {
|
|||
}
|
||||
Require(trapped);
|
||||
|
||||
Require(__divti3_nid_postfix(100, 3) == 33);
|
||||
Require(__divti3_nid_postfix(-100, 3) == -33);
|
||||
Require(__divti3_nid_postfix(100, -3) == -33);
|
||||
Require(__divti3_nid_postfix(-100, -3) == 33);
|
||||
Require(SonyDivti3(0, 5) == 0);
|
||||
const __int128 large = (__int128)1 << 100;
|
||||
Require(SonyDivti3(large, 3) == large / 3);
|
||||
Require(SonyDivti3(-large, 3) == -(large / 3));
|
||||
Require(SonyDivti3(large, -3) == -(large / 3));
|
||||
Require(SonyDivti3(-large, -3) == large / 3);
|
||||
const __int128 minimum = (__int128)((unsigned __int128)1 << 127);
|
||||
const __int128 maximum = (__int128)(((unsigned __int128)1 << 127) - 1);
|
||||
Require(SonyDivti3(minimum, 1) == minimum);
|
||||
Require(SonyDivti3(minimum, -1) == minimum);
|
||||
Require(SonyDivti3(maximum, -1) == -maximum);
|
||||
trapped = false;
|
||||
try {
|
||||
SonyDivti3(1, 0);
|
||||
} catch (const std::exception&) {
|
||||
trapped = true;
|
||||
}
|
||||
Require(trapped);
|
||||
|
||||
void* previous = sceAmprSetConstraintHandlerS(reinterpret_cast<void*>(&CountingHandler));
|
||||
Require(previous != nullptr);
|
||||
Require(previous != reinterpret_cast<void*>(&CountingHandler));
|
||||
|
|
|
|||
Loading…
Reference in New Issue