什么是转换浮动为int x86上的最快方法 [英] What is the fastest way to convert float to int on x86
问题描述
什么是你知道一个浮点数转换为int在x86 CPU上的最快方法。 preferrably在C语言或汇编(可在C直列)以下的任意组合:
What is the fastest way you know to convert a floating-point number to an int on an x86 CPU. Preferrably in C or assembly (that can be in-lined in C) for any combination of the following:
- 32,/ 64/80位浮点 - > 32,/ 64位整数
我正在寻找一些技术,速度比刚才让编译器做到这一点。
I'm looking for some technique that is faster than to just let the compiler do it.
推荐答案
如果你想有一个截断转换或一个舍入之一,在什么precision这要看。默认情况下,当您从浮去诠释三将执行截断转换。有FPU指令做,但它不是一个ANSI C转换和有使用它显著警告(如知道FPU四舍五入状态)。由于回答您的问题是相当复杂的,取决于一些变数,你还没有前pressed,我推荐这篇文章的问题:
It depends on if you want a truncating conversion or a rounding one and at what precision. By default, C will perform a truncating conversion when you go from float to int. There are FPU instructions that do it but it's not an ANSI C conversion and there are significant caveats to using it (such as knowing the FPU rounding state). Since the answer to your problem is quite complex and depends on some variables you haven't expressed, I recommend this article on the issue:
http://www.stereopsis.com/FPU.html
这篇关于什么是转换浮动为int x86上的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!