xtensor-stack / xsimd

C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, AVX512, NEON, SVE))
https://xsimd.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.19k stars 256 forks source link

Any plans to add support for element-wise max? #1013

Closed mbasmanova closed 6 months ago

mbasmanova commented 6 months ago

I need to compute an element-wise max and I see that there are Intel intrinsics for that:

__m128i _mm_max_epi8 (__m128i a, __m128i b)
__m256i _mm256_max_epi8 (__m256i a, __m256i b)

Compare packed signed 8-bit integers in a and b, and store packed maximum values in dst.

and similar.

I wonder if xsimd already has an API for element-wise max / min. I looked in the documentation, but didn't find it. Would it make sense to add?

As a workaround, I'm currently using le + select.

auto lt = xsimd::lt(batch, otherBatch);
auto maxBatch = xsimd::select(lt, otherBatch, batch);

CC: @kgpai @Yuhta

serge-sans-paille commented 6 months ago

yeah, we already have this: https://xsimd.readthedocs.io/en/latest/api/math_index.html#_CPPv4I00E3max5batchI1T1AERK5batchI1T1AERK5batchI1T1AE https://xsimd.readthedocs.io/en/latest/api/math_index.html#_CPPv4I00E3min5batchI1T1AERK5batchI1T1AERK5batchI1T1AE

mbasmanova commented 6 months ago

@serge-sans-paille Thank you for the pointer. I missed these somehow. Appreciate a quick response.