6

SSE and/or 3D now! have vector instructions, but what do they optimize in practice ? Are 8 bits characters treated 4 by 4 instead of 1 by 1 for example ? Are there optimisation for some arithmetical operations ? Does the word size have any effect (16 bits, 32 bits, 64 bits) ?

Does all compilers use them when they are available ?

Does one really have to understand assembly to use SSE instructions ? Does knowing about electronics and gate logics helps understanding this ?

jokoon
  • 6,207
  • 11
  • 48
  • 85

4 Answers4

6

Background: SSE has both vector and scalar instructions. 3DNow! is dead.

It is uncommon for any compiler to extract a meaningful benefit from vectorization without the programmer's help. With programming effort and experimentation, one can often approach the speed of pure assembly, without actually mentioning any specific vector instructions. See your compiler's vector programming guide for details.

There are a couple portability tradeoffs involved. If you code for GCC's vectorizer, you might be able to work with non-Intel architectures such as PowerPC and ARM, but not other compilers. If you use Intel intrinsics to make your C code more like assembly, then you can use other compilers but not other architectures.

Electronics knowledge will not help you. Learning the available instructions will.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • This doesn't actually answer the question. The OP wants to know what SIMD instructions *do*. :) – jalf Apr 15 '11 at 13:52
  • @jalf: I agree that this isn't the best answer. I wanted to focus more on "Does one really have to understand assembly to use SSE instructions?" — he does seem to already have a grasp of what it's for. – Potatoswatter Apr 15 '11 at 15:12
  • Maybe we're reading it differently. His question about "8 bit chars being treated 4 by 4" seems to indicate a misunderstanding of how they work (as in, it splits up a single value across multiple execution units, in order to update that one value more efficiently, rather than processing multiple values in parallel) – jalf Apr 15 '11 at 15:33
  • @jalf: Dunno. Fortunately, we both answered :v) . If I could give you another upvote, I would. – Potatoswatter Apr 15 '11 at 15:53
4

In the general case, you can't rely on compilers to use vectorized instructions at all. Some do (Intel's C++ compiler does a reasonable job of it in many simple cases, and GCC attempts to do so too, with mixed success)

But the idea is simply to apply the same operation to 4 32-bit words (or 2 64 bit values in some cases).

So instead of the traditional `add´ instruction which adds together the values from 2 different 32-bit wide registers, you can use a vectorized add, which uses special, 128-bit wide registers containing four 32-bit values, and adds them together as a single operation.

jalf
  • 243,077
  • 51
  • 345
  • 550
2

Duplicate of other questions: Using SSE instructions

In short, SSE is short for Streaming SIMD Extensions, where SIMD = Single Instruction, Multiple Data. This is useful for performing a single mathematical or logical operation on many values at once, as is typically done for matrix or vector math operations.

The compiler can target this instruction set as part of it's optimizations (research your /O options), however you typically have to restructure code and either code SSE manually, or use a library like Intel Performance Primitives to really take advantage of it.

Community
  • 1
  • 1
holtavolt
  • 4,378
  • 1
  • 26
  • 40
0

If you know what you are doing, you might get a huge performance boost. See for example here, where this guy improved the performances of his algorithm 6 times.

BЈовић
  • 62,405
  • 41
  • 173
  • 273