aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/builtins/hexagon/fastmath2_ldlib_asm.S
blob: cf623f94c8492c0fefa1a0bcdec71e597dcfc47f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
//===----------------------Hexagon builtin routine ------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
/* ==================================================================== *

fast2_QLDOUBLE fast2_ldadd(fast2_QLDOUBLE a,fast2_QLDOUBLE b) {
      fast2_QLDOUBLE c;
      lint manta = a & MANTMASK;
      int  expa  = Q6_R_sxth_R(a) ;
      lint mantb = b & MANTMASK;
      int  expb  = Q6_R_sxth_R(b) ;
      int  exp, expdiff, j, k, hi, lo, cn;
      lint mant;

        expdiff = (int) Q6_P_vabsdiffh_PP(a, b);
        expdiff = Q6_R_sxth_R(expdiff) ;
        if (expdiff > 63) { expdiff = 62;}
        if (expa > expb) {
          exp = expa + 1;
          expa = 1;
          expb = expdiff + 1;
        } else {
          exp = expb + 1;
          expb = 1;
          expa = expdiff + 1;
        }
        mant = (manta>>expa) + (mantb>>expb);

        hi = (int) (mant>>32);
        lo = (int) (mant);

        k =  Q6_R_normamt_R(hi);
        if(hi == 0 || hi == -1) k = 31+Q6_R_normamt_R(lo);

        mant = (mant << k);
        cn  = (mant == 0x8000000000000000LL);
        exp = exp - k + cn;

        if (mant ==  0 || mant == -1)  exp = 0x8001;
        c = (mant & MANTMASK) | (((lint) exp) & EXP_MASK);
      return(c);
 }
 * ==================================================================== */
        .text
        .global fast2_ldadd_asm
        .type fast2_ldadd_asm, @function
