void DXGICapture::CopyBGRAtoBGRAVX232pre(uint8t* _restrict dst, const uint8t* restrict…
- User
void DXGICapture::CopyBGRA_to_BGR_AVX2_32_pre(uint8_t* __restrict dst, const uint8_t* __restrict src, int width, int height, int srcPitch) { const __m256i shuffle_mask = _mm256_setr_epi8( 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1, 0, 1, 2, 4, 5, 6, 8, 9, 10, 12, 13, 14, -1, -1, -1, -1 );
const __m256i permute_mask = _mm256_setr_epi32(0, 1, 2, 4, 5, 6, 3, 7); for (int y = 0; y < height; ++y) { const uint8_t* srcRow = src + y * srcPitch; uint8_t* dstRow = dst + y * width * 3; // 处理32个像素 for (int x = 0; x < width; x += 32) { // --- 添加预取指令 --- // 预取下一组32个像素的数据。 // 地址是 srcRow + (x + 32) * 4 // _MM_HINT_T0 表示加载到所有缓存级别 (L1, L2, L3) _mm_prefetch((const char*)(srcRow + (x + 32) * 4), _MM_HINT_T0); // 加载32个像素 (128字节) = 4个AVX2寄存器 __m256i bgra0 = _mm256_loadu_si256((__m256i*)(srcRow + x * 4)); __m256i bgra1 = _mm256_loadu_si256((__m256i*)(srcRow + x * 4 + 32)); __m256i bgra2 = _mm256_loadu_si256((__m256i*)(srcRow + x * 4 + 64)); __m256i bgra3 = _mm256_loadu_si256((__m256i*)(srcRow + x * 4 + 96)); // ... 剩余的转换和存储代码保持不变 ... __m256i bgr0 = _mm256_permutevar8x32_epi32( _mm256_shuffle_epi8(bgra0, shuffle_mask), permute_mask); __m256i bgr1 = _mm256_permutevar8x32_epi32( _mm256_shuffle_epi8(bgra1, shuffle_mask), permute_mask); __m256i bgr2 = _mm256_permutevar8x32_epi32( _mm256_shuffle_epi8(bgra2, shuffle_mask), permute_mask); __m256i bgr3 = _mm256_permutevar8x32_epi32( _mm256_shuffle_epi8(bgra3, shuffle_mask), permute_mask); _mm_storeu_si128((__m128i*)(dstRow + x * 3), _mm256_castsi256_si128(bgr0)); _mm_storel_epi64((__m128i*)(dstRow + x * 3 + 16), _mm256_extracti128_si256(bgr0, 1)); _mm_storeu_si128((__m128i*)(dstRow + x * 3 + 24), _mm256_castsi256_si128(bgr1)); _mm_storel_epi64((__m128i*)(dstRow + x * 3 + 40), _mm256_extracti128_si256(bgr1, 1)); _mm_storeu_si128((__m128i*)(dstRow + x * 3 + 48), _mm256_castsi256_si128(bgr2)); _mm_storel_epi64((__m128i*)(dstRow + x * 3 + 64), _mm256_extracti128_si256(bgr2, 1)); _mm_storeu_si128((__m128i*)(dstRow + x * 3 + 72), _mm256_castsi256_si128(bgr3)); _mm_storel_epi64((__m128i*)(dstRow + x * 3 + 88), _mm256_extracti128_si256(bgr3, 1)); } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.