Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Q_UNLIKELY and compiler optimization
Forum Updated to NodeBB v4.3 + New Features

Q_UNLIKELY and compiler optimization

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 931 Views 2 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.
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by kshegunov
    #1

    Hello,
    If I put a function call inside Q_UNLIKELY can I be sure that it won't be optimized out? Am I gaining the cache branching reduction one'd expect this way, or it's better to use a variable? E.g.

    if (Q_UNLIKELY(myfunction() != SUCCESS))
         ; // Do stuff
    

    or should I use:

    register int result = myfunction();
    if (Q_UNLIKELY(result != SUCCESS))
         ; // Do stuff
    

    Kind regards.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the value of success ? Depending on it you can use Q_LIKELY but in any case AFAIK, it won't be optimized out.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      kshegunovK 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        What is the value of success ? Depending on it you can use Q_LIKELY but in any case AFAIK, it won't be optimized out.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        @SGaist
        Success is equal to zero. I'm not expecting MPI_Iprobe (the function in question) to ever return an error, unless something is very wrong with a node. However the constant is external to my application and while it's value probably won't change I can't be certain of it.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's the kind of constant that shouldn't change. Usually success = 0 and anything else (usually below 0) is an error code. Sometimes a positive number can be an information like the size of something.

          I'd go for the first version of your if in case you have doubts that SUCCESS might change

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved