How to calculate sine values ​​somewhere and then move them to XMM0 in Assembly?

I did the integration task with FPU before, now I'm afraid of SSE.

My main problem was when I used the FPU stack, there was a fsin function that can be used for the number that is on the top of the stack (st0).

Now I want to calculate the sine of all my four numbers in XMM0 or calculate it somewhere else and go to XMM0 . I use the AT & T syntax.

I think the second idea is really possible, but I don’t know how :)

Does anyone know how to do this?

+4
source share
1 answer

Three options:

  • Use the existing library that computes sin in SSE vectors.
  • Write your own sin vector with SSE.
  • Store the vector in memory, use fsin to calculate the sine of each element and load the results. Assuming your stack is 16 byte aligned and has 16 byte space, something like this:

      movaps %xmm0, (%rsp) mov $3, %rcx 0: flds (%rsp,%rcx,4) fsin fstps (%rsp,%rcx,4) sub $1, %rcx jns 0b 

(1) - This is by far your best choice of performance, and also the easiest. If you have significant experience writing vector code and you know a priori that the arguments fall into a certain range, you can get better performance with (2). Using fsin will work, but it's ugly and slow and not particularly accurate if that matters.

+4
source

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


All Articles