avx2

Efficient way of rotating a byte inside an AVX register

回眸只為那壹抹淺笑 提交于 2019-12-05 06:44:39
Summary/tl;dr: Is there any way to rotate a byte in an YMM register bitwise (using AVX), other than doing 2x shifts and blending the results together? For each 8 bytes in an YMM register, I need to left-rotate 7 bytes in it. Each byte needs to be rotated one bit more to the left than the former. Thus the 1 byte should be rotated 0 bits and the seventh should be rotated 6 bits. Currently, I have made an implementation that does this by [I use the 1-bit rotate as an example here] shifting the register 1 bit to the left, and 7 to the right individually. I then use the blend operation (intrinsic

Efficient (on Ryzen) way to extract the odd elements of a __m256 into a __m128?

主宰稳场 提交于 2019-12-05 06:07:14
Is there an intrinsic or another efficient way for repacking high/low 32-bit components of 64-bit components of AVX register into an SSE register? A solution using AVX2 is ok. So far I'm using the following code, but profiler says it's slow on Ryzen 1800X : // Global constant const __m256i gHigh32Permute = _mm256_set_epi32(0, 0, 0, 0, 7, 5, 3, 1); // ... // function code __m256i x = /* computed here */; const __m128i high32 = _mm256_castsi256_si128(_mm256_permutevar8x32_epi32(x), gHigh32Permute); // This seems to take 3 cycles On Intel, your code would be optimal. One 1-uop instruction is the

Optimal uint8_t bitmap into a 8 x 32bit SIMD “bool” vector

坚强是说给别人听的谎言 提交于 2019-12-05 02:36:45
问题 As part of a compression algorithm, I am looking for the optimal way to achieve the following: I have a simple bitmap in a uint8_t . For example 01010011 What I want is a __m256i of the form: (0, maxint, 0, maxint, 0, 0, maxint, maxint) One way to achieve this is by shuffling a vector of 8 x maxint into a vector of zeros. But that first requires me to expand my uint8_t to the right shuffle bitmap. I am wondering if there is a better way? 回答1: Here is a solution (PaulR improved my solution,

Shift elements to the left of a SIMD register based on boolean mask

蹲街弑〆低调 提交于 2019-12-04 20:57:40
This question is related to this: Optimal uint8_t bitmap into a 8 x 32bit SIMD "bool" vector I would like to create an optimal function with this signature: __m256i PackLeft(__m256i inputVector, __m256i boolVector); The desired behaviour is that on an input of 64bit int like this: inputVector = {42, 17, 13, 3} boolVector = {true, false, true, false} It masks all values that have false in the boolVector and then repacks the values that remain to the left. On the output above, the return value should be: {42, 13, X, X} ... Where X is "I don't care". An obvious way to do this is the use _mm

SSE - AVX conversion from double to char

别说谁变了你拦得住时间么 提交于 2019-12-04 18:34:19
I want to convert a vector of double precision values to char. I have to make two distinct approaches, one for SSE2 and the other for AVX2. I started with AVX2. __m128i sub_proc(__m256d& in) { __m256d _zero_pd = _mm256_setzero_pd(); __m256d ih_pd = _mm256_unpackhi_pd(in,_zero_pd); __m256d il_pd = _mm256_unpacklo_pd(in,_zero_pd); __m128i ih_si = _mm256_cvtpd_epi32(ih_pd); __m128i il_si = _mm256_cvtpd_epi32(il_pd); ih_si = _mm_shuffle_epi32(ih_si,_MM_SHUFFLE(3,1,2,0)); il_si = _mm_shuffle_epi32(il_si,_MM_SHUFFLE(3,1,2,0)); ih_si = _mm_packs_epi32(_mm_unpacklo_epi32(il_si,ih_si),_mm_unpackhi

Aligned and unaligned memory access with AVX/AVX2 intrinsics

拥有回忆 提交于 2019-12-04 17:35:04
问题 According to Intel's Software Developer Manual (sec. 14.9), AVX relaxed the alignment requirements of memory accesses. If data is loaded directly in a processing instruction, e.g. vaddps ymm0,ymm0,YMMWORD PTR [rax] the load address doesn't have to be aligned. However, if a dedicated aligned load instruction is used, such as vmovaps ymm0,YMMWORD PTR [rax] the load address has to be aligned (to multiples of 32), otherwise an exception is raised. What confuses me is the automatic code generation

Intel AVX2 Assembly Development

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 14:38:54
I am Optimizing the my Video Decoder using Intel assembly for 64-bit architecture. For optimization am using AVX2 instruction set. My development Environment:- OS :- Win 7(64-bit) IDE:- MSVS 2008(Prof) CPU:- Core i5(support up to AVX) Assembler:- YASM I would like to know is there any emulators to run and debug my AVX2 code without upgrading the hardware. Majorly am looking to run & debug my application on existing environment. Any suggestions? You can download the Intel SDE (Software Development Emulator) for free and use that - it works pretty well. Native instructions run at full speed -

Why do processors with only AVX out-perform AVX2 processors for many SIMD algorithms?

China☆狼群 提交于 2019-12-04 07:20:48
I've been investigating the benefits of SIMD algorithms in C# and C++, and found that in many cases using 128-bit registers on an AVX processor offers a better improvement than using 256-bit registers on a processor with AVX2, but I don't understand why. By improvement I mean the speed-up of a SIMD algorithm relative to a non-SIMD algorithm on the same machine. On an AVX processor, the upper half of the 256 bit registers and floating point units are powered down by the CPU when not executing AVX instructons (VEX encoded opcodes). When code does use AVX instructions, the CPU has to power up the

_mm_alignr_epi8 (PALIGNR) equivalent in AVX2

百般思念 提交于 2019-12-04 06:21:58
In SSE3, the PALIGNR instruction performs the following: PALIGNR concatenates the destination operand (the first operand) and the source operand (the second operand) into an intermediate composite, shifts the composite at byte granularity to the right by a constant immediate, and extracts the right-aligned result into the destination. I'm currently in the midst of porting my SSE4 code to use AVX2 instructions and working on 256bit registers instead of 128bit. Naively, I believed that the intrinsics function _mm256_alignr_epi8 (VPALIGNR) performs the same operation as _mm_alignr_epi8 only on

Shuffle elements of __m256i vector

◇◆丶佛笑我妖孽 提交于 2019-12-04 06:13:41
I want to shuffle elements of __m256i vector. And there is an intrinsic _mm256_shuffle_epi8 which does something like, but it doesn't perform a cross lane shuffle. How can I do it with using AVX2 instructions? There is a way to emulate this operation, but it is not very beautiful: const __m256i K0 = _mm256_setr_epi8( 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0x70, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0); const __m256i K1 = _mm256_setr_epi8( 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,