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. Floating point assembler code [modified]

Floating point assembler code [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutoriallearning
3 Posts 3 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.
  • T Offline
    T Offline
    Tomerland
    wrote on last edited by
    #1

    Dear gurus, I detected a runtime-bottleneck in my code at the following line

    pY[j] = d1 * pY[j] + d2 * pX[j];

    . All variables are floating point. This line is excecuted millions of times. Now I think about improving runtime by using inline-assembler. Can somebody give me a hint how to start in the best way (e.g. using a library) (by the way: I'm not a beginner at assembler-coding) Kind regards

    modified on Thursday, July 3, 2008 5:16 AM

    R A 2 Replies Last reply
    0
    • T Tomerland

      Dear gurus, I detected a runtime-bottleneck in my code at the following line

      pY[j] = d1 * pY[j] + d2 * pX[j];

      . All variables are floating point. This line is excecuted millions of times. Now I think about improving runtime by using inline-assembler. Can somebody give me a hint how to start in the best way (e.g. using a library) (by the way: I'm not a beginner at assembler-coding) Kind regards

      modified on Thursday, July 3, 2008 5:16 AM

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      Tomerland wrote:

      All variables are floating point. This line is excecuted millions of times. Now I think about improving runtime by using inline-assembler.

      I would recommend you to not use inline-asm for various reasons, but the primary reason is "there must be a better way". A few things to reflect upon: 1. Floating point instructions are slow. Does it have to be floating points or would integer values suffice? 2. Updating an array of floating points is rarely a "bottleneck" from a data administration point of view. You rarely take time critical actions based upon floating point calculation with e.g. 15-bit exponent and a 64-bit mantissa which is what you have when using long double. If you're doing this from your GUI thread it will become unresponsive and the user will experience the UI as hung, but that's another problem. Is it not possible to calculate the new values of the array in a worker thread and post a message to the GUI thread when the calculation has finished? 3. How about using integers that are multiplied by e.g. 100? When you calculate with the values you have two "decimals", but when you present the value to the user, or store it, you can convert to a floating point value. I used this technique in an embedded system that had no support for floating point values, but I multiplied with 16 instead which was a good enough approximation.

      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      1 Reply Last reply
      0
      • T Tomerland

        Dear gurus, I detected a runtime-bottleneck in my code at the following line

        pY[j] = d1 * pY[j] + d2 * pX[j];

        . All variables are floating point. This line is excecuted millions of times. Now I think about improving runtime by using inline-assembler. Can somebody give me a hint how to start in the best way (e.g. using a library) (by the way: I'm not a beginner at assembler-coding) Kind regards

        modified on Thursday, July 3, 2008 5:16 AM

        A Offline
        A Offline
        Alan Balkany
        wrote on last edited by
        #3

        A few ideas: 1. Since the line is executed millions of times, you may be able to speed it up with loop unrolling http://en.wikipedia.org/wiki/Loop_unrolling[^]. 2. Every time you do pY[j], it requires a multiplication and an addition. If you're processing the array sequentially, it would be faster to start with a pointer to pY[0], then increment it to get the next array element. If you show some more surrounding code, we may be able to see some other optimizations.

        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