Community
cancel
Showing results for 
Search instead for 
Did you mean: 
vinc17
Beginner
250 Views

ICX bug (bad code) with __float128 [2021.1 Beta 20200715]

When testing GNU MPFR with ICX 2021.1 Beta 20200715, the test tset_float128 failed. Here's a simple testcase:

#include <stdio.h>

void foo (__float128 d)
{
  int i;
  __float128 p[8], q[8];

  if (d >= 1.0)
    {
      p[0] = 2.0;
      q[0] = 0.5;
      printf ("q[0] = %a\n", (double) q[0]);
      for (i = 0; i < 13 && d >= p[i]; i++)
        {
          printf ("q[%d] = %a\n", i, (double) q[i]);
          p[i+1] = p[i] * p[i];
          q[i+1] = q[i] * q[i];
        }
      for (; i >= 0; i--)
        if (d >= p[i])
          d *= q[i];
    }
  else if (d < 0.5)
    {
      p[0] = 2.0;
      q[0] = 0.5;
      for (i = 0; i < 13 && d < q[i]; i++)
        {
          p[i+1] = p[i] * p[i];
          q[i+1] = q[i] * q[i];
        }
      for (; i >= 0; i--)
        while (d < q[i])
          d *= p[i];
    }

  return;
}

int main (void)
{
  volatile __float128 d = 65536;

  foo (d);
  return 0;
}

When I compile this code with optimizations (i.e. not with -O0), I get:

q[0] = 0x1p-1
q[0] = 0x0p+0
q[1] = 0x0p+0
q[2] = 0x0p+0
q[3] = 0x0p+0
q[4] = 0x0p+0

instead of

q[0] = 0x1p-1
q[0] = 0x1p-1
q[1] = 0x1p-2
q[2] = 0x1p-4
q[3] = 0x1p-8
q[4] = 0x1p-16

 

0 Kudos
2 Replies
vinc17
Beginner
245 Views

Actually the bug occurs only with -O and -O2 (not with -O1 and -O3). So I assume that -O is equivalent to -O2.

AbhishekD_Intel
Moderator
225 Views

Hi,


Thank you for reporting this issue. We are also getting the same incorrect result with -O2 flag whereas we are getting the correct results with O1 and O3 flag as mentioned by you. As it seems a bug to us, we are forwarding this bug to the concerned team. They will get back to you.



Warm Regards,

Abhishek