Home > Article > Backend Development > How to Load 8 Characters from Memory into an __m256 Variable: Three Efficient Approaches
Problem:
You want to optimize an algorithm for Gaussian blur on an image by replacing a float buffer[8] with an intrinsic __m256 variable to enhance performance.
Solution 1: Using AVX2's PMOVZX and VCVTDQ2PS
This approach utilizes PMOVZX to extend 8-bit characters into 32-bit integers and then converts them to floating-point values through VCVTDQ2PS. Specifically:
VPMOVZXBD ymm0, [rsi] ; Byte to DWord VCVTDQ2PS ymm0, ymm0 ; convert to packed float
Solution 2: Combining Broadcast Load and Shuffling
This strategy involves performing a 128-bit broadcast load to yield a 64-bit shuffle control vector for vpshufb, allowing for zero extension and packed float conversion. It offers a high throughput by eliminating the need for additional shuffle instructions.
VPMOVSXBD xmm0, [rsi] ; Byte to DWord VPMOVSXBD xmm1, [rsi+4] VINSERTF128 ymm0, ymm0, xmm1, 1 VCVTDQ2PS ymm0, ymm0 ; convert to packed float.
Solution 3: Handling AVX1 Limitations
In the absence of AVX2, the following steps can be employed:
VPMOVZXBD xmm0, [rsi] VPMOVZXBD xmm1, [rsi+4] VINSERTF128 ymm0, ymm0, xmm1, 1 ; put the 2nd load of data into the high128 of ymm0 VCVTDQ2PS ymm0, ymm0 ; convert to packed float.
Additional Notes:
The above is the detailed content of How to Load 8 Characters from Memory into an __m256 Variable: Three Efficient Approaches. For more information, please follow other related articles on the PHP Chinese website!