From 618ba55a81518bc9f33af9eb9962b31ce20042ca Mon Sep 17 00:00:00 2001 From: Kyryl Melekhin Date: Thu, 10 Sep 2020 17:35:36 +0000 Subject: [PATCH] fix float to u64 intrinsics reverts commit 310e3b428cfd181b51723276e6563b90d670da06 (more info there) now functions check for sign bit in float. now hopefully this patch will cover entirety of areas it might affect --- lib/libtcc1.c | 35 ++++++++++++++++++++++++++--------- tccgen.c | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/libtcc1.c b/lib/libtcc1.c index 0e466180..89f0018c 100644 --- a/lib/libtcc1.c +++ b/lib/libtcc1.c @@ -541,13 +541,19 @@ unsigned long long __fixunssfdi (float a1) l = MANT(fl1.l); if (exp >= 41) - return (unsigned long long)-1; + return (unsigned long long)-1; else if (exp >= 0) - return (unsigned long long)l << exp; + if(SIGN(fl1.l)) + return (unsigned long long)-(l << exp); + else + return (unsigned long long)l << exp; else if (exp >= -23) - return l >> -exp; + if(SIGN(fl1.l)) + return -(l >> -exp); + else + return l >> -exp; else - return 0; + return 0; } long long __fixsfdi (float a1) @@ -573,13 +579,19 @@ unsigned long long __fixunsdfdi (double a1) l = MANTD_LL(dl1); if (exp >= 12) - return (unsigned long long)-1; + return (unsigned long long)-1; else if (exp >= 0) - return l << exp; + if(SIGND(dl1)) + return -(l >> exp); + else + return l << exp; else if (exp >= -52) - return l >> -exp; + if(SIGND(dl1)) + return -(l >> -exp); + else + return l >> -exp; else - return 0; + return 0; } long long __fixdfdi (double a1) @@ -608,7 +620,12 @@ unsigned long long __fixunsxfdi (long double a1) if (exp > 0) return (unsigned long long)-1; else if (exp >= -63) - return l >> -exp; + { + if(SIGNLD(dl1)) + return -(l >> -exp); + else + return l >> -exp; + } else return 0; } diff --git a/tccgen.c b/tccgen.c index 305a082b..dd6a497a 100644 --- a/tccgen.c +++ b/tccgen.c @@ -3478,7 +3478,7 @@ again: vtop->c.i = (vtop->c.ld != 0); } else { if(sf) - vtop->c.i = (int64_t)vtop->c.ld; + vtop->c.i = vtop->c.ld; else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR)) ; else if (sbt & VT_UNSIGNED)