Is SSE the best way to set case to 0.0 and 1.0?

I am using sse math vector3.

Typically, I set the fourth digit of my vector to 1.0f, as this does most of my math work, but sometimes I need to set it to 0.0f.

So I want to change something like: (32,4f, 21,2f, -4,0f, 1,0f) to (32,4f, 21,2f, -4,0f, 0,0f)

I was wondering what is the best way to do this:

  • Convert to 4 floats, set the 4th float, send back to SSE
  • xor register with itself, then do 2 shufps
  • Do all the SSE math with 1.0f, and then set the variables to what they should be when you're done.
  • Other?

Note: the vector is already in the SSE register when I need to change it.

+3
source share
5

, xmm0:

; xmm0 = [x y z w]
xorps %xmm1, %xmm1         ; [0 0 0 0]
pcmpeqs %xmm2, %xmm2       ; [1 1 1 1] 
movss %xmm1, %xmm2         ; [0 1 1 1]
pshufd $0x20, %xmm1, %xmm2 ; [1 1 1 0]
andps %xmm2, %xmm0         ; [x y z 0]

, .

+4

.

...

myMask:
.long 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000

...
andps  myMask, %xmm#

# = {0, 1, 2,....}

, .

+5

, , 1 , . , . 1 , pshufhw xmm0, xmm0, 0xa4 :

(gdb) ni
4       pshufhw $0xa4, %xmm0, %xmm0
(gdb) p $xmm0.v4_float
$4 = {32.4000015, 21.2000008, -4, 1}
(gdb) ni
5       ret
(gdb) p $xmm0.v4_float
$5 = {32.4000015, 21.2000008, -4, 0}

:)

+2
+1

[1 1 1 0]? , SSE .

Then, to return to the vector with 1 in the 4th dimension, simply add [0 0 0 1]. Again, there is an SSE instruction for this.

-1
source

Source: https://habr.com/ru/post/1790059/


All Articles