0

If I'm correct, there is no native assembly function to calculate -x from a float value x stored in an Xmm register. So, what is the best (i.e., fastest) way to do that?

Of course, I could do 0 - x or -1 * x, but that seems overly laborious. Since a float stores a single "sign" bit, it should be simpler (and more efficient?) to just flip that bit. Is that so? And how would that work?

(If there's an essential difference between single and double precision, please elaborate.)

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
Duke
  • 410
  • 7
  • 15
  • 2
    Both flipping the sign bit and subtracting from zero do the trick, but the behaviour for NaN values differs. – fuz Nov 30 '21 at 20:37
  • 5
    Often XOR of the sign bit is good, but do not overlook the possibility of combing it into operation operations, such as changing a fused-multiply-add into a fused-multiply-subtract. – Eric Postpischil Nov 30 '21 at 21:44
  • There's still the question of efficiency which none of the referenced questions answers. – Duke Dec 02 '21 at 18:53
  • @Duke It does not make much sense to ask about efficiency without context. As Eric said, often it is possible to fuse negating with other operations. – chtz Dec 07 '21 at 16:06

0 Answers0