What is the fastest way to convert float to int on x86

前端 未结 10 2255
轻奢々
轻奢々 2020-11-28 11:26

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

10条回答
  •  囚心锁ツ
    2020-11-28 11:44

    There is one instruction to convert a floating point to an int in assembly: use the FISTP instruction. It pops the value off the floating-point stack, converts it to an integer, and then stores at at the address specified. I don't think there would be a faster way (unless you use extended instruction sets like MMX or SSE, which I am not familiar with).

    Another instruction, FIST, leaves the value on the FP stack but I'm not sure it works with quad-word sized destinations.

提交回复
热议问题