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

前端 未结 10 2228
轻奢々
轻奢々 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:59

    If you can guarantee the CPU running your code is SSE3 compatible (even Pentium 5 is, JBB), you can allow the compiler to use its FISTTP instruction (i.e. -msse3 for gcc). It seems to do the thing like it should always have been done:

    http://software.intel.com/en-us/articles/how-to-implement-the-fisttp-streaming-simd-extensions-3-instruction/

    Note that FISTTP is different from FISTP (that has its problems, causing the slowness). It comes as part of SSE3 but is actually (the only) X87-side refinement.

    Other then X86 CPU's would probably do the conversion just fine, anyways. :)

    Processors with SSE3 support

提交回复
热议问题