Operators for mixed scalar-vector operations.

Issue #25 resolved
edanor repo owner created an issue

Currently only vec<->vec operations are permitted using overloaded C++ operators. Writing:

SIMD4_32f a, b, c;
c = a + b;

Is permitted, while:

SIMD4_32f a, b, c;
float d, e;
c = a + b; // OK
c = a + d; // Error: no implicit conversion between float and SIMD4_32f
c = e + b; // Error: no operator matching: 'operator+ (float, SIMD4_32f &)' 

This requires actually adding two overloads for every operator: one for RHS scalar types can be defined as member function of SIMD types:

VEC_TYPE operator+(VEC_TYPE const & a, SCALAR_TYPE b) const;   

and second one for LHS scalars as friend functions:

VEC_TYPE operator+(SCALAR_TYPE b, VEC_TYPE const & b) const;

Because of potential collisions with operators overloaded in std::, this cannot be done using templates, and thus requires explicit specialization of all scalar and SIMD types combinations.

Comments (2)

  1. edanor reporter

    Commit: 82aa3d4

    Added structure for overloaded scalar<->vec operators. Majority of operators already defined. Updated plugins correspondingly.

    Still missing:
    - '<<', '>>', '<<=', '>>=' operators
    - '%', '%=' operators (also missing corresponding interface functions)

  2. Log in to comment