| 1 | //cxx . . $ `<file>/arch/x86_64/rsp/vmac.h`/ |
| 2 | // arch/x86_64/rsp/vmacf.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 | static inline __m128icxx . . $ __m128i# rsp_vmacf_vmacucxx . . $ rsp_vmacf_vmacu(3a150aa905e39abd).(uint32_tcxx . . $ uint32_t# iw, __m128icxx . . $ __m128i# vs, __m128icxx . . $ __m128i# vt, |
| 9 | __m128icxx . . $ __m128i# zero, __m128icxx . . $ __m128i# *acc_lo, __m128icxx . . $ __m128i# *acc_md, __m128icxx . . $ __m128i# *acc_hi) { |
| 10 | __m128icxx . . $ __m128i# overflow_hi_mask, overflow_md_mask; |
| 11 | __m128icxx . . $ __m128i# lo, md, hi, carry, overflow_mask; |
| 12 | |
| 13 | // Get the product and shift it over |
| 14 | // being sure to save the carries. |
| 15 | lo = _mm_mullo_epi16cxx . . $ _mm_mullo_epi16(e79ab442e937dade).(vs, vt); |
| 16 | hi = _mm_mulhi_epi16cxx . . $ _mm_mulhi_epi16(e79ab442e937dade).(vs, vt); |
| 17 | |
| 18 | md = _mm_slli_epi16cxx . . $ _mm_slli_epi16(8c21f12da5b7f84d).(hi, 1); |
| 19 | carry = _mm_srli_epi16cxx . . $ _mm_srli_epi16(8c21f12da5b7f84d).(lo, 15); |
| 20 | hi = _mm_srai_epi16cxx . . $ _mm_srai_epi16(8c21f12da5b7f84d).(hi, 15); |
| 21 | md = _mm_or_si128cxx . . $ _mm_or_si128(e79ab442e937dade).(md, carry); |
| 22 | lo = _mm_slli_epi16cxx . . $ _mm_slli_epi16(8c21f12da5b7f84d).(lo, 1); |
| 23 | |
| 24 | // Tricky part: start accumulating everything. |
| 25 | // Get/keep the carry as we'll add it in later. |
| 26 | overflow_mask = _mm_adds_epu16cxx . . $ _mm_adds_epu16(e79ab442e937dade).(*acc_lo, lo); |
| 27 | *acc_lo = _mm_add_epi16cxx . . $ _mm_add_epi16(e79ab442e937dade).(*acc_lo, lo); |
| 28 | |
| 29 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(*acc_lo, overflow_mask); |
| 30 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(overflow_mask, zero); |
| 31 | |
| 32 | // Add in the carry. If the middle portion is |
| 33 | // already 0xFFFF and we have a carry, we have |
| 34 | // to carry the all the way up to hi. |
| 35 | md = _mm_sub_epi16cxx . . $ _mm_sub_epi16(e79ab442e937dade).(md, overflow_mask); |
| 36 | carry = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(md, zero); |
| 37 | carry = _mm_and_si128cxx . . $ _mm_and_si128(e79ab442e937dade).(carry, overflow_mask); |
| 38 | hi = _mm_sub_epi16cxx . . $ _mm_sub_epi16(e79ab442e937dade).(hi, carry); |
| 39 | |
| 40 | // Accumulate the middle portion. |
| 41 | overflow_mask = _mm_adds_epu16cxx . . $ _mm_adds_epu16(e79ab442e937dade).(*acc_md, md); |
| 42 | *acc_md = _mm_add_epi16cxx . . $ _mm_add_epi16(e79ab442e937dade).(*acc_md, md); |
| 43 | |
| 44 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(*acc_md, overflow_mask); |
| 45 | overflow_mask = _mm_cmpeq_epi16cxx . . $ _mm_cmpeq_epi16(e79ab442e937dade).(overflow_mask, zero); |
| 46 | |
| 47 | // Finish up the accumulation of the... accumulator. |
| 48 | *acc_hi = _mm_add_epi16cxx . . $ _mm_add_epi16(e79ab442e937dade).(*acc_hi, hi); |
| 49 | *acc_hi = _mm_sub_epi16cxx . . $ _mm_sub_epi16(e79ab442e937dade).(*acc_hi, overflow_mask); |
| 50 | |
| 51 | // VMACU |
| 52 | if (iw & 0x1) { |
| 53 | overflow_hi_mask = _mm_srai_epi16cxx . . $ _mm_srai_epi16(8c21f12da5b7f84d).(*acc_hi, 15); |
| 54 | overflow_md_mask = _mm_srai_epi16cxx . . $ _mm_srai_epi16(8c21f12da5b7f84d).(*acc_md, 15); |
| 55 | md = _mm_or_si128cxx . . $ _mm_or_si128(e79ab442e937dade).(overflow_md_mask, *acc_md); |
| 56 | overflow_mask = _mm_cmpgt_epi16cxx . . $ _mm_cmpgt_epi16(e79ab442e937dade).(*acc_hi, zero); |
| 57 | md = _mm_andnot_si128cxx . . $ _mm_andnot_si128(e79ab442e937dade).(overflow_hi_mask, md); |
| 58 | return _mm_or_si128cxx . . $ _mm_or_si128(e79ab442e937dade).(overflow_mask, md); |
| 59 | } |
| 60 | |
| 61 | // VMACF |
| 62 | else |
| 63 | return rsp_sclamp_acc_tomdcxx . . $ rsp_sclamp_acc_tomd(e79ab442e937dade).(*acc_md, *acc_hi); |
| 64 | } |
| 65 |