Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6355267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:43:50+00:00 2026-05-24T22:43:50+00:00

For a typical modern compiler on modern hardware, will the ? : operator result

  • 0

For a typical modern compiler on modern hardware, will the ? : operator result in a branch that affects the instruction pipeline?

In other words which is faster, calling both cases to avoid a possible branch:

bool testVar = someValue(); // Used later.
purge(white);
purge(black);

or picking the one actually needed to be purged and only doing it with an operator ?::

bool testVar = someValue();
purge(testVar ? white : black);

I realize you have no idea how long purge() will take, but I’m just asking a general question here about whether I would ever want to call purge() twice to avoid a possible branch in the code.

I realize this is a very tiny optimization and may make no real difference, but would still like to know. I expect the ?: does not result in branching, but want to make sure my understanding is correct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:43:51+00:00Added an answer on May 24, 2026 at 10:43 pm

    The CMOV (Conditional MOVe) instruction has been part of the x86 instruction set since the Pentium Pro. It is rarely automatically generated by GCC because of compiler options commonly used and restrictions placed by the C language. A SETCC/CMOV sequence can be inserted by inline assembly in your C program. This should only be done is cases where the conditional variable is a randomly oscillating value in the inner loop (millions of executions) of a program. In non-oscillating cases and in cases of simple patterns of oscillation, modern processors can predict branches with a very high degree of accuracy. In 2007, Linus Torvalds suggested here to avoid use of CMOV in most situations.

    Intel describes the conditional move in the Intel(R) Architecture Software Developer’s Manual, Volume 2: Instruction Set Reference Manual:

    The CMOVcc instructions check the state of one or more of the status
    flags in the EFLAGS register (CF, OF, PF, SF, and ZF) and perform a
    move operation if the flags are in a specified state (or condition). A
    condition code (cc) is associated with each instruction to indicate
    the condition being tested for. If the condition is not satisfied, a
    move is not performed and execution continues with the instruction
    following the CMOVcc instruction.

    These instructions can move a 16- or 32-bit value from memory to a
    general-purpose register or from one general-purpose register to
    another. Conditional moves of 8-bit register operands are not
    supported.

    The conditions for each CMOVcc mnemonic is given in the description
    column of the above table. The terms “less” and “greater” are used for
    comparisons of signed integers and the terms “above” and “below” are
    used for unsigned integers.

    Because a particular state of the status flags can sometimes be
    interpreted in two ways, two mnemonics are defined for some opcodes.
    For example, the CMOVA (conditional move if above) instruction and the
    CMOVNBE (conditional move if not below or equal) instruction are
    alternate mnemonics for the opcode 0F 47H.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
During a typical day programming, I implement functions in a way that I would
A typical forward iterator is expected to implement following methods: value_type& operator*(); value_type* operator->();
Typical scenario: a class that a lot of people have worked on. I'd like
In typical web design fashion, there's always something that doesn't look quite right between
In typical Persian fonts which are True Type, there is a historical problem with
The typical build targets for make and other build systems is a file or
Given a typical function that takes a C-Functionpointer as a callback like C-Stdlib qsort()
A typical CSS property that I use often is overflow-x or overflow-y . Sometimes
Typical scenario, post to an action that checks ModelState.IsValid and if it is, saves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.