Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Fast square root algorithm and using SSE Intrinsics to boost floating point calculation performance

Fast square root algorithm and using SSE Intrinsics to boost floating point calculation performance

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studioalgorithmsperformance
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    D_code_writer
    wrote on last edited by
    #1

    Hey Guys, I'm working on a simulation project that involves writing a highly accurate vehicle dynamics simulator. I'm writing the project using MFC/C++ and I'm using Visual Studio 2008. I've hit a bit of a block so I figured I would turn to the wisdom contained in this community. 1) I need to use a number of square root calculations. Would anyone happen to know a really fast square root algorithm in Visual Studio 2008 using C/C++. In my case I would be feeding it doubles. 2) I've read quite a bit about SSE Intrinsics, but apart from limited examples I haven't found a good source to say, let's do it this way or this is how you implement it. I've written the numerical engine using double varaibles, so does anyone have some tips about how do I go about converting doubles to the SSE Intrinsics. Many Thanks Danny

    M M R L D 5 Replies Last reply
    0
    • D D_code_writer

      Hey Guys, I'm working on a simulation project that involves writing a highly accurate vehicle dynamics simulator. I'm writing the project using MFC/C++ and I'm using Visual Studio 2008. I've hit a bit of a block so I figured I would turn to the wisdom contained in this community. 1) I need to use a number of square root calculations. Would anyone happen to know a really fast square root algorithm in Visual Studio 2008 using C/C++. In my case I would be feeding it doubles. 2) I've read quite a bit about SSE Intrinsics, but apart from limited examples I haven't found a good source to say, let's do it this way or this is how you implement it. I've written the numerical engine using double varaibles, so does anyone have some tips about how do I go about converting doubles to the SSE Intrinsics. Many Thanks Danny

      M Offline
      M Offline
      Michael Schubert
      wrote on last edited by
      #2

      Have you looked at this[^] article?

      1 Reply Last reply
      0
      • D D_code_writer

        Hey Guys, I'm working on a simulation project that involves writing a highly accurate vehicle dynamics simulator. I'm writing the project using MFC/C++ and I'm using Visual Studio 2008. I've hit a bit of a block so I figured I would turn to the wisdom contained in this community. 1) I need to use a number of square root calculations. Would anyone happen to know a really fast square root algorithm in Visual Studio 2008 using C/C++. In my case I would be feeding it doubles. 2) I've read quite a bit about SSE Intrinsics, but apart from limited examples I haven't found a good source to say, let's do it this way or this is how you implement it. I've written the numerical engine using double varaibles, so does anyone have some tips about how do I go about converting doubles to the SSE Intrinsics. Many Thanks Danny

        M Offline
        M Offline
        molesworth
        wrote on last edited by
        #3

        The best answer to this is to use very strange and dangerous magic, as described here. (This is for floats, but it should be expandable to doubles easily enough.) It's usually attributed to John Carmack, although I don't know if he came up with it, or got it from somewhere else. PS - there's even a Wikipedia article on it!! :)

        There are three kinds of people in the world - those who can count and those who can't...

        1 Reply Last reply
        0
        • D D_code_writer

          Hey Guys, I'm working on a simulation project that involves writing a highly accurate vehicle dynamics simulator. I'm writing the project using MFC/C++ and I'm using Visual Studio 2008. I've hit a bit of a block so I figured I would turn to the wisdom contained in this community. 1) I need to use a number of square root calculations. Would anyone happen to know a really fast square root algorithm in Visual Studio 2008 using C/C++. In my case I would be feeding it doubles. 2) I've read quite a bit about SSE Intrinsics, but apart from limited examples I haven't found a good source to say, let's do it this way or this is how you implement it. I've written the numerical engine using double varaibles, so does anyone have some tips about how do I go about converting doubles to the SSE Intrinsics. Many Thanks Danny

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #4

          One "trick" I have resorted to in the past is to minimize if not remove the use of square roots. There are some calculations where it is unavoidable but in many there are alternatives. For example, in computing distances like for finding closest objects don't compare with the actual distance but use the distance squared because actual distance requires a square root.

          1 Reply Last reply
          0
          • D D_code_writer

            Hey Guys, I'm working on a simulation project that involves writing a highly accurate vehicle dynamics simulator. I'm writing the project using MFC/C++ and I'm using Visual Studio 2008. I've hit a bit of a block so I figured I would turn to the wisdom contained in this community. 1) I need to use a number of square root calculations. Would anyone happen to know a really fast square root algorithm in Visual Studio 2008 using C/C++. In my case I would be feeding it doubles. 2) I've read quite a bit about SSE Intrinsics, but apart from limited examples I haven't found a good source to say, let's do it this way or this is how you implement it. I've written the numerical engine using double varaibles, so does anyone have some tips about how do I go about converting doubles to the SSE Intrinsics. Many Thanks Danny

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Hi, is you application already using MMX/SSE code? is it vectorized at all? if not, it won't make sense to use SSE just to get a square root; you would have to get the data in and out the vector processor, which would forego all the speed gain you might achieve. So just apply regular optimization on doubles. Some of these have already been mentioned: - avoid SQRT; don't use it when it isn't necessary. - use an approximation, if that is acceptable. - for the range of numbers you're interested in, find a fast way (often a polynomial, or something smart, sometimes called "magic"). - if you need SQRT on a series of related numbers, try using each result as the initial estimate for the next. :)

            Luc Pattyn


            Local announcement (Antwerp region): Lange Wapper? Neen!


            1 Reply Last reply
            0
            • D D_code_writer

              Hey Guys, I'm working on a simulation project that involves writing a highly accurate vehicle dynamics simulator. I'm writing the project using MFC/C++ and I'm using Visual Studio 2008. I've hit a bit of a block so I figured I would turn to the wisdom contained in this community. 1) I need to use a number of square root calculations. Would anyone happen to know a really fast square root algorithm in Visual Studio 2008 using C/C++. In my case I would be feeding it doubles. 2) I've read quite a bit about SSE Intrinsics, but apart from limited examples I haven't found a good source to say, let's do it this way or this is how you implement it. I've written the numerical engine using double varaibles, so does anyone have some tips about how do I go about converting doubles to the SSE Intrinsics. Many Thanks Danny

              D Offline
              D Offline
              D_code_writer
              wrote on last edited by
              #6

              Hey Guys, Many thanks for all your help. It has poven very useful. All the Best Danny

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups