GMP 6.1.2 t-count_zeros failure on ARM with assertions

Vincent Lefevre vincent at vinc17.net
Wed Jan 17 16:09:24 UTC 2018


On 2017-12-27 17:15:43 +0100, Niels Möller wrote:
> Vincent Lefevre <vincent at vinc17.net> writes:
> 
> >> diff -r 20cf1131dc94 longlong.h
> >> --- a/longlong.h	Thu Aug 31 01:00:02 2017 +0200
> >> +++ b/longlong.h	Tue Dec 26 10:59:24 2017 +0100
> >> @@ -535,7 +535,6 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype 
> >>  #endif /* defined(__ARM_ARCH_2__) ... */
> >>  #define count_leading_zeros(count, x)  count_leading_zeros_gcc_clz(count, x)
> >>  #define count_trailing_zeros(count, x)  count_trailing_zeros_gcc_ctz(count, x)
> >> -#define COUNT_LEADING_ZEROS_0 32
> >>  #endif /* __arm__ */
> >>  
> >>  #if defined (__aarch64__) && W_TYPE_SIZE == 64
> >> @@ -586,7 +585,6 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype 
> >>  #endif
> >>  #define count_leading_zeros(count, x)  count_leading_zeros_gcc_clz(count, x)
> >>  #define count_trailing_zeros(count, x)  count_trailing_zeros_gcc_ctz(count, x)
> >> -#define COUNT_LEADING_ZEROS_0 64
> >>  #endif /* __aarch64__ */
> >>  
> >>  #if defined (__clipper__) && W_TYPE_SIZE == 32
> >
> > I confirm that this fixes the problem.
> 
> Thanks for testing. Pushed now.

This is not sufficient. I get a failure for 32-bit x86 with MinGW.
This one is incorrect too:

#else /* ! pentiummmx || LONGLONG_STANDALONE */
/* The following should be a fixed 14 cycles or so.  Some scheduling
   opportunities should be available between the float load/store too.  This
   sort of code is used in gcc 3 for __builtin_ffs (with "n&-n") and is
   apparently suggested by the Intel optimizing manual (don't know exactly
   where).  gcc 2.95 or up will be best for this, so the "double" is
   correctly aligned on the stack.  */
#define count_leading_zeros(c,n)                                        \
  do {                                                                  \
    union {                                                             \
      double    d;                                                      \
      unsigned  a[2];                                                   \
    } __u;                                                              \
    ASSERT ((n) != 0);                                                  \
    __u.d = (UWtype) (n);                                               \
    (c) = 0x3FF + 31 - (__u.a[1] >> 20);                                \
  } while (0)
#define COUNT_LEADING_ZEROS_0   (0x3FF + 31)
#endif /* pentiummx */

There's also a typo in the latest comment. Patch attached.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
-------------- next part --------------
diff -r bd031c4d736b longlong.h
--- a/longlong.h	Wed Jan 17 05:34:55 2018 +0100
+++ b/longlong.h	Wed Jan 17 17:05:06 2018 +0100
@@ -965,8 +965,7 @@
     __u.d = (UWtype) (n);						\
     (c) = 0x3FF + 31 - (__u.a[1] >> 20);				\
   } while (0)
-#define COUNT_LEADING_ZEROS_0   (0x3FF + 31)
-#endif /* pentiummx */
+#endif /* pentiummmx */
 
 #else /* ! pentium */
 


More information about the gmp-bugs mailing list