快速上浮到INT的转换和浮点precision基于ARM(iPhone 3GS的/ 4) [英] Fast float to int conversion and floating point precision on ARM (iPhone 3GS/4)
问题描述
我读( http://www.stereopsis.com/FPU.html )中(<一提到href=\"http://stackoverflow.com/questions/78619/what-is-the-fastest-way-to-convert-float-to-int-on-x86\">http://stackoverflow.com/questions/78619/what-is-the-fastest-way-to-convert-float-to-int-on-x86).有谁知道,如果慢投简单(见下面的代码段)不适用于ARM架构,也?
I read (http://www.stereopsis.com/FPU.html) mentioned in (http://stackoverflow.com/questions/78619/what-is-the-fastest-way-to-convert-float-to-int-on-x86). Does anyone know if the slow simple cast (see snippet below) does apply to ARM architecture, too?
inline int Convert(float x)
{
int i = (int) x;
return i;
}
要申请,你必须设置浮点运算的precision FPU的文章中提到的一些技巧。我该怎么做,关于ARM?
To apply some tricks mentioned in the FPU article you have to set the precision for floating point operations. How do I do that on ARM?
什么是最快的浮子INT转换ARM架构?
What is the fastest float to int conversion on ARM architecture?
谢谢!
推荐答案
短版,不。
这文章是古代甚至不适用于现代的x86系统,更不用说ARM。一个简单的强制转换为整数相当快上的ARMv7(iPhone 3GS的/ 4),虽然有一个不起眼的摊位从VFP / NEON移动数据寄存器的通用寄存器。然而,鉴于你的浮动
数据可能是从VFP / NEON寄存器完成的计算来了,你将不得不支付这一举动不管你怎么做转换。
That article is ancient and doesn't even apply to modern x86 systems, let alone ARM. A simple cast to integer is reasonably fast on ARMv7 (iPhone 3GS/4), though there is a modest stall moving data from the VFP/NEON registers to the general purpose registers. However, given that your float
data is probably coming from a computation done in VFP/NEON registers, you will have to pay for that move no matter how you do the conversion.
我不认为这是一个最优化路径获利,除非你有痕迹显示,这是你的程序的一大瓶颈。即使这样,最快的转换是你不做转换;你几乎总是会更好发现算法的方式从你的程序消除转换。
I don't think that this is a profitable path for optimization unless you have traces showing that this is a major bottleneck for your program. Even then, the fastest conversion is the conversion you don't do; you will almost always be better off finding algorithmic ways to eliminate conversions from your program.
如果你的真正的需要优化的转换,寻找到 vcvt.i32.f32
指令,它转换的两个或四个矢量浮点数为两个或四个整数的的载体,而不的移动数据出来的NEON寄存器(因此,不会引起我提到的失速)。当然,你需要做的NEON单元对你以后的整数计算为这是一个有利可图的优化。
If you do genuinely need to optimize conversions, look into the vcvt.i32.f32
instruction, which converts a vector of two or four floating point numbers to a vector of two or four integers without moving the data out of the NEON registers (and therefore, without incurring the stall that I mentioned). Of course, you will need to do your subsequent integer computations on the NEON unit for this to be a profitable optimization.
问:什么是你的真正的意欲何为?为什么你认为你需要一个更快的引脚悬空> INT转换?
Question: What are you really trying to do? Why do you think you need a faster float->int conversion?
这篇关于快速上浮到INT的转换和浮点precision基于ARM(iPhone 3GS的/ 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!