Test compile: mpn_lshift_com optimization 2
Emmanuel Thomé
Emmanuel.Thome at inria.fr
Wed Jan 4 13:31:29 UTC 2017
On Wed, Jan 04, 2017 at 02:16:15PM +0100, Niels Möller wrote:
> Richard Biener <rguenther at suse.de> writes:
> > This test intoduced with GMP 6.1.2 FAILs with malloc debugging
> > because it appearantly relies on malloc returing zeroed memory?
> > Or it tests the wrong array elements?
>
> Can you please clarify which test program fails? There's no "t.c" or
> "a.out" files in my gmp tree. Please also provide the additional
> information requested in the Bug reporting instructions in the manual.
Richard refers to the configure check whose name is in the Subject line,
defined at line 704 in acinclude.m4 (and pasted below).
I read that code, I'm puzzled too. Given that ceil(528/23)==23, and that
23*89 is 2047, I don't see how one could expect r[2048] and such to
contain anything different from what is returned by malloc(). Which
should be assumed to be garbage.
E.
GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization 2],
[/* The following is mis-compiled by Intel ia-64 icc version 1.8 under
"icc -O3", After several calls, the function writes partial garbage to
the result vector. Perhaps relates to the chk.a.nc insn. This code needs
to be run to show the problem, but that's fine, the offending cc is a
native-only compiler so we don't have to worry about cross compiling. */
#if ! defined (__cplusplus)
#include <stdlib.h>
void
lshift_com (rp, up, n, cnt)
unsigned long *rp;
unsigned long *up;
long n;
unsigned cnt;
{
unsigned long high_limb, low_limb;
unsigned tnc;
long i;
up += n;
rp += n;
tnc = 8 * sizeof (unsigned long) - cnt;
low_limb = *--up;
high_limb = low_limb << cnt;
for (i = n - 1; i != 0; i--)
{
low_limb = *--up;
*--rp = ~(high_limb | (low_limb >> tnc));
high_limb = low_limb << cnt;
}
*--rp = ~high_limb;
}
int
main ()
{
unsigned long *r, *r2;
unsigned long a[88 + 1];
long i;
for (i = 0; i < 88 + 1; i++)
a[i] = ~0L;
r = malloc (10000 * sizeof (unsigned long));
r2 = r;
for (i = 0; i < 528; i += 23)
{
lshift_com (r2, a,
i / (8 * sizeof (unsigned long)) + 1,
i % (8 * sizeof (unsigned long)));
r2 += 88 + 1;
}
if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
abort ();
free (r);
return 0;
}
#else
int
main ()
{
return 0;
}
#endif
])
More information about the gmp-devel
mailing list