Questions tagged [avx]
Advanced Vector Extensions (AVX) is an extension to the x86 instruction set architecture for microprocessors from Intel and AMD.
1,276
questions
3
votes
3
answers
129
views
Collapse __mask64 aka 64-bit integer value, counting nibbles that have all bits set?
I have a __mask64 as a result of a few AVX512 operations:
__mmask64 mboth = _kand_mask64(lres, hres);
I would like to count the number of nibbles in this that have all bits set (0xF).
The simple ...
0
votes
0
answers
43
views
Summing the elements of a __m256i vector [duplicate]
I am looking to sum the elements contained in a __m256i vector and extract the result in a int in C.
Basically, I am trying to achieve this, but using AVX:
sum += key[l] + key[l + 1] + key[l + 2] + ...
-1
votes
1
answer
100
views
How does SIMD (avx) processing work? for example, if I want 10 32 bit floats how do i fit in a 256 bit avx vector?
I am learning about C avx intrinsics and I am wondering how this works.
I am familiar that I can do something like this:
__m256 evens = _mm256_set_ps(2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0);
Here ...
0
votes
0
answers
58
views
Alignment of array type data member of a heap allocated object
I am trying to simdize particular computations. For example I'll take AVX instruction using __m256 type (alignment 32 bytes :- 8 floats).
I am compiling for c++11 so unfortunately I don't have the ...
1
vote
0
answers
29
views
Branch based on the results of vcmpsd
Here is a small segment of NASM code:
vpxor xmm3,xmm3,xmm3
vmovsd xmm0,[rdi+rcx]
vmovsd xmm1,[rsi+rcx]
vsubsd xmm2,xmm0,xmm1
vcmpsd xmm4,xmm2,xmm3,0
je c_this
c_not_this:
mov rax,0
c_this:
mov rax,0
...
1
vote
2
answers
78
views
SIMD algorithm to check of if an integer block is "consecutive."
How to you check if an aligned chunk of 16 u32's is consecutive (and increasing)?
For example: [100, 101, 102, ..., 115] is.
And, [100, 99, 3 ...] is not.
I'm on AVX512f. This is what I have so far:
...
0
votes
0
answers
64
views
Pytorch on CPU without AVX Support
I'm currently working on a Python project that uses torch, torchvision, and torchaudio packages. On my local machine, everything is working fine but after I have deployed the project on a Windows ...
1
vote
0
answers
37
views
gcc: Enable AVX, but not for FP math
Does gcc have the option to enable AVX512, but only for non-FP operations? I have the problem that my application gets much slower if AVX512 is enabled, because they seem to downclock the CPU cores.
...
1
vote
2
answers
102
views
Is there a SIMD intrinsics like scatter but between registers?
So as far as I know there is _mm_shuffle_epi8 if you want to do
dst[i] = a[b[i]]
but my question is if there is a intrinsic that does
dst[b[i]] = a[i]
I want it to work with 16 elements of 8 bits (...
1
vote
1
answer
115
views
Setting/getting 1-bits of __m256i vector from integer array of bit positions
Setting bits:
Given an array int inds[N], where each inds[i] is a 1-bit position in [0, 255] range (and all inds[i] are sorted and unique), I need to set corresponding bits of __m256i to 1.
Is there a ...
0
votes
0
answers
43
views
Performance of float vs double with GCC, Intel & MS C
I have seen the previous ancient x87 era thread on this and thought it was time to revisit it in the modern era of SSE2 & AVX. The results of my fairly simple C benchmark test were mostly what I ...
0
votes
0
answers
35
views
how to calculate a parallel product in ispc
the following code does not work because ISPC refuses to compile a function that returns a varying variable from an exported function. Is there any way to do this?
Manually in AVX I would calculate ...
3
votes
2
answers
131
views
Logical shift between YMM registers
Is it possible for me to load let's say a 2048 bit number into 8 AVX ymm registers, and shift bits left and right between all of these?
I only need to shift 1 bit at a time.
I've tried finding ...
4
votes
0
answers
140
views
SSE/AVX: How to split a set of 16-bit pixels (packed RGB) into bitplanes
I have some basic SSE knowledge and have written some accelerated functions. But this problem has me stumped and I wonder whether there actually is a accelerated SIMD way to handle it.
I have an image ...
4
votes
0
answers
68
views
Why does MinGW GCC use x87 80bit FP library code for atan2, cos, exp & sin?
I have a curious problem porting working numerical code from Intel 2023 & MSC Visual C++ 2022.
The code compiled with GCC is perfectly accurate (too accurate) since some library calls are working ...
4
votes
0
answers
55
views
vpbroadcastb vs mov+vmovq+vpbroadcastq AVX2
I want to move a byte to each byte in a YMM register.
GCC 11 and older uses this method (FASM):
vmovdqa ymm1, YWORD [.byte32]
align 32
.byte32:
dq 0x3f3f3f3f3f3f3f3f
dq 0x3f3f3f3f3f3f3f3f
dq ...
1
vote
1
answer
152
views
How to align/rotate a 256 bit vector in AVX2?
I am working with AVX2 intrinsics and would like to get the following:
input: [1,2,3,4,5,6,7,8]
output: [8,1,2,3,4,5,6,7]
The following works with 128 bit vectors:
let vec1 = _mm_set_epi32(1,2,3,4);
...
0
votes
1
answer
114
views
Fast __m256i bit operations - find or clear highest or lowest set bit
I am looking for fast code to perform the following operations on __m256i and would appreciate help:
Clear least significant bit (least significant that is set)
Clear most significant bit (most ...
0
votes
1
answer
84
views
How to force gcc to use avx2 for copying a 32-byte struct with shared between threads?
Consider the following example compiled with -O3 -march=native:
struct str{
volatile uint64_t a1;
volatile uint64_t a2;
volatile uint64_t a3;
volatile uint64_t a4;
};
int main(void){
...
1
vote
1
answer
91
views
Decrement bytes in XMM/YMM and compare to zero
I have a bunch of unsigned single-byte counters and I'd like to simultaneously decrement them all and if any of them reaches 0, set the carry bit. And if the carry bit is set, I want to reset the ...
0
votes
1
answer
138
views
_mm256_setr_epi64x causing wrong results on x86 msvc v143 build with /arch:AVX
EDIT2: I have additionally reduced the case and improved the testing code
I have been pondering this for a week now, it is probably a compiler bug, but I can't be completely sure.
I'm using MSVC - 19....
0
votes
1
answer
70
views
How to test the latency and throughput of an intrinsic function?
In Intel's Intrinsic guide, each function has its own latency and throughput. For example, _mm256_loadu_ps:
Architecture, Latency, Throughput (CPI)
Alderlake, 7, 0.333333333
Icelake Intel Core, 7, 0.5
...
-1
votes
1
answer
85
views
How to use _mm256_shuffle_epi8 to order elements
I try following code. I know there are some lane restrictions in the shuffle function. But I don't know how to handle it properly. Has someone an idea?
#include <immintrin.h>
int main() {
...
0
votes
1
answer
354
views
Why isn't Google Cloud Run performing the startup probe after scaling?
I have written a Rust server that runs inside a Docker container on Google Cloud Run. The server receives infrequent requests and immediately responds with a 200 status code acknowledgement. It then ...
3
votes
1
answer
165
views
Unpack 12-bit data quickly (where the nibbles aren't contiguous; how to shuffle nibbles?)
I need to unpack 12-bit data stored packed, 2 unsigned 12-bit fields stored in 24-bits. I'd like to store them in a byte[] in a little endian uint16 order.
The packed format is a bit odd; byte[0] is ...
1
vote
3
answers
204
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. ...
1
vote
1
answer
102
views
How can I make the Rust compiler generate AVX2 instructions?
I'm trying to write a simple routine to make use of AVX2 instructions.
As an example, given the following two versions of the same function:
fn mul1(xs: &[i32], ys: &[i32]) -> Vec<i32>...
1
vote
2
answers
113
views
SSE Vector Comparison with Epsilon
I am writing software that needs to compare two _mm256 vectors for equality. However, I would like there to be a margin of error +/- 0.00001. Eg, 3.00001 should be considered equal to 3.00002. Is ...
0
votes
1
answer
77
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 ...
0
votes
3
answers
92
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 ...
3
votes
3
answers
132
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 ...
1
vote
1
answer
107
views
How to do an AVX shuffle by a variable
I want to do implement a fixed lookup table search through instruction.
The instruction _mm_shuffle_epi32(table, index) suit my requirement. but it need a immediate number.
if I want to use similar ...
1
vote
0
answers
117
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 ...
1
vote
1
answer
52
views
Seg fault while using _mm256_i64gather_pd
I am trying to use the gather intrinsic provided by AVX2 but the code exists with a segmentation fault.
double src[100];
// src initialization here
int indices[10] = { 2, 10, 12, 13, 48, 60, 71, 79, ...
4
votes
1
answer
140
views
Why is (V)SHUFPS not in Intel's constant time instruction list?
Earlier this year Intel published a list of instructions that are guaranteed not to have timing dependency on its data operands. (Initially it was suggested that these are constant-time only when ...
0
votes
0
answers
65
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]
...
0
votes
0
answers
155
views
Is the encoding "66| 48/ 0F 50 D8" in MASM for reg=rbx in "MOVMSKPD reg, xmm" correct?
In MOVMSKPD reg, xmm, VMOVMSKPD reg, xmm2, or VMOVMSKPD reg, ymm2 I think reg is r32 or r64.
But in MASM, I tested and got the following results :
MOVMSKPD rbx, xmm0 ;OK, 66| 48/ 0F 50 D8
MOVMSKPD ...
1
vote
1
answer
121
views
gcc c++ coroutine runs avx SIMD code, but causes SIGSEGV
c++ coroutine runs avx SIMD code, but causes SIGSEGV for AVX2 and AVX512
#define AVX512 0
#define AVX2 1
#define SSE 0
HelloCoroutine hello(int& index, int id, int group_size) {
unsigned res=...
30
votes
3
answers
3k
views
Why gcc is so much worse at std::vector<float> vectorization of a conditional multiply than clang?
Consider following float loop, compiled using -O3 -mavx2 -mfma
for (auto i = 0; i < a.size(); ++i) {
a[i] = (b[i] > c[i]) ? (b[i] * c[i]) : 0;
}
Clang done perfect job at vectorizing it. It ...
1
vote
1
answer
133
views
How to interleave the bytes of 3 avx registers in c++
Hi following snipped:
#include <immintrin.h>
#include <stdint.h>
int main() {
uint8_t a[] = {0, 3, 6, 9, 12, 15, 18, 21};
uint8_t b[] = {1, 4, 7, 10, 13, 16, 19, 22};
uint8_t ...
0
votes
0
answers
161
views
Fast 1D convolution using AVX
I would like to do optimize the following code.
void conv(int n, double* output, const double* input, double p1, double p2, double p3) {
for (int i = 1; i + 1 < n; ++i) {
output[i] = ...
0
votes
0
answers
114
views
error: inlining failed in call to ‘always_inline’ ‘_mm256_extract_epi64’: target specific option mismatch
Im trying to use avx intrinsics in C, using CLion.
Even though I included avxinttin.h in the header, the definitions of it are not included and I get an error message for all avx functions.
I get this ...
0
votes
2
answers
202
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 ...
1
vote
1
answer
225
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][...
0
votes
0
answers
159
views
Matrix Multiplication with AVX
I am trying to write a matrix multiplication using AVX.
The worrying snippet is the following
for(int i=0; i<blockRowsA; i++){
for(int j=0; j<blockColsB; j+=8){
// Load 8 floats from ...
0
votes
1
answer
134
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 ...
3
votes
1
answer
189
views
AV512: Best way to combine horizontal sum and broadcast
There is already a question about horizontal sums using AVX512. I'm trying to do something similar, but after the sum, I would like to broadcast the result to all 8 elements in a __m512d variable. So ...
2
votes
0
answers
95
views
What is causing different results when summing two arrays of float numbers using SSE SIMD in C++ versus Go assembly? [closed]
I wrote a little function, just for example, of sum two arrays of float numbers using cted to SSE SIMD vector oerations in C++, but i didn't expected to see the same result in Go lang assembly? What ...
0
votes
0
answers
161
views
How to efficiently multiply and reduce mod n in an AVX register?
I have a __m256i containing 8 32-bit signed integers. I want to multiply them with another __m256i vector of 32-bit integers, but the result will not fit in 32 bit. But immediately after the ...
2
votes
1
answer
196
views
Unable to return multiple SIMD vectors using vectorcall
I am currently working on a program that processes large amounts of data in a tight loop. Blocks of data are loaded into YMM registers, from which 64-bit chunks are extracted to be actually worked on.
...