Skip to main content
GameDev.net gamedev.net
🔒 Locked

SSE

Started by arm Nov 17, 2004 at 5:32 AM 3 replies 1k views
Original Post
arm
arm
Hi, Just as a guide, whats the smallest dataset you should use when thinking about converting an algorithm to use SIMD? This is assuming that there are about 10 arithmetic operations per element. Cheers, -arm
janos
janos
it can be very small.
It just depends if the data is arranged (arrageable) in a SIMD friendly way, and if the original computation is costly.
Otherwise SSE does not take extra time or state transition time.
In fact, if you look at intel compiler output code, SSE's non vectorial instructions are used instead of x87 code
Act of War - EugenSystems/Atari
Charles B
Charles B
First replace your common vector class by a x,y,z,w everywhere. This trades 25% of memory against a huge speed up. If memory is a problem use array conversion routines.

Next you can use SSE to replace any FPU operations for 3D math. SSE only sucks for dot and cross products, this requires swizzling and accumulations. Still it's at least comparable to FPU code, but you'll gain far more on other functions and avoid float to SSE overheads. So it's better to be in a full SIMD (SSE) context. Also if you use scale a vector by a scalar. The scalar type had better be a 4 x copy of the same value rather than a float.

For instance code exploiting my math lib will look like this :

// You don't gain much here
xScalar dp = A*B; // dot product, in fact { dp, dp, dp, dp }
// But you gain by a factor 4 here.
xVector D = dp*C; // a simple mul_4f (mul_ps)

See the point in being in a full SIMD context ?

Next, as janos evocated, SoA is a significant potential speed up. I would use fast SoA -> AoS and the reverse for vertex lists. For instance you load an AoS, and during several frames you use the SoA format. You can hide this format by making the user believe it's always AoS, through C++ access functions that would intelligently deal with an SoA/AoS flag bit for the same buffer (over allocate and create dummy vectors for data alignment requirements in AoS).
"Coding math tricks in asm is more fun than Java"
superpig
superpig
SoA is the big win. It may be helpful to know that you can convert four AoS-style vectors to four SoA-style vectors using a matrix transpose.

You'll also want to ensure your new 4-element vector class is aligned to a 16-byte boundary.

I'm moving this to General Programming because it's more of an optimization issue than a graphics one.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
Enigma
Enigma
For those unfamilier with the terms AoS and SoA (as I was) they are explained near the bottom of page four in this document.

EDIT: I guess the GDNet forums don't support the tag then!

Enigma

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.