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

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

问题描述



我的意思是高精度版本,不是常规 double precision。

解决方案

FPU堆栈仍然可用,公开了80位精度算法正如@EricPostpischil指出的那样(不知道如果处理器仍然有完整的逻辑,或者这个部分是在硬件层面上模拟的话)。 GCC中的开发者可以使用 long double 类型。例如,为方法生成的程序集

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

$ / code>

将会是

<$ ($ rbp)
fldt 32(%rbp)
fmulp%st,%st(1)


  long double my_logl(long double x)
{
long double y;
__asm__ volatile(
fldln2 \\\

fldl%1 \\\

fyl2x
:= t(y): m(x));
return y;




$ p
$ b

当编译没有SSE的代码时,AVX或其他向量扩展,你的代码可能会产生使用80位FPU这样的指令,并可能会输出不同的值。下面是一个示例代码来说明:

  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 \ n,x,y,x,z);
double res = epstest(x,y);
printf(long double:%lf +%le - %lf =%le \ n,x,y,x,res);
返回0;





和输出:

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

更高的精度(超过 long double )在软件中实现对于x86_64。


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\n"
    "fldl   %1\n"
    "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\n",  x, y, x, z);
        double res = epstest (x, y) ;
        printf ("long double: %lf + %le - %lf = %le\n",  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天全站免登陆