向量双双浮点运算 [英] Vector double-double floating point arithmetic

查看:44
本文介绍了向量双双浮点运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存在双精度浮点不够用的工作负载,因此需要四精度.这很少在硬件中提供,因此解决方法是使用 double-double,其中 128 位数字由一对 64 位数字表示.这不是真正的 IEEE-754 四精度 - 一方面,您不会获得任何额外的指数位 - 但在许多用途上已经足够接近,并且比纯软件实现快得多.

There exist workloads for which double precision floating point is not quite adequate, hence a need for quad precision. This is rarely supplied in hardware, so a workaround is to use double-double, where a 128-bit number is represented by a pair of 64-bit numbers. It's not true IEEE-754 quad precision - for one thing you don't get any extra exponent bits - but is for many purposes close enough, and much faster than a pure software implementation.

许多计算机提供向量浮点运算,最好将它们用于双双运算.这可能吗?特别是,在 https 中查看 double-double 的实现://github.com/JuliaMath/DoubleDouble.jl/blob/master/src/DoubleDouble.jl 在我看来,每个算术运算中间至少需要一个条件分支,我认为这意味着 SIMD 向量运算不能使用,除非我遗漏了什么?

Many computers provide vector floating-point operations, and it would be desirable to use these for double-double operations. Is this possible? In particular, looking at an implementation of double-double at https://github.com/JuliaMath/DoubleDouble.jl/blob/master/src/DoubleDouble.jl it seems to me that each arithmetic operation requires at least one conditional branch in the middle, which I think means SIMD vector operations cannot be used, unless I am missing something?

推荐答案

我认为你正在考虑加减法的实现,例如:

I take it you’re thinking of the implementations of addition and subtraction, for example:

# Dekker add2
function +{T}(x::Double{T}, y::Double{T})
    r = x.hi + y.hi
    s = abs(x.hi) > abs(y.hi) ? (((x.hi - r) + y.hi) + y.lo) + x.lo : (((y.hi - r) + x.hi) + x.lo) + y.lo
    Double(r, s)
end

在某些架构上,解决方案可能是使用 SIMD 指令并行计算两个分支,然后执行一个操作来检索两个分支的正确结果.例如,从错误的操作数中减去 x.hi + y.hi 产生的错误结果可能总是带有负号,因此取最大值可能总是提取正确的结果.(此时此刻,我不保证在这种情况下这是有效的,但对于某些操作,一般方法是.)

On some architectures, the solution might be to compute both branches in parallel using SIMD instructions, then perform an operation that will retrieve the correct result of the two. For example, an incorrect result produced by subtracting x.hi + y.hi from the wrong operand might always have a negative sign, so taking the maximum might always extract the correct result. (At this time of night, I won’t guarantee that this is valid in this case, but for some operations, the general approach would be.)

另一个可能是比较向量 {x. y.hi} >{y. x.hi} 以形成位掩码.(这是伪代码,不是 Julia 语法.)位掩码和这对潜在结果的按位 AND 将使正确结果保持不变,并将错误结果的所有位设置为零.然后,使用按位 OR 减少屏蔽向量会产生正确的结果.不需要分支.

Another might be to compare the vector {x. y.hi} > {y. x.hi} in order to form a bitmask. (That’s pseudocode, not Julia syntax.) The bitwise AND of the bitmask and the pair of potential results will leave the correct result intact and set all bits of the incorrect one to zero. Then, reducing the masked vector with bitwise OR yields the correct result. No branch is required.

给定的 ISA 可能有其他可行的技巧,例如条件指令.或者还有除 Dekker 之外的其他算法.

A given ISA might have other tricks that would work, such as conditional instructions. Or there are other algorithms than Dekker’s.

这篇关于向量双双浮点运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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