Questions tagged [simd]

Single instruction, multiple data (SIMD) is the concept of having each instruction operate on a small chunk or vector of data elements. CPU vector instruction sets include: x86 SSE and AVX, ARM NEON, and PowerPC AltiVec. To efficiently use SIMD instructions, data needs to be in structure-of-arrays form and should occur in longer streams. Naively "SIMD optimized" code frequently surprises by running slower than the original.

Filter by
Sorted by
Tagged with
1 vote
0 answers
17 views

How to Handle 64-Bit Pointers with 32-Bit Lane Registers in SVE Gather-Load Intrinsics?

SVE offers various gather-load intrinsics. For instance, svuint32_t m = svld1_gather_u32_offset_u32(svbool_t pg, const uint32_t *base, svuint32_t offsets) loads base[i] into each lane i of m. ...
ature's user avatar
  • 11
4 votes
1 answer
74 views

OpenMP SIMD Multi-Reductions (Sum, Min and Max) in Single For Loop

I have the following loop to calculate basic summary statistics (mean, standard deviation, minimum and maximum) in C++, skipping missing values (x is a double vector): int k = 0; long double sum = 0.0,...
Sebastian's user avatar
  • 1,117
-2 votes
0 answers
84 views

Will C# System.Numerics namespace run on AVX-512 in .NET8 or in the near future?

Given all the info on AVX-512 in the .NET8 communication, it seemed logical to me that the C# System.Numerics namespace would be AVX-512 accelerated on servers that support AVX-512 technology. However,...
ForlaneListener's user avatar
0 votes
1 answer
72 views

How to replace nested IF/ELSE branches with SIMD (SSE or AVX)?

EDIT x 2 Added more comprehensive function which returns an abstract register class: the function outputs a register full of floats. I don't care the actual length - SSE, AVX... - because Google ...
stuckoverlow's user avatar
0 votes
0 answers
49 views

static function is used in an inline function with external linkage - while trying to use load instruction inside an inline function

I was working with clang compiler recently for a work of mine. I encountered the following issue which I didn't encounter either with gcc or msvc compiler test_newer.c:8:32: fatal error: static ...
Srihari S's user avatar
-1 votes
0 answers
40 views

SIMD get first true and set everything else to zero

This seems a bit like what I'm after but I only want to use SIMD Intrinsics I'm trying to solve a problem in simd where I have a compare mask but I only care about the first true and all other values ...
confused cmake user's user avatar
0 votes
0 answers
90 views

How to indicate the array length to the c++ compiler

A common reason why code involving character sequences aren't vectorized is demonstrated by the following example. find_a() is a toy function that sets the current_index pointer to the next occurring '...
NoNae's user avatar
  • 331
2 votes
1 answer
73 views

Are C# struct parameters and locals aligned by default?

