Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to negate a double in the SSE2 registers

830 views
Skip to first unread message

jacob navia

unread,
Oct 30, 2001, 9:18:17 PM10/30/01
to
Hi
I am writing a new back end for my compiler system lcc-win32.
Suppose that a user dares to write:

double x = 3.14159;
x = -x;

How can I negate a number in an xmm register?

I put x in an SSE register using the low 64 bits. I have just to toggle bit
63 obviously.
I wouldn't want to use a general register (eax-edx), since they are in
scarce supply.

I can't use the FPU FCHS instruction, that does that, since there is no path
from the SSE registers to the FPU.

The code I use now does it by substracting from zero:

subl $8,%esp ; Make place in the stack
movlpd %xmm0,(%esp) ; Move the number to the stack
xorpd %xmm0,%xmm0 ; Clear the register to zero
subsd (%esp),%xmm0 ; substract the number in stack from zero
addl $8,%esp ; adjust the stack

This looks horrible to me. Too much for such a simple operation!

Does anyone here have a better idea?

Thanks in advance.

igor...@nospicedham.gmail.com

unread,
Mar 28, 2015, 10:01:12 PM3/28/15
to
Dne sreda, 31. oktober 2001 04.02.49 UTC+1 je oseba jacob navia napisala:
Define Int64 constant of value $8000000000000000 (like int64 C_SIGN = $80..0.), load it into xmm reg (like movq xmm1, C_SIGN, then pxor %xmm0,xmm1

This would flip the sign bit. POR would set any double value to a negative one - like x= -abs(x)

PAND with the value $7FFFFFFFFFFFFFFF would act as x=abs(x).

I.

Terje Mathisen

unread,
Mar 29, 2015, 2:31:38 AM3/29/15
to
That is the right way to do it. :-)

In my own code I define 128-bit constants for each type of sign
set/clear/flip I will need, then use them directly without loading into
a register first.

Terje



--
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"
0 new messages