This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libgcc/78067] liggcc2 calls count_leading_zero with 0
- From: "bernd.edlinger at hotmail dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 21 Oct 2016 19:41:07 +0000
- Subject: [Bug libgcc/78067] liggcc2 calls count_leading_zero with 0
- Auto-submitted: auto-generated
- References: <bug-78067-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78067
--- Comment #2 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
This happens with __floattisf and __floattidf in 64bit libgcc.
But because a bsr $rsi,$rsi is used, apparently the result register is zero,
when the input is zero and not completely undefined. Thus __floattisf/df
seems to return correct results although the count is 63 instead of 64.
That seems to be just luck, if other registers would be used, the function
would fail.
Possible patch:
Index: libgcc2.c
===================================================================
--- libgcc2.c (revision 241400)
+++ libgcc2.c (working copy)
@@ -1643,6 +1643,11 @@
hi = -(UWtype) hi;
UWtype count, shift;
+#if !defined (COUNT_LEADING_ZEROS_0) || COUNT_LEADING_ZEROS_0 != W_TYPE_SIZE
+ if (hi == 0)
+ count = W_TYPE_SIZE;
+ else
+#endif
count_leading_zeros (count, hi);
/* No leading bits means u == minimum. */