vgetmantps vs andpd 获取浮点数尾数的说明
vgetmantps vs andpd instructions for getting the mantissa of float
对于skylakex(agner fog的指令表):
+-----------------------+-------------+-------------------+---------------------+----------------+---------+-----------------------+
| Instruction | Operands | µops fused domain | µops unfused domain | µops each port | Latency | Reciprocal throughput |
+-----------------------+-------------+-------------------+---------------------+----------------+---------+-----------------------+
| VGETMANTPS/PD | v,v,v | 1 | 1 | p01/05 | 4 | 0.5-1 |
| AND/ANDN/OR/ XORPS/PD | x,x / y,y,y | 1 | 1 | p015 | 1 | 0.33 |
+-----------------------+-------------+-------------------+---------------------+----------------+---------+-----------------------+
这是否意味着使用位掩码和逻辑并获取浮点数的尾数比使用 vgetmantps 指令更快?
将数字从 float 传输到 int 再返回到 float 的延迟是多少?
为了实现 log(x)
,您想要 尾数和指数为 float
,并且 vgetmantps
/ vgetexpps
是完美的为了它。 . This is what those instructions are for, and do speed up a fast approximation to log(2)
. (Plus it can normalize the significant to -0.5 .. +0.5 instead of 0..1 or other neat ranges to create input for a polynomial approximation to log(x+1)
or whatever. See its docs.)
如果您只想将尾数作为整数,那么确定并去掉其他位,一条指令就完成了。
(但请记住,对于 NaN,尾数是 NaN 有效载荷,因此如果您需要对 NaN 做一些不同的事情,那么您需要检查指数。)
How much is the latency for transferring the number from float to int and back to float?
您已经有了 Agner Fog 的指令 tables (https://agner.org/optimize/)。在 Skylake(SKL 和 SKX)上,VCVT(T) PS2DQ
是 FMA 端口的 4c 延迟,另一个方向也是如此。
或者您是在询问使用像 andps
这样的 FP 指令的输出作为整数指令的输入的旁路延迟吗?
Agner Fog 的 microarch PDF 有一些关于在 vec-int 和 fp 域之间发送数据的绕过延迟的信息,但细节不多。
Skylake 的旁路延迟很奇怪:与以前的 uarche 不同,它取决于指令实际选择的端口。 andps
如果它运行在端口 5 上,则 FP 指令之间没有旁路延迟,但如果它运行在 p0 或 p1 上,则有额外的 1c 延迟。
请参阅 Intel 的优化手册,了解按域+执行端口细分的 table 域交叉延迟。
(更奇怪的是,这种旁路延迟延迟会永远影响该寄存器,即使它已经明确写回物理寄存器并且没有通过旁路网络转发。vpaddd xmm0, xmm1, xmm2
如果任一输入来自 vmulps
,则两个输入都有 2c 延迟。但是一些随机播放和其他指令在任一域中都有效。我已经有一段时间没有尝试过这个了,我没有检查我的笔记,所以这个例子可能不完全正确,但它是这样的。)
(英特尔的优化手册没有提到这种永久效果,它会持续到您用新值覆盖架构寄存器为止。因此在使用整数指令循环之前创建 FP 常量时要小心。)
对于skylakex(agner fog的指令表):
+-----------------------+-------------+-------------------+---------------------+----------------+---------+-----------------------+
| Instruction | Operands | µops fused domain | µops unfused domain | µops each port | Latency | Reciprocal throughput |
+-----------------------+-------------+-------------------+---------------------+----------------+---------+-----------------------+
| VGETMANTPS/PD | v,v,v | 1 | 1 | p01/05 | 4 | 0.5-1 |
| AND/ANDN/OR/ XORPS/PD | x,x / y,y,y | 1 | 1 | p015 | 1 | 0.33 |
+-----------------------+-------------+-------------------+---------------------+----------------+---------+-----------------------+
这是否意味着使用位掩码和逻辑并获取浮点数的尾数比使用 vgetmantps 指令更快?
将数字从 float 传输到 int 再返回到 float 的延迟是多少?
为了实现 log(x)
,您想要 尾数和指数为 float
,并且 vgetmantps
/ vgetexpps
是完美的为了它。 log(2)
. (Plus it can normalize the significant to -0.5 .. +0.5 instead of 0..1 or other neat ranges to create input for a polynomial approximation to log(x+1)
or whatever. See its docs.)
如果您只想将尾数作为整数,那么确定并去掉其他位,一条指令就完成了。
(但请记住,对于 NaN,尾数是 NaN 有效载荷,因此如果您需要对 NaN 做一些不同的事情,那么您需要检查指数。)
How much is the latency for transferring the number from float to int and back to float?
您已经有了 Agner Fog 的指令 tables (https://agner.org/optimize/)。在 Skylake(SKL 和 SKX)上,VCVT(T) PS2DQ
是 FMA 端口的 4c 延迟,另一个方向也是如此。
或者您是在询问使用像 andps
这样的 FP 指令的输出作为整数指令的输入的旁路延迟吗?
Agner Fog 的 microarch PDF 有一些关于在 vec-int 和 fp 域之间发送数据的绕过延迟的信息,但细节不多。
Skylake 的旁路延迟很奇怪:与以前的 uarche 不同,它取决于指令实际选择的端口。 andps
如果它运行在端口 5 上,则 FP 指令之间没有旁路延迟,但如果它运行在 p0 或 p1 上,则有额外的 1c 延迟。
请参阅 Intel 的优化手册,了解按域+执行端口细分的 table 域交叉延迟。
(更奇怪的是,这种旁路延迟延迟会永远影响该寄存器,即使它已经明确写回物理寄存器并且没有通过旁路网络转发。vpaddd xmm0, xmm1, xmm2
如果任一输入来自 vmulps
,则两个输入都有 2c 延迟。但是一些随机播放和其他指令在任一域中都有效。我已经有一段时间没有尝试过这个了,我没有检查我的笔记,所以这个例子可能不完全正确,但它是这样的。)
(英特尔的优化手册没有提到这种永久效果,它会持续到您用新值覆盖架构寄存器为止。因此在使用整数指令循环之前创建 FP 常量时要小心。)