NASM Forum > Programming with NASM

What are the SIMD equivalents to x87 transcendental functions?

(1/2) > >>

ben321:
For example, with x87 floating point registers, I can use fpsin to calculate the sine of an angle. Now with 64bit CPUs, the recommendation is to stop using the x87 instructions, and use the SIMD instructions instead, which operate on the XMM registers. But I have a problem. What are the SIMD instructions for transcendental functions like sine? Do they even exist? I can't find any proof of their existence. One thing is certain though, is that even if they exist, I can't find anything on the internet about them.

fredericopissarra:
There are no math instructions other then the four basic arithmetic functions (add, substraction, multiplication and division) with SSE (or almost all SIMD in other processors as well).

This is not a bad thing, since fsin and fcos are very slow (50-120 cycles).

ben321:

--- Quote from: fredericopissarra on December 13, 2023, 06:29:49 PM ---There are no math instructions other then the four basic arithmetic functions (add, substraction, multiplication and division) with SSE (or almost all SIMD in other processors as well).

This is not a bad thing, since fsin and fcos are very slow (50-120 cycles).

--- End quote ---

Then how does Intel expect you to run any useful algorithms (which often require transcendental functions like sine or cosine) with the XMM registers (what they want you to use when in 64bit mode)? You can't do sine and cosine simply by using a combination of add, subtract, multiply, and divide.

Michael Mehlich:
Transcendental functions actually can be computed (i.e. approximated up to an arbitrary desired precision) using only those basic operations; efficient algorithms to do so are not particularly simple though, and are best left to be implemented by experts in that area.  As such, you should probably just use a library that has implementations for these.  A library written (in C) to compute these using SIMD operations can be found at https://sleef.org/.

ben321:

--- Quote from: Michael Mehlich on December 16, 2023, 04:12:48 PM ---Transcendental functions actually can be computed (i.e. approximated up to an arbitrary desired precision) using only those basic operations; efficient algorithms to do so are not particularly simple though, and are best left to be implemented by experts in that area.  As such, you should probably just use a library that has implementations for these.  A library written (in C) to compute these using SIMD operations can be found at https://sleef.org/.

--- End quote ---

If you need to do tons of arithmetic to get it to work though, is it actually any faster than the native x87 fsin and fcos instructions.

Navigation

[0] Message Index

[#] Next page

Go to full version