C++ Logo

std-proposals

Advanced search

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

From: samuel ammonius <sfammonius_at_[hidden]>
Date: Wed, 12 Apr 2023 12:00:04 -0230
I know there's already an std::experimental solution in place for SIMD, but
I think there's a better way to go about this.

When you add 2 variables together in C, the generated assembly basically
says:

    1. Put the first number into register A
    2. Put the second number into register B
    3. Calculate the result into register C
    4. Copy register C to the desired memory location

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".

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.

Received on 2023-04-12 14:30:17