[libc] Make log2f correctly rounded for all rounding modes when FMA is not available.

Add to log2f 2 more exceptional cases got when not using fma for polyeval.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D117812
This commit is contained in:
Tue Ly 2022-01-20 13:51:04 -05:00
parent 5ef7abbc6f
commit 1f3f90ab88
2 changed files with 18 additions and 5 deletions

View File

@ -105,11 +105,24 @@ LLVM_LIBC_FUNCTION(float, log2f, (float x)) {
int m = 0;
// Hard to round value(s).
if (FPBits(x).uintval() == 0x3f81d0b5U) {
switch (FPBits(x).uintval()) {
case 0x3f81d0b5U: {
int rounding_mode = fputil::get_round();
if (rounding_mode == FE_DOWNWARD || rounding_mode == FE_TOWARDZERO) {
return 0x1.4cdc4cp-6f;
}
break;
}
case 0x3f7e3274U:
if (fputil::get_round() == FE_TONEAREST) {
return -0x1.4e1d16p-7f;
}
break;
case 0x3f7d57f5U:
if (fputil::get_round() == FE_TOWARDZERO) {
return -0x1.ed1c32p-7f;
}
break;
}
// Exceptional inputs.

View File

@ -31,10 +31,10 @@ TEST(LlvmLibcLog2fTest, SpecialNumbers) {
}
TEST(LlvmLibcLog2fTest, TrickyInputs) {
constexpr int N = 9;
constexpr uint32_t INPUTS[N] = {0x3f7d57f5U, 0x3f7ed848U, 0x3f7fd6ccU,
0x3f7fffffU, 0x3f80079bU, 0x3f81d0b5U,
0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U};
constexpr int N = 10;
constexpr uint32_t INPUTS[N] = {
0x3f7d57f5U, 0x3f7e3274U, 0x3f7ed848U, 0x3f7fd6ccU, 0x3f7fffffU,
0x3f80079bU, 0x3f81d0b5U, 0x3f82e602U, 0x3f83c98dU, 0x3f8cba39U};
for (int i = 0; i < N; ++i) {
float x = float(FPBits(INPUTS[i]));