Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <stddef.h>
- #include <emmintrin.h>
- #include <tmmintrin.h>
- /// Aligned search max item
- static inline uint8_t search_max_octet_aligned(const __m128i *src, size_t length) {
- __m128i vmax = _mm_set_epi32(0, 0, 0, 0);
- __m128i mj;
- while (length --> 0) {
- mj = _mm_load_si128(src++);
- vmax = _mm_max_epu8 (vmax, mj);
- }
- vmax = _mm_max_epu8(vmax, _mm_alignr_epi8(vmax, vmax, 1));
- vmax = _mm_max_epu8(vmax, _mm_alignr_epi8(vmax, vmax, 2));
- vmax = _mm_max_epu8(vmax, _mm_alignr_epi8(vmax, vmax, 4));
- vmax = _mm_max_epu8(vmax, _mm_alignr_epi8(vmax, vmax, 8));
- return _mm_extract_epi16(vmax, 0) & 0xFF;
- }
- uint8_t search_max_octet(const uint8_t *src, size_t length) {
- uint8_t result = 0;
- while (length && (((uintptr_t)src) & 0xF)) {
- result = result < src[0] ? src[0] : result;
- src++;
- length--;
- }
- if (length > 16) {
- size_t rl = length & ~0xF;
- result = search_max_octet_aligned((const __m128i *)src, rl >> 16);
- src += rl;
- length -= rl;
- }
- for (unsigned i = 0; i < length; i++)
- result = result < src[i] ? src[i] : result;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement