x86/x64 处理器使用哪些寄存器进行浮点数学运算? [英] Which registers do x86/x64 processors use for floating point math?

查看:40
本文介绍了x86/x64 处理器使用哪些寄存器进行浮点数学运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x86/x64 是否使用 SIMD 寄存器进行高精度浮点运算或专用 FP 寄存器?

我的意思是高精度版本,而不是常规的double精度.

解决方案

FPU 堆栈仍然可用并公开 80 位精度算术,正如@EricPostpischil 指出的那样(不确定处理器是否仍然具有完整的逻辑,或者这部分在硬件级别得到了模拟).它以 long double 类型提供给 GCC 中的开发人员.例如,为方法

生成的程序集

long double f(long double a, long double b){返回 a*b ;}

将是

 fldt 16(%rbp)fldt 32(%rbp)fmulp %st, %st(1)

这个归档电子邮件提供了有用的元素此类数据例如:

<块引用>

long double my_logl(long double x){长双y;__asm__ 易失性("fldln2
""fldl %1
"fyl2x":=t"(y):m"(x));返回 y;}

在没有 SSE、AVX 或其他向量扩展的情况下编译代码时,您的代码可能会使用 80 位 FPU 生成此类指令,并且可能会输出不同的值.下面是一个示例代码来说明:

double epstest(long double a, long double b){长双 y ;y = a + b ;y = y - a ;返回 y ;}#include int main(){双 x = 1.0 ;双 y = 1e-17 ;双 z = x + y ;z = z - x ;printf ("double: %lf + %le - %lf = %le
", x, y, x, z);双 res = epstest (x, y) ;printf ("long double: %lf + %le - %lf = %le
", x, y, x, res);返回 0 ;}

和输出:

double: 1.000000 + 1.000000e-17 - 1.000000 = 0.000000e+00长双:1.000000 + 1.000000e-17 - 1.000000 = 9.974660e-18

在 x86_64 的软件中实现了更高的精度(超出 long double).

Does x86/x64 use SIMD register for high precision floating point operations or dedicated FP registers?

I mean the high precision version, not regular double precision.

解决方案

The FPU stack is still available and exposes a 80-bits precision arithmetic as @EricPostpischil points out (not sure though if the processor still has the full logic or if this part got emulated at hardware level). It is made available to the developper in GCC with the long double type. For example, the generated assembly for method

long double f(long double a, long double b)
{
    return a*b ;
}

Will be

    fldt    16(%rbp)
    fldt    32(%rbp)
    fmulp   %st, %st(1)

This archive email provides useful elements for using such data e.g.:

long double my_logl(long double x)
{
  long double y;
  __asm__ volatile(
    "fldln2
"
    "fldl   %1
"
    "fyl2x"
    : "=t" (y) : "m" (x));
  return y;
}

When compiling code without SSE, AVX or other vector extension, your code will likely generate such instructions using the 80bits FPU, and probably will output different values. Here is an example code to illustrate:

double epstest(long double a, long double b)
{
        long double y ;
        y = a + b ;
        y = y - a ;
        return y ;
}

#include <cstdio>

int main()
{
        double x = 1.0 ;
        double y = 1e-17 ;
        double z = x + y ;
        z = z - x ;
        printf ("double: %lf + %le - %lf = %le
",  x, y, x, z);
        double res = epstest (x, y) ;
        printf ("long double: %lf + %le - %lf = %le
",  x, y, x, res);
        return 0 ;
}

And the output:

double: 1.000000 + 1.000000e-17 - 1.000000 = 0.000000e+00
long double: 1.000000 + 1.000000e-17 - 1.000000 = 9.974660e-18

Higher precision (beyond long double) is implemented in software for x86_64.

这篇关于x86/x64 处理器使用哪些寄存器进行浮点数学运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