Assume I have a struct defined like this: [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 1)] readonly struct Example { [FieldOffset(0)] public float A; [FieldOffset(4)] public ...
Xenoprimate's user avatar
  • 7,733
1 vote
3 answers
142 views

x86-64 SIMD mechanism to "compare" 8-bit unsigned integers, giving a vector of +1 / 0 / -1 results (signum)?

Let's say I have two unsigned integer (8-bit) packed registers a and b. I'd like to compare them and get back +1 for a > b, 0 for a=b, or -1 for a < b. Alternatively, distance also works (i.e. ...
Vitali's user avatar
  • 3,463
3 votes
1 answer
101 views

Am I missing a target-feature for AVX512 when I compile my Rust code?

I have written some Rust functions that use AVX2 and AVX512 instructions to speed up image compositing. I am using an AMD 7950x CPU. When I run RUSTFLAGS="-C target-cpu=native" cargo bench I ...
Chris's user avatar
  • 1,525
1 vote
1 answer
124 views

How to overlay images with alpha blending using AVX512 instructions?

I have two images A and B that are stored as byte arrays of ARGB data: Image A: [a0, r0, g0, b0, a1, r1, g1, b1, ...] Image B: [a0, r0, g0, b0, a1, r1, g1, b1, ...] I would like to overlay image B on ...
Chris's user avatar
  • 1,525
0 votes
1 answer
43 views

Correct syntax to leverage SIMD-enabled types in System.Numerics?

Fairly simple question but not so obvious in the end, look at the following example: public void Test(float a, float b, float c, float d) { // not SIMD-enabled since we multiply ourselves? var ...
aybe's user avatar
  • 15.5k
0 votes
1 answer
62 views

Missing byte-granularity masked store in AVX

I am migrating code from SSE to AVX. The code uses _mm_maskmoveu_si128, which conditionally stores 16 bytes based on a mask. The AVX equivalent would be _mm256_maskmoveu_si256 for 32 bytes, but this ...
user avatar
5 votes
0 answers
94 views

Why does the compiler not use SIMD in my range-expression?

I have got two implementations of a dot-product: One hand-coded https://godbolt.org/z/48EEnnY4r int bla2(const std::vector<int>& a, const std::vector<int>& b){ int res = 0; ...
Stein's user avatar
  • 3,179
0 votes
3 answers
80 views

C simd AVX1 m256 horizontal max min normalisation

I figured it out myself, didn't find any answer for avx1 (no avx2). So here is the answer for future persons in search of an answer. 8-float m256 max, then usable for normalisation as _max will be ...
Vadim Kashtanov's user avatar
3 votes
3 answers
120 views

How to decompress bit pairs from uint64_t to __m256i?

Consider uint64_t where each consecutive 2 bits is a number: b00 for 0, b01 for 1, b11 for -1 and b10 is unused (never happens, assume no handling for it). How to decompress such an uint64_t into ...
Serge Rogatch's user avatar
3 votes
2 answers
135 views

How to pack +-1 signs of 8 packed 32-bit integers (in an __m256i) into bytes of a 64-bit integer?

Given an __m256i worth of packed 32-bit signed integers, how to get a single 64-bit number where each byte is 1 if the corresponding 32-bit signed integer from the original __m256i is greater than or ...
Serge Rogatch's user avatar
2 votes
1 answer
121 views

Why are vectorized computations faster on smaller-width integer types?

Why are computations on smaller-width integer arrays faster? And why are computations on 8-bit integer arrays ~4x faster than on 16-bit integer arrays, but on 16-bit integer arrays only ~2x faster ...
Avantgarde's user avatar
2 votes
3 answers
67 views

C simd _m128 fabs

How to make fabs() for __m128 vector ? Does I have to use sign bits to multiply the original vector by 1.0f/-1.0f ? Didn't find any instruction set to do it. I don't want __m256 or 512. I'm searching ...
K V's user avatar
  • 61
0 votes
1 answer
54 views

SIMD _mm_store_si128 | _mm_storeu_si128 don't storing correctly

I have a string const signed char From[] = { 0b00000000, 0b00000001, 0b00000010, 0b00000011, 0b00000100, 0b00000101, 0b00000110, 0b00000111, 0b00001000, 0b00001001, 0b00001010, 0b00001011, ...
faust403's user avatar
1 vote
0 answers
34 views

OpenJDK Vector API type conversion issue (Double to Float)

I'm using JDK21 EA to test the Vector API performance. My original (non-vector) code looks like this: double[] src; double divisor; float[] dst; for (int i=0; i<src.length; ++i) { if (src[i]<=...
Jatinder Sangha's user avatar
1 vote
2 answers
78 views

vectorized & in numpy

My use case is to use numpy for bitmap (that is, set operations using bit encoding). I use numpy arrays with uint64. If I have a query with 3 entries, I can then do bitmap | query !=0 to check if any ...
Guillaume's user avatar
  • 1,277
2 votes
1 answer
88 views

C++: Is there ever a reason to make alignof > sizeof for a type

As indicated in this question, it is possible to have alignment greater than size for a type, you just can't make an array of it. However you can make an array of char[alignof(T)] and reinterpret_cast ...
metamorphosis's user avatar
1 vote
1 answer
78 views

Matrix multiplication using simd produces incorrect results when filled with floating point values [closed]

I wanted to create a matrix multiplication with simd. Everything is fine, when matrix is filled with some integers. But there are some issues when my matrices are filled with floating point values. ...
Arheus's user avatar
  • 21
0 votes
0 answers
49 views

C code with vector instrinsics for Riscv Vector

I have simulated bare-metal General purpose Riscv programs on spike. Now I want to run bare-metal vector program on spike but I think that the C program that will be used to cross compile and generate ...
Syed Hassan Ul Haq's user avatar
1 vote
1 answer
35 views

_mm512_i32scatter_ps when the indices are repeated

What happens when you call _mm512_i32scatter_ps and the indices repeat? Does it store the sum? Does it just store one? Is it UB? I can't seem to find any documentation on this edge case and I don't ...
Grogfrognumber47's user avatar
1 vote
0 answers
61 views

Use AVX-AVX2 instructions in an AVX512 function

For example, we have a CPU with AVX512bw support. Now i want to run 3 types of string-length SIMD functions on this CPU. The first function takes 16 bytes (AVX) of a string and search its characters ...
HelloGUI's user avatar
  • 121
1 vote
0 answers
35 views

GCC error for ""vmull.u16 q7, d19, d8[0]" but not for ""vmull.u16 q7, d19, d7[0]"

I am using Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205 on Windows 11, and on compilation of a sequence of NEON instructions (vector multiplication by scalar): vmull.u16 q7, d19, d0[...
jcdmelo's user avatar
  • 11
0 votes
0 answers
19 views

Why are _mm_packs_epi32 and _mm_unpacklo_epi16 not consistent with the 256-bit versions? [duplicate]

In SIMD, If I have a simple algorithm written for 128-bit vectors like: __m128 add_128(__m128 a, __m128 b) { return _mm_add_ps(a, b); } All I have to do to make this work for 256-bit vectors is ...
aganm's user avatar
  • 1,245
0 votes
0 answers
108 views

asm SIMD sniffer

There is x264. It use a lot of x86 asm files. For example pixel-32.asm. This files can use different SIMD instruction set: mmx, 3DNow!, sse family, others I need the simple way to automatically ...
Андрей Тернити's user avatar
0 votes
0 answers
58 views

Does mixing 4-wide and 8-wide instructions suppose to harm performance that bad?

I have this AVX code that runs much slower than the SSE4 version and I'm trying to figure out why. This smallish loop in SSE4: (asm by gcc 13.1) .L6: movaps xmm1, XMMWORD PTR [rbx+rsi] ...
aganm's user avatar
  • 1,245
0 votes
0 answers
112 views

Is slicing + assign numpy equivalent to a for loop in C?

When we do, with numpy (in Python): my_array[::4] = 0 is it: for (int i = 0; i < my_array_size; i += 4) { my_array[i] = 0; } in C? Or is there SIMD done by numpy? If so, what are actual cases ...
FluidMechanics Potential Flows's user avatar
3 votes
2 answers
106 views

SIMD bit reordering of packed 12-bit integer array

I've got a large tightly packed array of 12-bit integers in the following repeating bit-packing pattern: (where n in An/Bn represents bit number and A and B are the first two 12-bit integers in the ...
Russell Newman's user avatar
3 votes
1 answer
82 views

Idiomatic way to set simd lanes to 0 based on mask?

New to using rust’s std::simd library, and I’ve found myself encountering this scenario: I have a mask8x8 and a u8x8, and I want to set each lane in the u8x8 to 0 if the corresponding mask is false; ...
Jam's user avatar
  • 476
0 votes
0 answers
66 views

What are the differences between `ld1`/`st1` and `ldr`/`str`, `ldp`/`stp` instructions when operating on one or two vector registers?

I am working on some ARM assembly code and I want to know the differences between ld1/st1 and ldr/str, ldp/stp instructions when operating on one or two vector registers. I know that ld1 has some ...
Zz Tux's user avatar
  • 610
3 votes
0 answers
181 views

OpenMP - Weird Result in Combination of parallel and SIMD namespaces

I have a C++ project which uses OpenMP, and in some place in the code I have #pragma omp simd nested inside #pragma omp parallel. There was a consistent crash in the code which happened only in multi-...
Amit's user avatar
  • 117
1 vote
0 answers
136 views

How should I chose between _mm_move_sd / _mm_shuffle_pd / _mm_blend_pd

If I am not mistaken, _mm_shuffle_pd(x, y, _MM_SHUFFLE2(0, 1)); and _mm_move_sd(x, y); And also _mm_blend_pd in a later instruction set should all do the same thing. But clang and gcc generate ...
Denis Yaroshevskiy's user avatar
2 votes
0 answers
106 views

Optimizing "vector" comparison in Rust

I am attempting to optimize some basic "statistics-lite" primitives (averages, medians and the like) in Rust. I am very happy with the performance of the compiled code, as it beats pretty ...
Martinghoul's user avatar
0 votes
1 answer
113 views

How to optimize array iteration in C for intel processors [duplicate]

Tthe function difference may compute the amount of unequal elements of two char arrays of the length n: size_t difference(size_t n, const char a[n], const char b[n]) { size_t res = 0; for (...
HeapUnderStop's user avatar
0 votes
0 answers
62 views

loading and using char Array with a xmm register with intel intrinsics in C

Is it possible to compute char- arrays with intel sse intrinsics? my attempt so far: void load_and_print( char arr[], size_t l ){ __m128i __attribute__((aligned(16))) x_reg = _mm_load_si128((const ...
marcel fiedler's user avatar
0 votes
2 answers
182 views

How to further optimize this algorithm for detecting motion between two images using AVX2

I have written an algorithm that compares two image frames (represented as ARGB arrays with each color channel byte) and detect if there is a significant difference between the images, taking into ...
ImJustACowLol's user avatar
1 vote
0 answers
63 views

Sum of bytes in an __m128 register [duplicate]

I am trying to find the sum of all bytes in an __m128 register using SSE and SSE2. So far what I have is __m128i sum = _mm_sad_epu8(bytes, _mm_setzero_si128()); return _mm_cvtsi128_si32(sum) + ...
user17784058's user avatar
1 vote
1 answer
138 views

SIMD Intrinsics AVX. Tried to use _mm256_mullo_epi64. But got 0xC000001D: Illegal Instruction exception

I want to multiply two NxN matrices using SIMD. I want to do matrix multiplication for 64-bit integers, and multiply one element of a matrix with another element with the same index. For example: c[1][...
hellicop11's user avatar
0 votes
1 answer
100 views

Find index of first occurrence of 16-bit value using AVX/SIMD

I'm trying to return the index of the first occurrence of a 16 bit value within 256 bits. I know how to do this for 8-bits, using: int _mm256_movemask_epi8 (__m256i a) However, there does not seem to ...
user997112's user avatar
  • 29.1k
0 votes
1 answer
173 views

R code Boost "fatal error: boost/detail/endian.hpp: No such file

Simple example from RcppNT2 that generates "fatal error: boost/detail/endian.hpp: No such file or directory #include <boost/detail/endian.hpp>". I downloaded boost C++ version 1.82. I ...
user3647872's user avatar
0 votes
1 answer
61 views

Is it slow to branch on a memory offset incremented by vld1q in ARM NEON?

The instruction vld1q_u16 seems to make my ARM NEON code about 3x slower if the address it increments is branched on. At least that is my current suspicion. You can check out some example runnable C ...
J. Rehbein's user avatar
3 votes
1 answer
85 views

Why does __m128 cause alignment issues in a union with float x/y/z?

I've never actually ran into this problem before, at least not that I'm aware of... But I'm working on some SIMD vector optimizations in some of my code and I'm having some alignment issues. Here's ...
Seishuku's user avatar
0 votes
0 answers
45 views

page fault error with SIMD strlen (using SWAR in integer registers, not SSE) [duplicate]

The asm function strlen receives the link to an string as a char - Array. To to so, the functions may use SIMD on general purpose register, but without using xmm register or SSE instructions. The ...
HeapUnderStop's user avatar
7 votes
1 answer
91 views

Give the CLANG compiler a loop length assertion

I have a loop that loads two float* arrays into __m256 vectors and processes them. Following this loop, I have code that loads the balance of values into the vectors and then processes them. So there ...
IamIC's user avatar
  • 17.8k
0 votes
1 answer
200 views

How to check if a register contains a zero byte without SIMD instructions

Given a 64 Bit general purpose register (Not a xmm register) in x64 architecture, filled with one byte unsigned values. How can I check it for a zero value simultaneously without using SSE ...
HeapUnderStop's user avatar

1
2 3 4 5
51