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 7061459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:28:37+00:00 2026-05-28T04:28:37+00:00

If you are writing some SIMD code that will be run by another program,

  • 0

If you are writing some SIMD code that will be run by another program, is it always favorable to get rid of branching to increase performance? I heard that even doing extra operations just to avoid if/else statements, etc is still much faster.

I ask this because I have some branching that I do that’s basically like this:

//  axis; x=0, y=1, z=2

float p, q;
if (axis == 0)
{
    p = point.y;
    q = point.z;
}
else if (axis == 1)
{
    p = point.x;
    q = point.z;
}
else if (axis == 2)
{
    p = point.x;
    q = point.y;
}

Can I avoid this kind of branching with some clever trick?

  • 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-28T04:28:37+00:00Added an answer on May 28, 2026 at 4:28 am

    Most SIMD architectures have special instructions which let you conditionally select elements based on a mask vector. The mask vector is typically the result of a SIMD compare instruction. So yes, it’s pretty easy to get rid of the kind of branches that you have in your example above.

    Whether you actually need to get rid of any given branch though will depend on various factors such as the predictability of the branch, the nature (statistics) of the data, and how much code is executed conditionally. As a rule of thumb, branchless is good, but as with most rules there are exceptions.

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

Sidebar

Related Questions

I am writing some code and trying to speed it up using SIMD intrinsics
So I was writing some code today that basically looks like this: string returnString
I'm writing a program in C that needs to do some fast math calculations.
I'm writing some python code that's supposed to parse a CSV file. Calculate the
I'm writing some code that does date and time calculations against the current time.
I am writing some BASH shell script that will continuously check a file to
Today while I was writing some code for two methods that shows and hides
I've been writing some code that replaces some existing: while(runEventLoop){ if(select(openSockets, readFDS, writeFDS, errFDS,
I'm writing some code against a C++ API that takes vectors of vectors of
I'm writing some code that needs to work against an array of different database

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.