Results 1 to 3 of 3

Thread: Vector representations, SIMD

  1. #1
    Join Date
    Jun 2007
    Posts
    5,612

    Vector representations, SIMD

    I've done some some benchmarks comparing common approaches to doing vector math, particularly in relation to 3D geometry:
    https://github.com/cjameshuff/vectests

    It's a bit messy (various alternate tests/implementations are commented out) and nowhere near comprehensive, but gives some useful results. There's little advantage to using arrays: C++ has little or no overhead for structs/classes, given the right constructors, proper parameter passing by reference, and as long as virtual functions aren't used.

    However, there is an advantage to using the built-in (and non-standard) primitive vector types, even over a vector class using SSE. I haven't looked at the resulting code in detail, but I think this is largely due to the built-in vectors being passed to functions via the SSE registers, while the contents of the vector class have to be loaded into a register before use. And Clang can apparently emit fairly good SSE code for those vectors, though hand optimization using SSE intrinsics can occasionally be a substantial benefit.

    SSE is clearly not designed for doing general vector math, it's designed to do parallel operations on scalars. It's quite weak at "horizontal" operations like adding up the elements of a register, though recent versions have added a few horizontal operations that work on pairs of elements and floating point dot product instructions. It's also hampered by only being 128 bits wide, which means double precision math can only work on 2 doubles at a time. The new AVX instructions do better, doubling the register width to 256 bits...and someday I'll have hardware that can use them.

  2. #2
    Join Date
    Nov 2001
    Posts
    3,251
    Sort of curious, have you performance marked the same with DirextX libraries?

  3. #3
    Join Date
    Jun 2007
    Posts
    5,612
    Quote Originally Posted by dgavin View Post
    Sort of curious, have you performance marked the same with DirextX libraries?
    I don't use DirectX, but a quick search shows it just uses classes. If whatever compiler you're using doesn't have optimizations specifically and exclusively for DirectX vectors, they'll be the same as any other vector classes. With some downsides...they aren't templated, and are only available in single precision floating point, so they can't be used for integer or double precision math, and of course they are Windows-only.

Similar Threads

  1. Product of a vector and its derivative
    By Glom in forum Science and Technology
    Replies: 2
    Last Post: 2011-Oct-28, 06:29 PM
  2. magnetic vector potential
    By AriAstronomer in forum Space/Astronomy Questions and Answers
    Replies: 3
    Last Post: 2010-Nov-18, 07:04 PM
  3. How do solar sails work? Can they go on any vector?
    By WalrusLike in forum Space/Astronomy Questions and Answers
    Replies: 15
    Last Post: 2010-Jul-30, 04:53 AM
  4. What's our Hubble Flow Vector?
    By George in forum Space/Astronomy Questions and Answers
    Replies: 23
    Last Post: 2010-May-27, 02:36 PM
  5. Vector as a tensor.
    By tommac in forum Space/Astronomy Questions and Answers
    Replies: 23
    Last Post: 2008-May-14, 05:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •