* Integer Division ***************************/ See simd/intdiv.h for more clarification divide each unsigned 8-bit element by a precomputed divisor
| 91 | // See simd/intdiv.h for more clarification |
| 92 | // divide each unsigned 8-bit element by a precomputed divisor |
| 93 | NPY_FINLINE npyv_u8 npyv_divc_u8(npyv_u8 a, const npyv_u8x3 divisor) |
| 94 | { |
| 95 | const __m128i bmask = _mm_set1_epi32(0x00FF00FF); |
| 96 | const __m128i shf1b = _mm_set1_epi8(0xFFU >> _mm_cvtsi128_si32(divisor.val[1])); |
| 97 | const __m128i shf2b = _mm_set1_epi8(0xFFU >> _mm_cvtsi128_si32(divisor.val[2])); |
| 98 | // high part of unsigned multiplication |
| 99 | __m128i mulhi_even = _mm_mullo_epi16(_mm_and_si128(a, bmask), divisor.val[0]); |
| 100 | __m128i mulhi_odd = _mm_mullo_epi16(_mm_srli_epi16(a, 8), divisor.val[0]); |
| 101 | mulhi_even = _mm_srli_epi16(mulhi_even, 8); |
| 102 | __m128i mulhi = npyv_select_u8(bmask, mulhi_even, mulhi_odd); |
| 103 | // floor(a/d) = (mulhi + ((a-mulhi) >> sh1)) >> sh2 |
| 104 | __m128i q = _mm_sub_epi8(a, mulhi); |
| 105 | q = _mm_and_si128(_mm_srl_epi16(q, divisor.val[1]), shf1b); |
| 106 | q = _mm_add_epi8(mulhi, q); |
| 107 | q = _mm_and_si128(_mm_srl_epi16(q, divisor.val[2]), shf2b); |
| 108 | return q; |
| 109 | } |
| 110 | // divide each signed 8-bit element by a precomputed divisor (round towards zero) |
| 111 | NPY_FINLINE npyv_s16 npyv_divc_s16(npyv_s16 a, const npyv_s16x3 divisor); |
| 112 | NPY_FINLINE npyv_s8 npyv_divc_s8(npyv_s8 a, const npyv_s8x3 divisor) |
nothing calls this directly
no test coverage detected