SSE2: pand xmm3, 31?

General FreeBASIC programming questions.
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 9:31

SSE2 is very nearly an immediate free zone - what a pain.

This is what I would like to do 'pand xmm3, 31' but I am getting 'operand type mismatch for pand'.

I have been at this for a while. Is there a workaround?
srvaldez
Posts: 2650
Joined: Sep 25, 2005 21:54

Re: SSE2: pand xmm3, 31?

Postby srvaldez » Sep 25, 2018 10:06

hello deltarho[1859]
I think you need to move the integer 31 into another xmm register and work with that
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

Re: SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 10:16

@srvaldez

I would love to but we cannot move an immediate into a xmm register. We can use immediates with the shift instructions but very little else that I can see. I have even tried moving an immediate into a x86 and moving that but I cannot get that to work.
srvaldez
Posts: 2650
Joined: Sep 25, 2005 21:54

Re: SSE2: pand xmm3, 31?

Postby srvaldez » Sep 25, 2018 10:37

I am no expert, but I think you need to move from memory

Code: Select all

dim as longint m=123456789, n=31,r
asm
   movq xmm2,[n]
   movq xmm3,[m]
   pand xmm3, xmm2
   movq [r],xmm3
end asm
? r,m and n
sleep
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

Re: SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 10:56

@srvaldez

Yep, that does it. <smile>

I am off topic now but I now need to negate a register.

I have tried this:
pcmpeqd xmm3, xmm3 ' fill xmm3 with 1s
pxor xmm3, xmm2 ' I want xmm3 to be equal to -xmm2

With x86 we have opcodes to do these things. <grrrr>
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

Re: SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 11:16

We need to use memory here as well

Code: Select all

Dim As Longint TempVar = 50
Asm
pcmpeqd xmm1, xmm1 ' fill xmm3 with 1s
movq xmm0, [TempVar]
pxor xmm1, xmm0
movq [TempVar], xmm1
End Asm

Print TempVar

Sleep

Not quite there - I am getting -51.

With x86 we just use NEG.

I will keep at it.
srvaldez
Posts: 2650
Joined: Sep 25, 2005 21:54

Re: SSE2: pand xmm3, 31?

Postby srvaldez » Sep 25, 2018 11:22

you could do this

Code: Select all

dim as longint m=50, r=&hffffffffffffffffLL

asm
   movd xmm2,[r]
   movq xmm3,[m]
   pandn xmm3, xmm2
   movq [r],xmm3
end asm
? r,not m

or this

Code: Select all

dim as longint m=50, r

asm
   pcmpeqd xmm2, xmm2
   movq xmm3,[m]
   pandn xmm3, xmm2
   movq [r],xmm3
end asm
? r,not m
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

Re: SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 11:37

I am getting -51 with both of them.
srvaldez
Posts: 2650
Joined: Sep 25, 2005 21:54

Re: SSE2: pand xmm3, 31?

Postby srvaldez » Sep 25, 2018 11:49

deltarho[1859] wrote:I am getting -51 with both of them.

yes, but that's the same result as the FB integer NOT
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

Re: SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 11:51

I am looking for negate ie 50 becomes -50.

This gives -50

Code: Select all

dim as longint m=50, r, one = 1

asm
   pcmpeqd xmm2, xmm2
   movq xmm3,[m]
   pandn xmm3, xmm2
   movq xmm4, [one]
   paddq xmm3, xmm4
   movq [r],xmm3
end asm
? r

sleep

The problem with these workarounds to do something which we can do with just one instruction in x86 is that it slows things down to the point where it isn't worth it. <laugh>
jj2007
Posts: 1962
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: SSE2: pand xmm3, 31?

Postby jj2007 » Sep 25, 2018 11:58

Take deb as pseudocode for print eax:

Code: Select all

  movups xmm1, OWORD PTR MyO   ; DWORD 1000, 2000, ...
  xorps xmm0, xmm0  ' set to zero
  psubd xmm0, xmm1
  movd eax, xmm0
  deb 4, "A", eax
  pshufd xmm0, xmm0, 11100001b
  movd eax, xmm0
  deb 4, "B", eax
Note you can do this simple negation for 4 DWORDs.
srvaldez
Posts: 2650
Joined: Sep 25, 2005 21:54

Re: SSE2: pand xmm3, 31?

Postby srvaldez » Sep 25, 2018 11:59

try this, only 32-bits

Code: Select all

dim as long m=50, r

asm
   pcmpeqd xmm2, xmm2
   movd xmm3,[m]
   psignd xmm3,xmm2
   movd [r],xmm3
end asm
? r,(not m)+1
jj2007
Posts: 1962
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: SSE2: pand xmm3, 31?

Postby jj2007 » Sep 25, 2018 12:21

Nice, srvaldez. I had not used PSIGND before, it works fine but is somewhat slower than PSUBD in my tests.
deltarho[1859]
Posts: 2852
Joined: Jan 02, 2017 0:34
Location: UK

Re: SSE2: pand xmm3, 31?

Postby deltarho[1859] » Sep 25, 2018 12:29

Thanks srvaldez - that did it.

I couldn't find psignd in my SSE2 Instruction Set. Looks like it came in with SSE3. I need to look into that - I cannot use something which other folks may not have.

Anyway, the code that I am working on sees the console open and then closes. I hate that - give me a GPF any day. <smile>

Nope: SSSE3 - oh, dear!
jj2007
Posts: 1962
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: SSE2: pand xmm3, 31?

Postby jj2007 » Sep 25, 2018 13:21

deltarho[1859] wrote:Nope: SSSE3 - oh, dear!
You can use psubd, see above, it's SSE2.

Return to “General”

Who is online

Users browsing this forum: No registered users and 9 guests