C++ Logo


Advanced search

Re: [std-proposals] SIMD by just operating on 2 arrays

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Wed, 12 Apr 2023 16:50:16 +0200
On 12/04/2023 16:30, samuel ammonius via Std-Proposals wrote:
> Using SIMD for addition performs the exact same process but with lists
> of numbers instead of single ones, so why not just do this:
> float a[4] = {1.0f, 5.0f, 0.0f, 0.005f};
> float b[4] = {0.0f, 1000.0f, 0.0f, 9.0f};
> float c[4] = a + b; // SIMD
> Common SIMD-operable types - like lists of 2, 4, or 8 floats or ints -
> could be operated together like this, and other types could just produce
> a syntax error like "This array type cannot be operated on".

What if my platform doesn't have SIMD?

In general, is writing std::fixed_simd<float, 4> instead of float[4] in
the above so bad that it warrants such a language change?

> Does anyone think this might be a good idea? The only issue I can see is
> that people may be misled into thinking this concatenates the arrays.

It's also a "language API break" (?) -- at the moment, `a - b` actually
compiles and yields ptrdiff_t, not float[4]. (But if you actually
evaluate it, it's UB https://eel.is/c++draft/expr#add-5.3 .)

Giuseppe D'Angelo

Received on 2023-04-12 14:50:20