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

  • SEARCH
  • Home
  • 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 7728899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:50:02+00:00 2026-06-01T05:50:02+00:00

I am designing a series of Vector classes in C++ that support SSE(SIMD). The

  • 0

I am designing a series of Vector classes in C++ that support SSE(SIMD). The operators have been overloaded for convenience. Example of class:

class vector2 {
public:
//...code
friend const vector2 operator+ (const vector2 & lhs, const vector2 & rhs);
//...code
protected:
float x, y;
};

So far the method checks to see if the CPU has a SSE(SIMD) feature, using a class I created called PROCESSOR, which does this check when the program is executed at run-time. Example of method:

const vector2 operator+ (const vector2 & lhs, const vector2 & rhs) {
vector2 temp;
if(PROCESSOR.SSE) {
_asm { //... The "SSE WAY"
}
} else {
// The "NORMAL WAY"
}
return temp;
}

So as you can see if SSE is available it will run the “SSE” way otherwise it will run “normal” way. However, it is very in-efficient having to check if SSE is available every time this operation is called. Is there a way to implement two versions of a method and call only the appropriate method? Since my PROCESSOR class only does the SSE check once, is there a way of setting my vector class can do the same?

  • 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-06-01T05:50:03+00:00Added an answer on June 1, 2026 at 5:50 am

    To help you avoid code duplication you can create two vector classes, one for SSE and one for non-SSE. Then you can template your calling algorithms.

    class vector_base { float x,y; } ;
    class vector_sse : public vector_base { vector_sse operator+(...){...} };
    class vector_nonsse : public vector_base { vector_nonsse operator+(...){...} };
    
    template< typename VECTOR >
    void do_somthing() {
       for( /*lots*/) {
         VECTOR v = ...;
         VECTOR w = ...;
         foo(v+w);
       }
    }
    
    int main() {
       if(PROCESSOR.SSE)  { do_something<vector_sse>(); }
       else { do_something<vector_nonsse>(); }
    }
    

    If you’re likely to use other classes than vector (like matrix etc) in an SSE manner you might do better by tagging your types instead .. in which case the code looks like this:

    class vector_base { float x,y; } ;
    struct SSE_tag;
    struct NONSSE_tag;
    
    template<typename T>
    class vector;
    
    template<>
    class vector<SSE_tag> : public vector_base { vector_sse operator+(...){...} };
    
    template<>
    class vector<NONSSE_tag> : public vector_base { vector_nonsse operator+(...){...} };
    
    template< typename TAG >
    void do_somthing() {
       for( /*lots*/) {
         vector<TAG> v = ...;
         vector<TAG> w = ...;
         matrix<TAG> m = ...;
         foo(v+(m*w));
       }
    }
    
    int main() {
       if(PROCESSOR.SSE)  { do_something<SSE_tag>(); }
       else { do_something<NONSSE_tag>(); }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm designing an application that receives information from roughly 100k sensors that measure time-series
I'm designing a system that will write time series data to a file. The
One of the struggles I have as android development newbie is that my classes
I am designing a simple internal framework for handling time series data. Given that
designing a pushdown automata for the language a^n b c^n+2, n>0 I have been
I set about designing my own class to hold a series of radio buttons.
Designing forms has always been fun, but getting them to send email on the
When designing a C API for configuring a library/utility, I have a co-worker who
Our organisation uses inline sql. We have been tasked with providing a suitable data
Working in Flex 3, I have a series of components being rendered on a

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.