Sign in to follow this  
Alundra

standard cos/sin... still needed ?

Recommended Posts

Hi,

Since all computer has SSE2, now, using standard math function (cmath) still needed ?

Is it correct to do all using SSE2 ? AVX is young but now SSE2 is here since a long time.

 

Thanks

Edited by Alundra

Share this post


Link to post
Share on other sites

I think you are making an assumption on how the C library is implemented and what type of code the compiler will generate from it. Your compiler may already be using SSE2 instructions.

Share this post


Link to post
Share on other sites

Hi,

Since all computer has SSE2, now, using standard math function (cmath) still needed ?

Is it correct to do all using SSE2 ? AVX is young but now SSE2 is here since a long time.

Not all CPUs have SSE2. However, you might not be targeting "all CPUs" with your program. Yes, nearly all personal computers have SSE2 support these days, but there's a good number of devices (like cell phones, RPis, etc.) that don't support SSE2. So it depends on what kind of computers you are targeting, and I'm not sure what that is. It's up to you.

 

But of course, the cmath functions, plus your compiler's optimizer, very well might be using SSE2 anyway...

Share this post


Link to post
Share on other sites
<cmath> is a C++ standard header, and its contents have nothing to do with particular instruction sets available in some platforms.

AVX is young but now SSE2 is here since a long time.

Let me guess... are you German? smile.png (SSE2 has been here for a long time). Edited by Álvaro

Share this post


Link to post
Share on other sites

If you're making a game for Windows PCs, you can just assume that the user will have SSE2, and write on your box/manual/website that an SSE2 CPU is required (basically: Pentium 4 or newer).

 

On other platforms, there might be different SIMD instruction sets other than SSE/AVX -- e.g. ARM CPUs have NEON and PPC have AltiVec.

 

However, using on x86/PC, it's not always best to use SSE, because mixing float and SSE code is slow. Within a particular bit of code (e.g. a particle simulation), you either need all of your code to use float, or all of it to use SSE. 

If some of the code is float, and some is SSE, then data needs to be transferred from the SSE registers to the float registers (or vice versa) -- in order to do this, the CPU needs to write the data from one type of register to RAM, then read it from RAM to the other type of register. This can be extremely slow.

Share this post


Link to post
Share on other sites

I was writing some 2d collision code about a month ago, and when testing the collision with objects at around position x = 10,000, the collision was messing up - it was getting me stuck on walls and other objects that would not cause an issue around x = 0.

After a lot of debugging, I had a realization, turned off the SSE optimization and my collision issues disappeared. The collision was done with doubles too. There's definitely a tradeoff when using SSE, and while it may not matter most of the time, sometimes it does.

Share this post


Link to post
Share on other sites
Not all C++ coding is on a Windows PC, and not all programs are games.
Really, the sin and cos functions of cmath are about as relevant now as they ever were. Explicit SIMD replacements for them serve a different purpose.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this