Here is the brief summarized debate of whether SIMD vectors should have operator==
return a SIMD vector or a boolean
operator==
Should Returns a SIMD Vector Camp
- That’s what state-of-arts C++ libraries do
- It’s what people want for the most of times
- If returning a
bool
, it is not clear what the semantics is (all? at least one?) - Boolean returning simd vector
operator==
can be misuse- e.g.
std::simd x, y, z; auto result = (x == y) * z; /* spreading here */
- e.g.
- Generic code that works both on scalars and vectors need
operator==
returning vector
operator==
Should Returns a Bool Camp
- regular types’
operator==
returnbool
- Returning a vector can break generic code which expect
operator==
to returnbool
- Returning a vector can break generic code which expect
- Rust’s std::simd does that
- Lesley: this is related to how Rust’s equality is implemented (Eq trait), so in C++ the situation is different
Third Option: operator==
Should not Exist
That’s my take. And it seems to solve a large numbers of concerns above
Cons
- Can’t easily take advantage of generic code (both the above two options do it somewhat)
- using explicit functions looks quite ugly for basic math stuff
Fourth Option: Implicitly Convert a simd<bool>
to bool
IMO just horrible