| 1 | //cxx . . $ `<file>/arch/x86_64/rsp/vmull.h`/ |
| 2 | // arch/x86_64/rsp/vmadl.h |
| 3 | // |
| 4 | // This file is subject to the terms and conditions defined in |
| 5 | // 'LICENSE', which is part of this source code package. |
| 6 | // |
| 7 | |
| 8 | #include "common.h"cxx . . $ `<file>/build/common.h`/ |
| 9 | |
| 10 | static inline __m128icxx . . $ __m128i# rsp_vmadl_vmudlcxx . . $ rsp_vmadl_vmudl(3a150aa905e39abd).(uint32_tcxx . . $ uint32_t# iw, __m128icxx . . $ __m128i# vs, __m128icxx . . $ __m128i# vt, |
| 11 | __m128icxx . . $ __m128i# zero, __m128icxx . . $ __m128i# *acc_lo, __m128icxx . . $ __m128i# *acc_md, __m128icxx . . $ __m128i# *acc_hi) { |
| 12 | __m128icxx . . $ __m128i# hi, overflow_mask; |
| 13 | |
| 14 | hi = _mm_mulhi_epu16cxx . . $ _mm_mulhi_epu16(e79ab442e937dade).(vs, vt); |
| 15 | |
| 16 | // VMADL |
| 17 | if (iw & 0x8) { |
| 18 | |
| 19 | // Tricky part: start accumulate everything. |
| 20 | // Get/keep the carry as we'll add it in later. |
| 21 | overflow_mask = _mm_adds_epu16cxx . . $ _mm_adds_epu16(e79ab442e937dade).(*acc_lo, hi); |
| 22 | *acc_lo = _mm_add_epi16cxx . . $ _mm_add_epi16(e79ab442e937dade).(*acc_lo, hi); |
| 23 | |
| 24 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(*acc_lo, overflow_mask); |
| 25 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(overflow_mask, zero); |
| 26 | hi = _mm_sub_epi16cxx . . $ _mm_sub_epi16(e79ab442e937dade).(zero, overflow_mask); |
| 27 | |
| 28 | // Check for overflow of the upper sum. |
| 29 | // |
| 30 | // TODO: Since hi can only be {0,1}, we should |
| 31 | // be able to generalize this for performance. |
| 32 | overflow_mask = _mm_adds_epu16cxx . . $ _mm_adds_epu16(e79ab442e937dade).(*acc_md, hi); |
| 33 | *acc_md = _mm_add_epi16cxx . . $ _mm_add_epi16(e79ab442e937dade).(*acc_md, hi); |
| 34 | |
| 35 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(*acc_md, overflow_mask); |
| 36 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(overflow_mask, zero); |
| 37 | |
| 38 | // Finish up the accumulation of the... accumulator. |
| 39 | // Since the product was unsigned, only worry about |
| 40 | // positive overflow (i.e.: borrowing not possible). |
| 41 | *acc_hi = _mm_sub_epi16cxx . . $ _mm_sub_epi16(e79ab442e937dade).(*acc_hi, overflow_mask); |
| 42 | |
| 43 | return rsp_uclamp_acccxx . . $ rsp_uclamp_acc(fc847b05503d94b9).(*acc_lo, *acc_md, *acc_hi, zero); |
| 44 | } |
| 45 | |
| 46 | // VMUDL |
| 47 | else { |
| 48 | *acc_lo = hi; |
| 49 | *acc_md = zero; |
| 50 | *acc_hi = zero; |
| 51 | |
| 52 | return hi; |
| 53 | } |
| 54 | } |
| 55 |