C++ Logo

std-proposals

Advanced search

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

From: samuel ammonius <sfammonius_at_[hidden]>
Date: Wed, 12 Apr 2023 15:12:26 -0230
Hi Sebastian,

On Wed, Apr 12, 2023 at 2:11 PM Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hi Samuel,
>
>
>
> what is it exactly you are mainly after?
>
> a) To express vector operations with implicit fallback to a loop
>
> b) To have a nice way to express SIMD code with simple mathematical
> operations
>
> c) To create better interoperation between C-style arrays and SIMD code?
>
> Or strictly a combination of those?
>

It's mainly b) and c). My primary issue was that I thought templates and
classes are overkill for something that is just a CPU instruction. However,
everyone has brought up a ton of great issues so I don't think this idea
would work anymore. But just as a brainstorm, what about a class that
operates on an array like this:

alignas(float) float a[4] = {0.0f, 1.0f, 2.0f, 3.0f};

std::simd4 a_simd = std::simd4(&a);

a_simd += 0.1f; // Adds 0.1 to all elements of "a"

This way arrays can be operated on without breaking compatibility. Does
this sound like a better idea?

Received on 2023-04-12 17:42:39