[Bug c/90867] New: Multiplication or typecast of integer and double always zero when...

2019-06-13 Thread sven.schm...@gmx-topmail.de
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 
#include 

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

uint64_t freq = 36UL;   /* 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.00 Hz
freq = 0.00 kHz
freq = 0.00 MHz
freq = 0.00 GHz
-

Compiling same code with -m32... 

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

...gives expected results:

-
freq = 36.00 Hz
freq = 360.00 kHz
freq = 3600.00 MHz
freq = 3.60 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

[Bug c/90867] Multiplication or typecast of integer and double always zero when...

2019-06-13 Thread sven.schm...@gmx-topmail.de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90867

--- Comment #1 from Sven Schmidt  ---
Created attachment 46486
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46486&action=edit
Assembler output