0

How to conditionally keep `equal floats using AVX intrinsics?

I have

__m256 valA = .....;
__m256 valB = .....;

__m256 aIsB = _mm256_cmp_ps( valA, valB, _CMP_EQ_OS );

After getting such a mask I intended to use

__m256 zeros = _mm256_set1_ps(0.0f)
__m256 same = _mm256_blend_ps(valA, zeros, aIsB);//<--aIsB must actually be imm8

however _mm256_blend_ps requires mask to be a runtime compile constant. Otherwise I would somehow need to cast __m256 into imm8

Should I use some other function?

Documentation:

_mm256_blend_ps

_mm256_cpm_ps

"AVX compare" predicate variants

Kari
  • 1,244
  • 1
  • 13
  • 27

1 Answers1

3

The instruction you were looking for is blendvps, but if you want to have zero at every entry which does not fulfill the comparison, you can simply use andps.

__m256 aIsB = _mm256_cmp_ps( valA, valB, _CMP_EQ_OS );
__m256 same = _mm256_and_ps( valA, aIsB);
chtz
  • 17,329
  • 4
  • 26
  • 56