linuxassemblyx86-64fpusigfpe

Why floating point exception does not occur?


I'm learning about arithmetic of floating point number. And I wrote following code. But floating point exception does not occur. My environment is Cent OS 6.4 (x86_64).

Please teach me this reason.

#include <stdio.h>

int
main(void)
{
  double a,b,c;
  unsigned short int fctr;

  a=3.0;
  b=0.0;
  c=1.0;

  asm volatile(
    "fstcw %w0" // get FPU control word
    :"=m"(fctr):);
  printf("FPU control word= %X\n", fctr);

  fctr = fctr ^ 0x4;
  printf("FPU control word= %X\n", fctr);

  asm volatile(
    "fldcw %w0"  // set operand to FPU control word
    : :"m"(fctr));

  asm volatile(
    "fstcw %w0" // get FPU control word
    :"=m"(fctr):);
  printf("FPU control word= %X\n", fctr);

  c = a/b;

  return 0;
}

Solution

  • Probably because the x86_64 architecture by default does floating point with SSE2 not x87. (the statusword belongs to x87)

    Compile with -S and check if the generated assembler really is x87.

    Search for MXCSR in this link