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. Other Discussions
  3. The Weird and The Wonderful
  4. This Definitely Falls into the Wonderful Camp

This Definitely Falls into the Wonderful Camp

Scheduled Pinned Locked Moved The Weird and The Wonderful
c++csharpcssvisual-studiocom
4 Posts 2 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
    David A Gray
    wrote on last edited by
    #1

    When I saw a cmovne instruction in a disassembly through which I am tracing, I asked Bing what it was, and got the details at [Purpose of cmove instruction in x86 assembly? - Stack Overflow](https://stackoverflow.com/a/56312037/3079037), which are borne out by the demonstrated behavior of my code. It appears that the Visual C++ compiler that ships with Visual Studio 2019 counts the cost of two mov instructions followed by a cmovne instruction as less than that of a branch that causes both to execute anyway, even though the outcome of one of the two mov instructions would eventually be discarded. Moreover, this is happening in a debug build! This is by no means the first such unexpected optimization that I've seen the MSVC compiler generate in a debug build.

    David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

    L 1 Reply Last reply
    0
    • D David A Gray

      When I saw a cmovne instruction in a disassembly through which I am tracing, I asked Bing what it was, and got the details at [Purpose of cmove instruction in x86 assembly? - Stack Overflow](https://stackoverflow.com/a/56312037/3079037), which are borne out by the demonstrated behavior of my code. It appears that the Visual C++ compiler that ships with Visual Studio 2019 counts the cost of two mov instructions followed by a cmovne instruction as less than that of a branch that causes both to execute anyway, even though the outcome of one of the two mov instructions would eventually be discarded. Moreover, this is happening in a debug build! This is by no means the first such unexpected optimization that I've seen the MSVC compiler generate in a debug build.

      David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      David A. Gray wrote:

      It appears that the Visual C++ compiler that ships with Visual Studio 2019 counts the cost of two mov instructions followed by a cmovne instruction as less than that of a branch that causes both

      Keep in mind that due to the speculative execution leaks... the emitted instructions may be avoiding data-dependent branching. Optimization is not as simple as it was ten years ago... Do me a favor and right click on your project settings and navigate to the 'Code Generation' tab and check if /Qspectre is enabled.

      D 1 Reply Last reply
      0
      • L Lost User

        David A. Gray wrote:

        It appears that the Visual C++ compiler that ships with Visual Studio 2019 counts the cost of two mov instructions followed by a cmovne instruction as less than that of a branch that causes both

        Keep in mind that due to the speculative execution leaks... the emitted instructions may be avoiding data-dependent branching. Optimization is not as simple as it was ten years ago... Do me a favor and right click on your project settings and navigate to the 'Code Generation' tab and check if /Qspectre is enabled.

        D Offline
        D Offline
        David A Gray
        wrote on last edited by
        #3

        My take on the whole point of the conditional move instruction is to eliminate speculative execution from the mix by keeping the program flow in a straight line. FWIW, I double-checked, and Spectre mitigation is disabled. I suspected it was, because I've never enabled it for any of my projects. What made it stand out was that this was happening in a debug build. Had it been a release build, I would have expected this level of optimization. However, this is the most recent of many such unanticipated, and welcome, optimizations, that I've seen in recent debug builds.

        David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

        L 1 Reply Last reply
        0
        • D David A Gray

          My take on the whole point of the conditional move instruction is to eliminate speculative execution from the mix by keeping the program flow in a straight line. FWIW, I double-checked, and Spectre mitigation is disabled. I suspected it was, because I've never enabled it for any of my projects. What made it stand out was that this was happening in a debug build. Had it been a release build, I would have expected this level of optimization. However, this is the most recent of many such unanticipated, and welcome, optimizations, that I've seen in recent debug builds.

          David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          David A. Gray wrote:

          What made it stand out was that this was happening in a debug build. Had it been a release build, I would have expected this level of optimization. However, this is the most recent of many such unanticipated, and welcome, optimizations, that I've seen in recent debug builds.

          Yeah, it's not a coincidence that the first compiler implementing the /Qspectre mitigations[^] is generating slighty different conditional moves. It's an active area of development. Best Wishes, -David Delaune

          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