双重实现弹性到FPU舍入模式 [英] double-double implementation resilient to FPU rounding mode

查看:182
本文介绍了双重实现弹性到FPU舍入模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:双重算术



Double-double是数字的表示形式,即两个双精度数字的总和,在有效数字中不重叠。这种表示方法利用现有的双精度硬件实现来实现接近四倍精度的计算。

一个典型的低级C函数在双双实现中可能需要两个双精度数 a b | a | ≥| b | ,然后计算代表它们总和的双数(s,e)

  s = a + b; 
e = b - (s - a);

(改编自这篇文章。)



(s,e)<这些实现通常假定为圆到最接近偶模式。 / code>是仅仅因为这个假设而产生的标准化的双倍。没有它,在向上模式下, a == 0x1.0p60 b == 1 c $ c> s 被计算为 0x1.0000000000001p60 e code> -0x0.0000000000001p60 。他们的总和等于 a b 的数学和,但是他们的有效数字重叠。



a == 0x1.0p120 以及 a 和<$一方面是c $ c> b ,另一方面是 s e 甚至不重合。


问题



有没有办法建立一个类似于double-double的图书馆具有相同的属性,一个典型的双双库在圆到最接近的(即,相对较快和相对准确),但无论圆角模式恰好是什么工作?

这样的库是否已经存在?

更一般的上下文:正确舍入的基本函数



在实现正确舍入初等函数库的过程中,使用双双排序的实现来进行中间计算。因此,以这种方式实现的库倾向于会失败。改变函数内部的舍入模式不是很好,出于性能方面的原因,因为在函数执行时到达的信号会使FPU离开最近偶数模式。我认为最简单的方法是快速,正确地舍入在任何舍入模式下工作的基本函数,如果有人可以依靠在任何舍入模式下工作的双重双重算术。

解决方案

文章由njuffa引用提供了下面的功能,与我的问题非常类似的符号,除了什么是标记 fl(a + b)有简单的表示为 a + b 在我的问题中:

  (a,b)

if(| a | <| b |)
swap(a,b)
s = fl(a + b)$ b如果(| 2 * b | <| d |)
s = a,e = b $ b $,那么$ bd = fl(s - a)
e = fl(b - d) b返回(s,e)

这个特殊的基本计算在一轮 - 向前 - 零模式。有人希望能够实现一个正确的四舍五入的基本函数,至少可以通过尽早测试四舍五入模式并选择单独的算法,或者编写适用于所有舍入模式的非常小心的代码。


Context: double-double arithmetic

"Double-double" is a representation of numbers as the sum of two double-precision numbers without overlap in the significands. This representation takes advantage of existing double-precision hardware implementations for "near quadruple-precision" computations.

One typical low-level C function in a double-double implementation may take two double-precision numbers a and b with |a| ≥ |b| and compute the double-double number (s, e) that represents their sum:

s = a + b;
e = b - (s - a);

(Adapted from this article.)

These implementations typically assume round-to-nearest-even mode.

In the above computation, (s, e) is a normalized double-double only because of this assumption. Without it, with a == 0x1.0p60, b == 1, in round-upward mode, s is computed as 0x1.0000000000001p60 and e a bit above -0x0.0000000000001p60. Their sum is equal to the mathematical sum of a and b but their significands overlap.

Take a == 0x1.0p120 and the mathematical sums of a and b on the one hand and s and e on the other hand do not even coincide any more.

Question

Is there a way to build a double-double-like library with the same properties that a typical double-double library has in round-to-nearest-even (that is, relatively fast and relatively accurate), but that works whatever the rounding mode happens to be?

Does such a library already exist?

More general context: correctly rounded elementary functions

Implementations of the double-double sort are used for intermediate computations in the implementation of libraries of correctly rounded elementary functions. As a result, libraries implemented this way tend to fail spectacularly when a function is called while the FPU is not in round-to-nearest-even mode. Changing the rounding mode inside the function is not very palatable, for performance reasons and because a signal arriving while the function is executing would leave the FPU in round-to-nearest-even mode. The simplest way I see to have fast, correctly rounded elementary functions that work in any rounding mode would be if one could somehow rely on a double-double-kind of arithmetic that worked in any rounding mode.

解决方案

The article referred to by njuffa offers the function below, with very similar notations to those of my question, except that what is denoted fl (a+b) there is simply denoted a+b in my question:

Two−Sum−toward−zero2 (a, b)

if (|a| < |b|)
  swap (a , b)
s = fl (a + b)
d = fl (s − a)
e = fl (b − d)
if(|2 ∗ b|<|d|)
  s = a, e = b
return (s, e)

This is a very neat fix for this particular elementary computation when in round-toward-zero mode. It makes one hope that something would be possible for implementing a correctly rounded elementary function, at the very least by testing the rounding mode early and picking separate algorithms, or perhaps by writing very careful code that works for all rounding modes.

这篇关于双重实现弹性到FPU舍入模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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