1 //===----------------------Hexagon builtin routine ------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 /* ==================================================================== *
10 fast2_QLDOUBLE fast2_ldadd(fast2_QLDOUBLE a,fast2_QLDOUBLE b) {
12 lint manta = a & MANTMASK;
13 int expa = Q6_R_sxth_R(a) ;
14 lint mantb = b & MANTMASK;
15 int expb = Q6_R_sxth_R(b) ;
16 int exp, expdiff, j, k, hi, lo, cn;
19 expdiff = (int) Q6_P_vabsdiffh_PP(a, b);
20 expdiff = Q6_R_sxth_R(expdiff) ;
21 if (expdiff > 63) { expdiff = 62;}
31 mant = (manta>>expa) + (mantb>>expb);
33 hi = (int) (mant>>32);
36 k = Q6_R_normamt_R(hi);
37 if(hi == 0 || hi == -1) k = 31+Q6_R_normamt_R(lo);
40 cn = (mant == 0x8000000000000000LL);
43 if (mant == 0 || mant == -1) exp = 0x8001;
44 c = (mant & MANTMASK) | (((lint) exp) & EXP_MASK);
47 * ==================================================================== */
49 .global fast2_ldadd_asm
50 .type fast2_ldadd_asm, @function
72 expd = sub(expa, expb):sat
73 ce = CMP.GT(expa, expb);
74 if ( ce.new) exp = add(expa, #1)
75 if (!ce.new) exp = add(expb, #1)
86 if (!ce) expa = add(expd, #1)
87 if ( ce) expb = add(expd, #1)
89 lmanta = ASR(lmanta, expa)
90 lmantb = ASR(lmantb, expb)
92 lmant = add(lmanta, lmantb)
98 exp -= add(k, #-1) //exp = exp - (k-1)
103 if(!p0)memw(r7+#8) = exp
104 lmant = ASL(lmant, k)
105 if(p0) jump .Ldenorma
116 /* =================================================================== *
117 fast2_QLDOUBLE fast2_ldsub(fast2_QLDOUBLE a,fast2_QLDOUBLE b) {
119 lint manta = a & MANTMASK;
120 int expa = Q6_R_sxth_R(a) ;
121 lint mantb = b & MANTMASK;
122 int expb = Q6_R_sxth_R(b) ;
123 int exp, expdiff, j, k;
126 expdiff = (int) Q6_P_vabsdiffh_PP(a, b);
127 expdiff = Q6_R_sxth_R(expdiff) ;
128 if (expdiff > 63) { expdiff = 62;}
138 mant = (manta>>expa) - (mantb>>expb);
139 k = Q6_R_clb_P(mant)-1;
142 if (mant == 0 || mant == -1) exp = 0x8001;
143 c = (mant & MANTMASK) | (((lint) exp) & EXP_MASK);
146 * ==================================================================== */
148 .global fast2_ldsub_asm
149 .type fast2_ldsub_asm, @function
171 expd = sub(expa, expb):sat
172 ce = CMP.GT(expa, expb);
173 if ( ce.new) exp = add(expa, #1)
174 if (!ce.new) exp = add(expb, #1)
181 expd = min(expd, c63)
183 mantb = memd(r29+#16)
185 if (!ce) expa = add(expd, #1)
186 if ( ce) expb = add(expd, #1)
188 lmanta = ASR(lmanta, expa)
189 lmantb = ASR(lmantb, expb)
191 lmant = sub(lmanta, lmantb)
197 exp -= add(k, #-1) //exp = exp - (k+1)
202 if(!p0)memw(r7+#8) = exp
203 lmant = asl(lmant, k)
204 if(p0) jump .Ldenorma_s
216 /* ==================================================================== *
217 fast2_QLDOUBLE fast2_ldmpy(fast2_QLDOUBLE a,fast2_QLDOUBLE b) {
219 lint manta = a & MANTMASK;
220 int expa = Q6_R_sxth_R(a) ;
221 lint mantb = b & MANTMASK;
222 int expb = Q6_R_sxth_R(b) ;
225 int hia, hib, hi, lo;
226 unsigned int loa, lob;
228 hia = (int)(a >> 32);
229 loa = Q6_R_extractu_RII((int)manta, 31, 1);
230 hib = (int)(b >> 32);
231 lob = Q6_R_extractu_RII((int)mantb, 31, 1);
233 mant = Q6_P_mpy_RR(hia, lob);
234 mant = Q6_P_mpyacc_RR(mant,hib, loa);
235 mant = (mant >> 30) + (Q6_P_mpy_RR(hia, hib)<<1);
237 hi = (int) (mant>>32);
239 k = Q6_R_normamt_R(hi);
241 exp = expa + expb - k;
242 if (mant == 0 || mant == -1) exp = 0x8001;
243 c = (mant & MANTMASK) | (((lint) exp) & EXP_MASK);
246 * ==================================================================== */
248 .global fast2_ldmpy_asm
249 .type fast2_ldmpy_asm, @function
264 #define lmantc R11:10
275 mantb = memd(r29+#16)
279 mantbl_= extractu(mantbl, #31, #1)
280 mantxl_= extractu(mantxl, #31, #1)
284 lmantc = mpy(mantxh, mantbh)
285 mantd = mpy(mantxh, mantbl_)
290 lmantc = add(lmantc, lmantc)
291 mantd += mpy(mantbh, mantxl_)
294 mantd = asr(mantd, #30)
296 p1 = cmp.eq(mantx, mantb)
299 mantd = add(mantd, lmantc)
300 expa= add(expa, expb)
301 p2 = cmp.eq(mantb, min)
314 mantd = asl(mantd, kp)
317 if(p0.new) jump:NT .Ldenorm //rarely happens