https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90867

            Bug ID: 90867
           Summary: Multiplication or typecast of integer and double
                    always zero when...
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sven.schm...@gmx-topmail.de
  Target Milestone: ---

Created attachment 46485
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46485&action=edit
Compiler output text

A multiplication of integer with double or a typecast of integer to double is
always zero when compiling with -march=native and the function is defined
"GENERIC" with "__attribute__ ((target ("arch=x86-64")))" or any other arch.

The bug occurs an all gcc 64-bit (x86-64) for Linux since gcc-6 I've tested.
Not affected is gcc 32-bit (i386) or other systems like gcc for mingw.

-----
#include <stdint.h>
#include <stdio.h>

/*
 * no opcode optimization allowed
 */
#if __i386__
# define GENERIC        __attribute__ ((target ("arch=i386")))
#else
# define GENERIC        __attribute__ ((target ("arch=x86-64")))
#endif

uint64_t freq = 3600000000UL;   /* 3.6 GHz = 3600.0 MHz */

GENERIC int main (void)
{
  printf("freq = %f Hz\n", (double)freq);
  printf("freq = %f kHz\n", 1e-3 * freq);
  printf("freq = %f MHz\n", 1e-6 * freq);
  printf("freq = %f GHz\n", 1e-9 * freq);

  return 0;
}
-----

Compile with: gcc -v -save-temps -Wall -Wextra -march=native test.c -o test

Result when running is:
-----
freq = 0.000000 Hz
freq = 0.000000 kHz
freq = 0.000000 MHz
freq = 0.000000 GHz
-----

Compiling same code with -m32... 

  gcc -m32 -v -save-temps -Wall -Wextra -march=native test.c -o test

...gives expected results:

-----
freq = 3600000000.000000 Hz
freq = 3600000.000000 kHz
freq = 3600.000000 MHz
freq = 3.600000 GHz
-----

gcc --version: gcc (Debian 8.3.0-6) 8.3.0

gcc compiles assembler code for the old FPU and there is a bug in machine code.
When compiling same code without architecture restrictions assembler code is
build for SSE unit without bug. 

Compiler output file is appended.

Best regards
Sven

Reply via email to