fast2_ldadd_asm:
#define manta      R1:0
#define lmanta     R1:0
#define mantb      R3:2
#define lmantb     R3:2
#define expa       R4
#define expb       R5
#define expd       R6
#define exp        R8
#define c63        R9
#define lmant      R1:0
#define k          R4
#define ce         P0
#define zero       R3:2
        .falign
      {
        expa = memw(r29+#8)
        expb = memw(r29+#24)
        r7 = r0
      }
      {
        expd = sub(expa, expb):sat
        ce = CMP.GT(expa, expb);
        if ( ce.new) exp = add(expa, #1)
        if (!ce.new) exp = add(expb, #1)
      } {
        expd = abs(expd):sat
        if ( ce) expa = #1
        if (!ce) expb = #1
        c63 = #62
      } {
        expd = MIN(expd, c63)
        manta = memd(r29+#0)
        mantb = memd(r29+#16)
      } {
        if (!ce) expa = add(expd, #1)
        if ( ce) expb = add(expd, #1)
      } {
        lmanta = ASR(lmanta, expa)
        lmantb = ASR(lmantb, expb)
      } {
        lmant = add(lmanta, lmantb)
        zero = #0
      } {
        k  = clb(lmant)
        c63.L =#0x0001
      } {
        exp -= add(k, #-1)  //exp =  exp - (k-1)
        k = add(k, #-1)
        p0 = cmp.gt(k, #58)
        c63.H =#0x8000
      } {
        if(!p0)memw(r7+#8) = exp
        lmant = ASL(lmant, k)
        if(p0) jump .Ldenorma
      } {
        memd(r7+#0) = lmant
        jumpr  r31
      }
.Ldenorma:
        memd(r7+#0) = zero
      {
        memw(r7+#8) = c63
        jumpr  r31
      }
/* =================================================================== *
 fast2_QLDOUBLE fast2_ldsub(fast2_QLDOUBLE a,fast2_QLDOUBLE b) {
      fast2_QLDOUBLE c;
      lint manta = a & MANTMASK;
      int  expa  = Q6_R_sxth_R(a) ;
      lint mantb = b & MANTMASK;
      int  expb  = Q6_R_sxth_R(b) ;
      int  exp, expdiff, j, k;
      lint mant;

        expdiff = (int) Q6_P_vabsdiffh_PP(a, b);
        expdiff = Q6_R_sxth_R(expdiff) ;
        if (expdiff > 63) { expdiff = 62;}
        if (expa > expb) {
          exp = expa + 1;
          expa = 1;
          expb = expdiff + 1;
        } else {
          exp = expb + 1;
          expb = 1;
          expa = expdiff + 1;
        }
        mant = (manta>>expa) - (mantb>>expb);
        k =  Q6_R_clb_P(mant)-1;
        mant = (mant << k);
        exp = exp - k;
        if (mant ==  0 || mant == -1)  exp = 0x8001;
        c = (mant & MANTMASK) | (((lint) exp) & EXP_MASK);
      return(c);
 }
 * ==================================================================== */
        .text
        .global fast2_ldsub_asm
        .type fast2_ldsub_asm, @function
fast2_ldsub_asm:
#define manta      R1:0
#define lmanta     R1:0
#define mantb      R3:2
#define lmantb     R3:2
#define expa       R4
#define expb       R5
#define expd       R6
#define exp        R8
#define c63        R9
#define lmant      R1:0
#define k          R4
#define ce         P0
#define zero       R3:2
        .falign
      {
        expa = memw(r29+#8)
        expb = memw(r29+#24)
        r7 = r0
      }
      {
        expd = sub(expa, expb):sat
        ce = CMP.GT(expa, expb);
        if ( ce.new) exp = add(expa, #1)
        if (!ce.new) exp = add(expb, #1)
      } {
        expd = abs(expd):sat
        if ( ce) expa = #1
        if (!ce) expb = #1
        c63 = #62
      } {
        expd = min(expd, c63)
        manta = memd(r29+#0)
        mantb = memd(r29+#16)
      } {
        if (!ce) expa = add(expd, #1)
        if ( ce) expb = add(expd, #1)
      } {
        lmanta = ASR(lmanta, expa)
        lmantb = ASR(lmantb, expb)
      } {
        lmant = sub(lmanta, lmantb)
        zero = #0
      } {
        k  = clb(lmant)
        c63.L =#0x0001
      } {
        exp -= add(k, #-1)  //exp =  exp - (k+1)
        k = add(k, #-1)
        p0 = cmp.gt(k, #58)
        c63.H =#0x8000
      } {
        if(!p0)memw(r7+#8) = exp
        lmant = asl(lmant, k)
        if(p0) jump .Ldenorma_s
      } {
        memd(r7+#0) = lmant
        jumpr  r31
      }
.Ldenorma_s:
        memd(r7+#0) = zero
      {
        memw(r7+#8) = c63
        jumpr  r31
      }

/* ==================================================================== *
 fast2_QLDOUBLE fast2_ldmpy(fast2_QLDOUBLE a,fast2_QLDOUBLE b) {
        fast2_QLDOUBLE c;
        lint manta = a & MANTMASK;
        int  expa  = Q6_R_sxth_R(a) ;
        lint mantb = b & MANTMASK;
        int  expb  = Q6_R_sxth_R(b) ;
        int exp, k;
        lint mant;
        int          hia, hib, hi, lo;
        unsigned int loa, lob;

        hia = (int)(a >> 32);
        loa = Q6_R_extractu_RII((int)manta, 31, 1);
        hib = (int)(b >> 32);
        lob = Q6_R_extractu_RII((int)mantb, 31, 1);

        mant = Q6_P_mpy_RR(hia, lob);
        mant = Q6_P_mpyacc_RR(mant,hib, loa);
        mant = (mant >> 30) + (Q6_P_mpy_RR(hia, hib)<<1);

        hi = (int) (mant>>32);

        k =  Q6_R_normamt_R(hi);
        mant = mant << k;
        exp = expa + expb - k;
        if (mant ==  0 || mant == -1)  exp = 0x8001;
        c = (mant & MANTMASK) | (((lint) exp) & EXP_MASK);
        return(c);
 }
 * ==================================================================== */
        .text
        .global fast2_ldmpy_asm
        .type fast2_ldmpy_asm, @function
fast2_ldmpy_asm:

#define mantxl_    R9
#define mantxl     R14
#define mantxh     R15
#define mantx      R15:14
#define mantbl     R2
#define mantbl_    R8
#define mantbh     R3
#define mantb      R3:2
#define expa       R4
#define expb       R5
#define c8001      R8
#define mantd      R7:6
#define lmantc     R11:10
#define kp         R9
#define min        R13:12
#define minh       R13
#define max        R13:12
#define maxh       R13
#define ret        R0

        .falign
      {
        mantx = memd(r29+#0)
        mantb = memd(r29+#16)
        min = #0
      }
      {
        mantbl_= extractu(mantbl, #31, #1)
        mantxl_= extractu(mantxl, #31, #1)
        minh.H = #0x8000
      }
      {
        lmantc = mpy(mantxh, mantbh)
        mantd = mpy(mantxh, mantbl_)
        expa = memw(r29+#8)
        expb = memw(r29+#24)
      }
      {
        lmantc = add(lmantc, lmantc)
        mantd += mpy(mantbh, mantxl_)
      }
      {
        mantd = asr(mantd, #30)
        c8001.L =  #0x0001
        p1 = cmp.eq(mantx, mantb)
      }
      {
        mantd = add(mantd, lmantc)
        expa= add(expa, expb)
        p2 = cmp.eq(mantb, min)
      }
      {
        kp  = clb(mantd)
        c8001.H =  #0x8000
        p1 = and(p1, p2)
      }
      {
        expa-= add(kp, #-1)
        kp = add(kp, #-1)
        if(p1) jump .Lsat
      }
      {
        mantd = asl(mantd, kp)
        memw(ret+#8) = expa
	p0 = cmp.gt(kp, #58)
        if(p0.new) jump:NT .Ldenorm   //rarely happens
      }
      {
        memd(ret+#0) = mantd
        jumpr  r31
      }
.Lsat:
      {
        max = #0
        expa+= add(kp, #1)
      }
      {
        maxh.H = #0x4000
        memw(ret+#8) = expa
      }
      {
        memd(ret+#0) = max
        jumpr  r31
      }
.Ldenorm:
      {
        memw(ret+#8) = c8001
        mantx = #0
      }
      {
        memd(ret+#0) = mantx
        jumpr  r31
      }