linux - 为什么不出现浮点异常?

标签 linux assembly x86-64 fpu sigfpe

我正在学习 float 的算术。我写了下面的代码。但不会发生浮点异常。我的环境是 Cent OS 6.4 (x86_64)。

请教我这个道理。

#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;
}

最佳答案

可能是因为默认情况下 x86_64 架构使用 SSE2 而不是 x87 进行浮点运算。 (statusword属于x87)

使用 -S 编译并检查生成的汇编器是否真的是 x87。

this 中搜索 MXCSR链接

关于linux - 为什么不出现浮点异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936237/

相关文章:

c - 映射: Cannot allocate memory

java - IJVM ILOAD 指令未加载正确的值

installation - 安装程序根据 CPU 架构(x86 32 位、x64 64 位等)选择 MSI

C HTTP 流媒体服务器流式传输音频分贝级别

PHP FileToUpload 未定义索引错误

assembly - 何时在 MIPS 汇编语言中使用临时寄存器和保存寄存器?

rust - Rust 的 128 位整数 `i128` 如何在 64 位系统上工作?

linux-kernel - 通过 NUMA 环回优化套接字数据传输

PHP脚本修改Ubuntu用户密码

windows - 带有 User32.dll 的 LoadLibraryA 在 ntdll.dll(x64 程序集)中崩溃