AVX512 中 _mm256_sign_epi8 的等效函数

问题描述 投票:0回答:1

我正在尝试编写 AVX512 代码。在进行相同的工作时,试图在 AVX512 中寻找类似于 _mm256_sign_epi8 的函数,但无法找到等效的函数。如果我们找到类似的指令,那将非常有用。是否有等效的指令或任何其他替代方法可以为具有相似/较小 CPI/延迟的 AVX512 执行此操作?谢谢

AVX2 功能示例

z = _mm256_sign_epi8(x,y)

基于 y 元素的符号,x 元素的符号也会更新

c++ simd intrinsics avx2 avx512
1个回答
0
投票

AVX512 中没有 _mm256_sign_epi8 的直接替代品。

引用https://lemire.me/blog/2024/01/11/implementing-the-missing-sign-instruction-in-avx-512/,一种可能的替代方法是:

#include <immintrin.h>

__m512i _mm512_sign_epi8(__m512i a, __m512i b) {
  // Set a 512-bit integer vector of all zeros.
  __m512i zero = _mm512_setzero_si512();
  // Build 64-bit mask, where each bit indicates whether the corresponding element < 0.
  __mmask64 blt0 = _mm512_movepi8_mask(b);
  // Build 64-bit mask, where each bit indicates whether the corresponding element <= 0.
  __mmask64 ble0 = _mm512_cmple_epi8_mask(b, zero);
  // Copy elements from `a` where the mask blt0 is true, otherwise use zero.
  __m512i a_blt0 = _mm512_mask_mov_epi8(zero, blt0, a);
  // Return `a - a_blt0` where the mask ble0 is true, otherwise use zero.
  return _mm512_mask_sub_epi8(a, ble0, zero, a_blt0);
}
© www.soinside.com 2019 - 2024. All rights reserved.