Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


standard cos/sin... still needed ?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Alundra   Members   -  Reputation: 886

Like
0Likes
Like

Posted 17 February 2013 - 05:25 PM

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, 17 February 2013 - 05:26 PM.


Sponsor:

#2 Chris_F   Members   -  Reputation: 2436

Like
3Likes
Like

Posted 17 February 2013 - 06:01 PM

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.



#3 Cornstalks   Crossbones+   -  Reputation: 6991

Like
3Likes
Like

Posted 17 February 2013 - 06:03 PM

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...


[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#4 Álvaro   Crossbones+   -  Reputation: 13652

Like
1Likes
Like

Posted 17 February 2013 - 06:03 PM

<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, 17 February 2013 - 06:08 PM.


#5 Alundra   Members   -  Reputation: 886

Like
0Likes
Like

Posted 17 February 2013 - 06:54 PM

haha, english is not my natal language, i'm French.

ok, the best is again to check macro to use SSE2 or not.



#6 Hodgman   Moderators   -  Reputation: 30965

Like
2Likes
Like

Posted 17 February 2013 - 07:10 PM

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.



#7 Chris_F   Members   -  Reputation: 2436

Like
0Likes
Like

Posted 17 February 2013 - 07:37 PM

The last time I inspected the assembly output from GCC, it was using SSE/SSE2 instructions exclusively for floating point calculations, even for scalar math.



#8 Milcho   Crossbones+   -  Reputation: 1177

Like
1Likes
Like

Posted 17 February 2013 - 09:21 PM

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.



#9 iMalc   Crossbones+   -  Reputation: 2313

Like
0Likes
Like

Posted 18 February 2013 - 12:50 AM

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.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS