Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

SSE4 added FRNDINT (x87) and ROUNDSS/SD (xmm) to do this task purely on hardware.

Further, if one is seriously determined, there are ways to perform bitwise on floating-point registers directly. On XMM, it's trivial: just take advantage of the integer (and non-integer, e.g. XORAPS) instruction available.

On x87, one can take advantage of the direct mapping between MMX and x87 registers to manipulate them using MMX's integer instructions. This has problems, but as I said -- seriously determined.



On modern x86 hardware, integer instructions that act on float values in xmm registers (and vice versa) require a somewhat expensive change of execution domain. That the register names are the same is irrelevant: everything will be renamed into what the CPU works with internally (which is separate integer and floating point domains).

Mixing integer mmx and x87 is even worse, with the crazy emms junk. Not worth it.


The penalty is at most ~1 cycle of latency -- in practice I find it gets completely absorbed by the OOE engine. I've never measured any significant penalty in any code for mixing float and int SSE operations on any x86 microarchitecture.

Floating point bitwise operations exist too: xorps, andps, and so on.


Hmm, ok. Intel recommend avoiding it pretty strongly: I guess they overstate their case. One cycle in (and one out?) isn't exactly crushing.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: