Author Topic: SIMD module  (Read 688 times)

Camper

  • Regular Member
  • *
  • Posts: 22
SIMD module
« on: June 14, 2017, 03:57:22 AM »
Hi,

I just can't seem to find the right info on how to create a SIMD module. Or elementary Hello function program.

I get things like..
Code: [Select]
movaps 0xffffffe8(%ebp),%xmm0
  8f: 0f 58 45 d8          addps  0xffffffd8(%ebp),%xmm0
  93: 0f 29 45 c8          movaps %xmm0,0xffffffc8(%ebp

But I may as well point to a named variable here?
Code: [Select]
movaps xmm1,var
addps xmm1, xmm7
movaps var, xmm1

Also, what is the right way to create a module? Is there need for a stack frame? Or is it a matter of preloading the registers?
Can I do?
Code: [Select]
proc_name:
 addps xmm1,xmm2
ret

movaps xmm2,var
call    proc_name


Regards,
« Last Edit: June 15, 2017, 11:10:21 PM by Skupje »

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: How to SIMD module
« Reply #1 on: June 14, 2017, 06:05:27 AM »
If using movaps, be sure the data is 16 bit aligned, else use movups.
Not sure what you mean by SIMD module?

If you meant SIMD proc functions, you can do it like this.

Code: [Select]
.data
align 16
var  real4 1.0,2.0,3.0,4.0
var2 real4 10.0,2.0,7.0,6.0

.code

Addfunction proc
    movaps xmm1,var
    movaps xmm7,var2
    addps  xmm1,xmm7
    movaps var,xmm1
    ret
Addfunction endp   

    call Addfunction

;or like this:

Addfunction2 proc
    movaps xmm1,var
    addps  xmm1,var2
    movaps var,xmm1
    ret
Addfunction2 endp

    call Addfunction2

; or this way

Addfunction3 proc uses esi edi Item1:DWORD,Item2:DWORD
    mov     esi,Item1
    mov     edi,Item2
    movaps  xmm0,oword ptr[esi]
    addps   xmm0,oword ptr[edi]
    movaps  oword ptr[esi],xmm0
    ret
Addfunction3 endp   

    invoke  Addfunction3,addr var,addr var2



Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #2 on: June 14, 2017, 10:59:36 PM »
So this creates the stack frame in the background for "Addfunction3"? And using pointers to non SIMD registers?
Code: [Select]
Addfunction3 proc uses esi edi Item1:DWORD,Item2:DWORD
    mov     esi,Item1 
    mov     edi,Item2
    movaps  xmm0,oword ptr[esi]
    addps   xmm0,oword ptr[edi]
    movaps  oword ptr[esi],xmm0
    ret
Addfunction3 endp   

or can I move Item to esi at any time?
Code: [Select]

    mov     esi,Item1 
    mov     edi,Item2
Addfunction3 proc
    movaps  xmm0,oword ptr[esi]
    addps   xmm0,oword ptr[edi]
    movaps  oword ptr[esi],xmm0
 ret
Addfunction3 endp 



« Last Edit: June 15, 2017, 11:15:05 PM by Skupje »

Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #3 on: June 15, 2017, 11:14:52 PM »
Great  8)
« Last Edit: July 25, 2017, 07:14:00 AM by Skupje »

Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #4 on: August 09, 2017, 04:00:31 AM »
Back at it,

So it took me a while to notice it was the integers getting divided into 4 bytes, in conjunction with the align16 instruction.
"Dividing the xmm registers into 16 bytes"

Which made me wonder what  the outcome of an integer movaps instruction on an aligned4 register will be?
Will it be:      int32, int32, int32, int32,
Or will it be:  int32, -       , -       , -      ,


Regards,

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: SIMD module
« Reply #5 on: August 09, 2017, 04:36:55 AM »
movaps must be 16 byte aligned.
you can use movups if unaligned, or movss for a single int32/real4

Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #6 on: August 09, 2017, 07:37:49 AM »
For me it would be movss then..

I was browsing to forum to rediscover the topic that hosted this link, had to dig down in my bookmarks to find it. I think it's brilliant to study SIMD.
http://softpixel.com/~cwright/programming/simd/sse.php

« Last Edit: August 09, 2017, 08:52:45 AM by Skupje »

Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #7 on: August 09, 2017, 09:05:13 AM »
Actually my problem is more complicated,  I have to copy my value into the adjacent variables.

So, does having "Var real8 1, 2 "  mean the values of Var end up in register "xmmx  = 64,64"
by using the movapd instruction alone?

Or do you have to use logic to do it like so,
Code: [Select]
movsd xmm2,int64  ;move int64 into lower quadrant
shufpd xmm1,xmm2,0 ;flip quadrants 0 to 1, move result into 1
movsd xmm1,xmm2 ;move int64 into lower quadrant
« Last Edit: August 10, 2017, 02:05:24 AM by Skupje »

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: SIMD module
« Reply #8 on: August 09, 2017, 10:49:36 PM »
something like this?

paddb   xmm0,xmm1 ; A+B 16*8bit
paddsb   xmm0,xmm1 ; A+B 16*8bit with saturation  {-128...127}
paddusb   xmm0,xmm1 ; A+B 16*8bit with saturation  {0...255}

I'm not exactly sure what you're calculating here.
Maybe if you explain in plain arithmetic what you want to achieve, we can try to solve it with SIMD.

Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #9 on: August 10, 2017, 01:57:21 AM »
I changed my question a bit,  hope its more legible like this.
I have a little VB.net console app compiler going but not really in the position to test this yet.

Siekmanski

  • Member
  • *****
  • Posts: 1110
Re: SIMD module
« Reply #10 on: August 10, 2017, 05:31:36 AM »
Code: [Select]
.data
align 16
Real8A real8 1.0,2.0
Real8B real8 0.0,0.0

.code
movapd xmm0,Real8A ; 1.0,2.0
shufpd xmm0,xmm0,01b ; exchange low 64bit with high 64bit
movapd Real8B,xmm0 ; 2.0,1.0

Camper

  • Regular Member
  • *
  • Posts: 22
Re: SIMD module
« Reply #11 on: August 11, 2017, 02:57:48 AM »
Top!