Skip to content

Commit 8d15cfa

Browse files
committed
Replaced the computation for valid X with polynomial approximation
1 parent 10f2410 commit 8d15cfa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libc/src/math/generic/rsqrtf16.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ LLVM_LIBC_FUNCTION(float16, rsqrtf16, (float16 x)) {
6060
return fputil::cast<float16>(1.0f);
6161
}
6262

63-
// x is valid, estimate the result - below is temporary solution for just
64-
// testing
63+
// x is valid, estimate the result
64+
// 3-degree polynomial generated using Sollya
65+
// P = fpminimax(1/sqrt(x), [|1, 2, 3|], [|SG...|], [0.5, 1]);
6566
float xf = x;
66-
return fputil::cast<float16>(1.0f / xf);
67+
float result =
68+
fputil::polyeval(xf, 0x1.d42408p2f, -0x1.7cc4fep3f, 0x1.66cb6ap2f);
69+
return fputil::cast<float16>(result);
6770
}
6871
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)