2.9
[glibc/nacl-glibc.git] / sysdeps / ia64 / fpu / s_log1pf.S
blob77e79c39df1ab56bcba9a4c8ac414e12fbe9b2ae
1 .file "log1pf.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
22 // permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://www.intel.com/software/products/opensource/libraries/num.htm.
40 // History
41 //==============================================================
42 // 02/02/00 Initial version
43 // 04/04/00 Unwind support added
44 // 08/15/00 Bundle added after call to __libm_error_support to properly
45 //          set [the previously overwritten] GR_Parameter_RESULT.
46 // 06/29/01 Improved speed of all paths
47 // 05/20/02 Cleaned up namespace and sf0 syntax
48 // 10/02/02 Improved performance by basing on log algorithm
49 // 02/10/03 Reordered header: .section, .global, .proc, .align
50 // 04/18/03 Eliminate possible WAW dependency warning
51 // 12/16/03 Fixed parameter passing to/from error handling routine
53 // API
54 //==============================================================
55 // float log1pf(float)
57 // log1p(x) = log(x+1)
59 // Overview of operation
60 //==============================================================
61 // Background
62 // ----------
64 // This algorithm is based on fact that
65 // log1p(x) = log(1+x) and
66 // log(a b) = log(a) + log(b).
67 // In our case we have 1+x = 2^N f, where 1 <= f < 2.
68 // So
69 //   log(1+x) = log(2^N f) = log(2^N) + log(f) = n*log(2) + log(f)
71 // To calculate log(f) we do following
72 //   log(f) = log(f * frcpa(f) / frcpa(f)) =
73 //          = log(f * frcpa(f)) + log(1/frcpa(f))
75 // According to definition of IA-64's frcpa instruction it's a
76 // floating point that approximates 1/f using a lookup on the
77 // top of 8 bits of the input number's + 1 significand with relative
78 // error < 2^(-8.886). So we have following
80 // |(1/f - frcpa(f)) / (1/f))| = |1 - f*frcpa(f)| < 1/256
82 // and
84 // log(f) = log(f * frcpa(f)) + log(1/frcpa(f)) =
85 //        = log(1 + r) + T
87 // The first value can be computed by polynomial P(r) approximating
88 // log(1 + r) on |r| < 1/256 and the second is precomputed tabular
89 // value defined by top 8 bit of f.
91 // Finally we have that  log(1+x) ~ (N*log(2) + T) + P(r)
93 // Note that if input argument is close to 0.0 (in our case it means
94 // that |x| < 1/256) we can use just polynomial approximation
95 // because 1+x = 2^0 * f = f = 1 + r and
96 // log(1+x) = log(1 + r) ~ P(r)
99 // Implementation
100 // --------------
102 // 1. |x| >= 2^(-8), and x > -1
103 //   InvX = frcpa(x+1)
104 //   r = InvX*(x+1) - 1
105 //   P(r) = r*((1 - A2*4) + r^2*(A3 - A4*r)) = r*P2(r),
106 //   A4,A3,A2 are created with setf instruction.
107 //   We use Taylor series and so A4 = 1/4, A3 = 1/3,
108 //   A2 = 1/2 rounded to double.
110 //   N = float(n) where n is true unbiased exponent of x
112 //   T is tabular value of log(1/frcpa(x)) calculated in quad precision
113 //   and rounded to double.  To load T we get bits from 55 to 62 of register
114 //   format significand as index and calculate address
115 //     ad_T = table_base_addr + 8 * index
117 //   L1 (log(2)) is calculated in quad precision and rounded to double;
118 //   it's created with setf
120 //   And final result = P2(r)*r + (T + N*L1)
123 // 2. 2^(-40) <= |x| < 2^(-8)
124 //   r = x
125 //   P(r) = r*((1 - A2*4) + r^2*(A3 - A4*r)) = r*P2(r),
126 //   A4,A3,A2 are the same as in case |x| >= 1/256
128 //   And final result = P2(r)*r
130 // 3. 0 < |x| < 2^(-40)
131 //   Although log1p(x) is basically x, we would like to preserve the inexactness
132 //   nature as well as consistent behavior under different rounding modes.
133 //   We can do this by computing the result as
135 //     log1p(x) = x - x*x
138 //    Note: NaT, any NaNs, +/-INF, +/-0, negatives and unnormalized numbers are
139 //          filtered and processed on special branches.
143 // Special values
144 //==============================================================
146 // log1p(-1)    = -inf            // Call error support
148 // log1p(+qnan) = +qnan
149 // log1p(-qnan) = -qnan
150 // log1p(+snan) = +qnan
151 // log1p(-snan) = -qnan
153 // log1p(x),x<-1= QNAN Indefinite // Call error support
154 // log1p(-inf)  = QNAN Indefinite
155 // log1p(+inf)  = +inf
156 // log1p(+/-0)  = +/-0
159 // Registers used
160 //==============================================================
161 // Floating Point registers used:
162 // f8, input
163 // f7 -> f15,  f32 -> f36
165 // General registers used:
166 // r8  -> r11
167 // r14 -> r22
169 // Predicate registers used:
170 // p6 -> p12
172 // Assembly macros
173 //==============================================================
174 GR_TAG                 = r8
175 GR_ad_T                = r9
176 GR_Exp                 = r10
177 GR_N                   = r11
179 GR_signexp_x           = r14
180 GR_exp_mask            = r15
181 GR_exp_bias            = r16
182 GR_05                  = r17
183 GR_A3                  = r18
184 GR_Sig                 = r19
185 GR_Ind                 = r19
186 GR_exp_x               = r20
187 GR_Ln2                 = r21
188 GR_025                 = r22
191 GR_SAVE_B0             = r33
192 GR_SAVE_PFS            = r34
193 GR_SAVE_GP             = r35
194 GR_SAVE_SP             = r36
196 GR_Parameter_X         = r37
197 GR_Parameter_Y         = r38
198 GR_Parameter_RESULT    = r39
199 GR_Parameter_TAG       = r40
203 FR_NormX               = f7
204 FR_RcpX                = f9
205 FR_r                   = f10
206 FR_r2                  = f11
207 FR_r4                  = f12
208 FR_N                   = f13
209 FR_Ln2                 = f14
210 FR_Xp1                 = f15
212 FR_A4                  = f33
213 FR_A3                  = f34
214 FR_A2                  = f35
216 FR_T                   = f36
217 FR_NxLn2pT             = f36
221 FR_Y                   = f1
222 FR_X                   = f10
223 FR_RESULT              = f8
226 // Data
227 //==============================================================
228 RODATA
229 .align 16
231 LOCAL_OBJECT_START(log_data)
232 // ln(1/frcpa(1+i/256)), i=0...255
233 data8 0x3F60040155D5889E // 0
234 data8 0x3F78121214586B54 // 1
235 data8 0x3F841929F96832F0 // 2
236 data8 0x3F8C317384C75F06 // 3
237 data8 0x3F91A6B91AC73386 // 4
238 data8 0x3F95BA9A5D9AC039 // 5
239 data8 0x3F99D2A8074325F4 // 6
240 data8 0x3F9D6B2725979802 // 7
241 data8 0x3FA0C58FA19DFAAA // 8
242 data8 0x3FA2954C78CBCE1B // 9
243 data8 0x3FA4A94D2DA96C56 // 10
244 data8 0x3FA67C94F2D4BB58 // 11
245 data8 0x3FA85188B630F068 // 12
246 data8 0x3FAA6B8ABE73AF4C // 13
247 data8 0x3FAC441E06F72A9E // 14
248 data8 0x3FAE1E6713606D07 // 15
249 data8 0x3FAFFA6911AB9301 // 16
250 data8 0x3FB0EC139C5DA601 // 17
251 data8 0x3FB1DBD2643D190B // 18
252 data8 0x3FB2CC7284FE5F1C // 19
253 data8 0x3FB3BDF5A7D1EE64 // 20
254 data8 0x3FB4B05D7AA012E0 // 21
255 data8 0x3FB580DB7CEB5702 // 22
256 data8 0x3FB674F089365A7A // 23
257 data8 0x3FB769EF2C6B568D // 24
258 data8 0x3FB85FD927506A48 // 25
259 data8 0x3FB9335E5D594989 // 26
260 data8 0x3FBA2B0220C8E5F5 // 27
261 data8 0x3FBB0004AC1A86AC // 28
262 data8 0x3FBBF968769FCA11 // 29
263 data8 0x3FBCCFEDBFEE13A8 // 30
264 data8 0x3FBDA727638446A2 // 31
265 data8 0x3FBEA3257FE10F7A // 32
266 data8 0x3FBF7BE9FEDBFDE6 // 33
267 data8 0x3FC02AB352FF25F4 // 34
268 data8 0x3FC097CE579D204D // 35
269 data8 0x3FC1178E8227E47C // 36
270 data8 0x3FC185747DBECF34 // 37
271 data8 0x3FC1F3B925F25D41 // 38
272 data8 0x3FC2625D1E6DDF57 // 39
273 data8 0x3FC2D1610C86813A // 40
274 data8 0x3FC340C59741142E // 41
275 data8 0x3FC3B08B6757F2A9 // 42
276 data8 0x3FC40DFB08378003 // 43
277 data8 0x3FC47E74E8CA5F7C // 44
278 data8 0x3FC4EF51F6466DE4 // 45
279 data8 0x3FC56092E02BA516 // 46
280 data8 0x3FC5D23857CD74D5 // 47
281 data8 0x3FC6313A37335D76 // 48
282 data8 0x3FC6A399DABBD383 // 49
283 data8 0x3FC70337DD3CE41B // 50
284 data8 0x3FC77654128F6127 // 51
285 data8 0x3FC7E9D82A0B022D // 52
286 data8 0x3FC84A6B759F512F // 53
287 data8 0x3FC8AB47D5F5A310 // 54
288 data8 0x3FC91FE49096581B // 55
289 data8 0x3FC981634011AA75 // 56
290 data8 0x3FC9F6C407089664 // 57
291 data8 0x3FCA58E729348F43 // 58
292 data8 0x3FCABB55C31693AD // 59
293 data8 0x3FCB1E104919EFD0 // 60
294 data8 0x3FCB94EE93E367CB // 61
295 data8 0x3FCBF851C067555F // 62
296 data8 0x3FCC5C0254BF23A6 // 63
297 data8 0x3FCCC000C9DB3C52 // 64
298 data8 0x3FCD244D99C85674 // 65
299 data8 0x3FCD88E93FB2F450 // 66
300 data8 0x3FCDEDD437EAEF01 // 67
301 data8 0x3FCE530EFFE71012 // 68
302 data8 0x3FCEB89A1648B971 // 69
303 data8 0x3FCF1E75FADF9BDE // 70
304 data8 0x3FCF84A32EAD7C35 // 71
305 data8 0x3FCFEB2233EA07CD // 72
306 data8 0x3FD028F9C7035C1C // 73
307 data8 0x3FD05C8BE0D9635A // 74
308 data8 0x3FD085EB8F8AE797 // 75
309 data8 0x3FD0B9C8E32D1911 // 76
310 data8 0x3FD0EDD060B78081 // 77
311 data8 0x3FD122024CF0063F // 78
312 data8 0x3FD14BE2927AECD4 // 79
313 data8 0x3FD180618EF18ADF // 80
314 data8 0x3FD1B50BBE2FC63B // 81
315 data8 0x3FD1DF4CC7CF242D // 82
316 data8 0x3FD214456D0EB8D4 // 83
317 data8 0x3FD23EC5991EBA49 // 84
318 data8 0x3FD2740D9F870AFB // 85
319 data8 0x3FD29ECDABCDFA04 // 86
320 data8 0x3FD2D46602ADCCEE // 87
321 data8 0x3FD2FF66B04EA9D4 // 88
322 data8 0x3FD335504B355A37 // 89
323 data8 0x3FD360925EC44F5D // 90
324 data8 0x3FD38BF1C3337E75 // 91
325 data8 0x3FD3C25277333184 // 92
326 data8 0x3FD3EDF463C1683E // 93
327 data8 0x3FD419B423D5E8C7 // 94
328 data8 0x3FD44591E0539F49 // 95
329 data8 0x3FD47C9175B6F0AD // 96
330 data8 0x3FD4A8B341552B09 // 97
331 data8 0x3FD4D4F3908901A0 // 98
332 data8 0x3FD501528DA1F968 // 99
333 data8 0x3FD52DD06347D4F6 // 100
334 data8 0x3FD55A6D3C7B8A8A // 101
335 data8 0x3FD5925D2B112A59 // 102
336 data8 0x3FD5BF406B543DB2 // 103
337 data8 0x3FD5EC433D5C35AE // 104
338 data8 0x3FD61965CDB02C1F // 105
339 data8 0x3FD646A84935B2A2 // 106
340 data8 0x3FD6740ADD31DE94 // 107
341 data8 0x3FD6A18DB74A58C5 // 108
342 data8 0x3FD6CF31058670EC // 109
343 data8 0x3FD6F180E852F0BA // 110
344 data8 0x3FD71F5D71B894F0 // 111
345 data8 0x3FD74D5AEFD66D5C // 112
346 data8 0x3FD77B79922BD37E // 113
347 data8 0x3FD7A9B9889F19E2 // 114
348 data8 0x3FD7D81B037EB6A6 // 115
349 data8 0x3FD8069E33827231 // 116
350 data8 0x3FD82996D3EF8BCB // 117
351 data8 0x3FD85855776DCBFB // 118
352 data8 0x3FD8873658327CCF // 119
353 data8 0x3FD8AA75973AB8CF // 120
354 data8 0x3FD8D992DC8824E5 // 121
355 data8 0x3FD908D2EA7D9512 // 122
356 data8 0x3FD92C59E79C0E56 // 123
357 data8 0x3FD95BD750EE3ED3 // 124
358 data8 0x3FD98B7811A3EE5B // 125
359 data8 0x3FD9AF47F33D406C // 126
360 data8 0x3FD9DF270C1914A8 // 127
361 data8 0x3FDA0325ED14FDA4 // 128
362 data8 0x3FDA33440224FA79 // 129
363 data8 0x3FDA57725E80C383 // 130
364 data8 0x3FDA87D0165DD199 // 131
365 data8 0x3FDAAC2E6C03F896 // 132
366 data8 0x3FDADCCC6FDF6A81 // 133
367 data8 0x3FDB015B3EB1E790 // 134
368 data8 0x3FDB323A3A635948 // 135
369 data8 0x3FDB56FA04462909 // 136
370 data8 0x3FDB881AA659BC93 // 137
371 data8 0x3FDBAD0BEF3DB165 // 138
372 data8 0x3FDBD21297781C2F // 139
373 data8 0x3FDC039236F08819 // 140
374 data8 0x3FDC28CB1E4D32FD // 141
375 data8 0x3FDC4E19B84723C2 // 142
376 data8 0x3FDC7FF9C74554C9 // 143
377 data8 0x3FDCA57B64E9DB05 // 144
378 data8 0x3FDCCB130A5CEBB0 // 145
379 data8 0x3FDCF0C0D18F326F // 146
380 data8 0x3FDD232075B5A201 // 147
381 data8 0x3FDD490246DEFA6B // 148
382 data8 0x3FDD6EFA918D25CD // 149
383 data8 0x3FDD9509707AE52F // 150
384 data8 0x3FDDBB2EFE92C554 // 151
385 data8 0x3FDDEE2F3445E4AF // 152
386 data8 0x3FDE148A1A2726CE // 153
387 data8 0x3FDE3AFC0A49FF40 // 154
388 data8 0x3FDE6185206D516E // 155
389 data8 0x3FDE882578823D52 // 156
390 data8 0x3FDEAEDD2EAC990C // 157
391 data8 0x3FDED5AC5F436BE3 // 158
392 data8 0x3FDEFC9326D16AB9 // 159
393 data8 0x3FDF2391A2157600 // 160
394 data8 0x3FDF4AA7EE03192D // 161
395 data8 0x3FDF71D627C30BB0 // 162
396 data8 0x3FDF991C6CB3B379 // 163
397 data8 0x3FDFC07ADA69A910 // 164
398 data8 0x3FDFE7F18EB03D3E // 165
399 data8 0x3FE007C053C5002E // 166
400 data8 0x3FE01B942198A5A1 // 167
401 data8 0x3FE02F74400C64EB // 168
402 data8 0x3FE04360BE7603AD // 169
403 data8 0x3FE05759AC47FE34 // 170
404 data8 0x3FE06B5F1911CF52 // 171
405 data8 0x3FE078BF0533C568 // 172
406 data8 0x3FE08CD9687E7B0E // 173
407 data8 0x3FE0A10074CF9019 // 174
408 data8 0x3FE0B5343A234477 // 175
409 data8 0x3FE0C974C89431CE // 176
410 data8 0x3FE0DDC2305B9886 // 177
411 data8 0x3FE0EB524BAFC918 // 178
412 data8 0x3FE0FFB54213A476 // 179
413 data8 0x3FE114253DA97D9F // 180
414 data8 0x3FE128A24F1D9AFF // 181
415 data8 0x3FE1365252BF0865 // 182
416 data8 0x3FE14AE558B4A92D // 183
417 data8 0x3FE15F85A19C765B // 184
418 data8 0x3FE16D4D38C119FA // 185
419 data8 0x3FE18203C20DD133 // 186
420 data8 0x3FE196C7BC4B1F3B // 187
421 data8 0x3FE1A4A738B7A33C // 188
422 data8 0x3FE1B981C0C9653D // 189
423 data8 0x3FE1CE69E8BB106B // 190
424 data8 0x3FE1DC619DE06944 // 191
425 data8 0x3FE1F160A2AD0DA4 // 192
426 data8 0x3FE2066D7740737E // 193
427 data8 0x3FE2147DBA47A394 // 194
428 data8 0x3FE229A1BC5EBAC3 // 195
429 data8 0x3FE237C1841A502E // 196
430 data8 0x3FE24CFCE6F80D9A // 197
431 data8 0x3FE25B2C55CD5762 // 198
432 data8 0x3FE2707F4D5F7C41 // 199
433 data8 0x3FE285E0842CA384 // 200
434 data8 0x3FE294294708B773 // 201
435 data8 0x3FE2A9A2670AFF0C // 202
436 data8 0x3FE2B7FB2C8D1CC1 // 203
437 data8 0x3FE2C65A6395F5F5 // 204
438 data8 0x3FE2DBF557B0DF43 // 205
439 data8 0x3FE2EA64C3F97655 // 206
440 data8 0x3FE3001823684D73 // 207
441 data8 0x3FE30E97E9A8B5CD // 208
442 data8 0x3FE32463EBDD34EA // 209
443 data8 0x3FE332F4314AD796 // 210
444 data8 0x3FE348D90E7464D0 // 211
445 data8 0x3FE35779F8C43D6E // 212
446 data8 0x3FE36621961A6A99 // 213
447 data8 0x3FE37C299F3C366A // 214
448 data8 0x3FE38AE2171976E7 // 215
449 data8 0x3FE399A157A603E7 // 216
450 data8 0x3FE3AFCCFE77B9D1 // 217
451 data8 0x3FE3BE9D503533B5 // 218
452 data8 0x3FE3CD7480B4A8A3 // 219
453 data8 0x3FE3E3C43918F76C // 220
454 data8 0x3FE3F2ACB27ED6C7 // 221
455 data8 0x3FE4019C2125CA93 // 222
456 data8 0x3FE4181061389722 // 223
457 data8 0x3FE42711518DF545 // 224
458 data8 0x3FE436194E12B6BF // 225
459 data8 0x3FE445285D68EA69 // 226
460 data8 0x3FE45BCC464C893A // 227
461 data8 0x3FE46AED21F117FC // 228
462 data8 0x3FE47A1527E8A2D3 // 229
463 data8 0x3FE489445EFFFCCC // 230
464 data8 0x3FE4A018BCB69835 // 231
465 data8 0x3FE4AF5A0C9D65D7 // 232
466 data8 0x3FE4BEA2A5BDBE87 // 233
467 data8 0x3FE4CDF28F10AC46 // 234
468 data8 0x3FE4DD49CF994058 // 235
469 data8 0x3FE4ECA86E64A684 // 236
470 data8 0x3FE503C43CD8EB68 // 237
471 data8 0x3FE513356667FC57 // 238
472 data8 0x3FE522AE0738A3D8 // 239
473 data8 0x3FE5322E26867857 // 240
474 data8 0x3FE541B5CB979809 // 241
475 data8 0x3FE55144FDBCBD62 // 242
476 data8 0x3FE560DBC45153C7 // 243
477 data8 0x3FE5707A26BB8C66 // 244
478 data8 0x3FE587F60ED5B900 // 245
479 data8 0x3FE597A7977C8F31 // 246
480 data8 0x3FE5A760D634BB8B // 247
481 data8 0x3FE5B721D295F10F // 248
482 data8 0x3FE5C6EA94431EF9 // 249
483 data8 0x3FE5D6BB22EA86F6 // 250
484 data8 0x3FE5E6938645D390 // 251
485 data8 0x3FE5F673C61A2ED2 // 252
486 data8 0x3FE6065BEA385926 // 253
487 data8 0x3FE6164BFA7CC06B // 254
488 data8 0x3FE62643FECF9743 // 255
489 LOCAL_OBJECT_END(log_data)
492 // Code
493 //==============================================================
495 .section .text
496 GLOBAL_IEEE754_ENTRY(log1pf)
497 { .mfi
498       getf.exp      GR_signexp_x = f8 // if x is unorm then must recompute
499       fadd.s1       FR_Xp1 = f8, f1       // Form 1+x
500       mov           GR_05 = 0xfffe
502 { .mlx
503       addl          GR_ad_T = @ltoff(log_data),gp
504       movl          GR_A3 = 0x3fd5555555555555 // double precision memory
505                                                // representation of A3
509 { .mfi
510       ld8           GR_ad_T = [GR_ad_T]
511       fclass.m      p8,p0 = f8,0xb // Is x unorm?
512       mov           GR_exp_mask = 0x1ffff
514 { .mfi
515       mov           GR_025 = 0xfffd            // Exponent of 0.25
516       fnorm.s1      FR_NormX = f8              // Normalize x
517       mov           GR_exp_bias = 0xffff
521 { .mfi
522       setf.exp      FR_A2 = GR_05 // create A2 = 0.5
523       fclass.m      p9,p0 = f8,0x1E1 // is x NaN, NaT or +Inf?
524       nop.i         0
526 { .mib
527       setf.d        FR_A3 = GR_A3 // create A3
528       nop.i         0
529 (p8)  br.cond.spnt  log1p_unorm          // Branch if x=unorm
533 log1p_common:
534 { .mfi
535       setf.exp      FR_A4 = GR_025 // create A4 = 0.25
536       frcpa.s1      FR_RcpX,p0 = f1,FR_Xp1
537       nop.i         0
539 { .mfb
540       nop.m         0
541 (p9)  fma.s.s0      f8 = f8,f1,f0 // set V-flag
542 (p9)  br.ret.spnt   b0 // exit for NaN, NaT and +Inf
546 { .mfi
547       getf.exp      GR_Exp = FR_Xp1            // signexp of x+1
548       fclass.m      p10,p0 = FR_Xp1,0x3A // is 1+x < 0?
549       and           GR_exp_x = GR_exp_mask, GR_signexp_x // biased exponent of x
551 { .mlx
552       nop.m         0
553       movl          GR_Ln2 = 0x3FE62E42FEFA39EF // double precision memory
554                                                 // representation of log(2)
558 { .mfi
559       getf.sig      GR_Sig = FR_Xp1 // get significand to calculate index
560                                     // for T if |x| >= 2^-8
561       fcmp.eq.s1    p12,p0 = f8,f0     // is x equal to 0?
562       sub           GR_exp_x = GR_exp_x, GR_exp_bias // true exponent of x
566 { .mfi
567       sub           GR_N = GR_Exp,GR_exp_bias // true exponent of x+1
568       fcmp.eq.s1    p11,p0 = FR_Xp1,f0     // is x = -1?
569       cmp.gt        p6,p7 = -8, GR_exp_x  // Is |x| < 2^-8
571 { .mfb
572       nop.m         0
573       nop.f         0
574 (p10) br.cond.spnt  log1p_lt_minus_1   // jump if x < -1
578 // p6 is true if |x| < 1/256
579 // p7 is true if |x| >= 1/256
580 .pred.rel "mutex",p6,p7
581 { .mfi
582       nop.m         0
583 (p6)  fms.s1        FR_r = f8,f1,f0 // range reduction for |x|<1/256
584 (p6)  cmp.gt.unc    p10,p0 = -40, GR_exp_x  // Is |x| < 2^-40
586 { .mfb
587 (p7)  setf.sig      FR_N = GR_N // copy unbiased exponent of x to the
588                                 // significand field of FR_N
589 (p7)  fms.s1        FR_r = FR_RcpX,FR_Xp1,f1 // range reduction for |x|>=1/256
590 (p12) br.ret.spnt   b0 // exit for x=0, return x
594 { .mib
595       setf.d        FR_Ln2 = GR_Ln2 // create log(2)
596 (p7)  extr.u        GR_Ind = GR_Sig,55,8 // get bits from 55 to 62 as index
597 (p11) br.cond.spnt  log1p_eq_minus_1 // jump if x = -1
601 { .mmf
602 (p7)  shladd        GR_ad_T = GR_Ind,3,GR_ad_T // address of T
603       nop.m         0
604 (p10) fnma.s.s0     f8 = f8,f8,f8   // If |x| very small, result=x-x*x
608 { .mmb
609 (p7)  ldfd          FR_T = [GR_ad_T]
610       nop.m         0
611 (p10) br.ret.spnt   b0              // Exit if |x| < 2^-40
615 { .mfi
616       nop.m         0
617       fma.s1        FR_r2 = FR_r,FR_r,f0 // r^2
618       nop.i         0
620 { .mfi
621       nop.m         0
622       fnma.s1       FR_A2 = FR_A2,FR_r,f1      // 1.0 - A2*r
623       nop.i         0
627 { .mfi
628       nop.m         0
629       fnma.s1       FR_A3 = FR_A4,FR_r,FR_A3 // A3 - A4*r
630       nop.i         0
634 { .mfi
635       nop.m         0
636 (p7)  fcvt.xf       FR_N = FR_N
637       nop.i         0
641 { .mfi
642       nop.m         0
643       // (A3*r+A2)*r^2+r
644       fma.s1        FR_A2 = FR_A3,FR_r2,FR_A2 // (A4*r+A3)*r^2+(A2*r+1)
645       nop.i         0
649 { .mfi
650       nop.m         0
651       // N*Ln2hi+T
652 (p7)  fma.s1        FR_NxLn2pT = FR_N,FR_Ln2,FR_T
653       nop.i         0
657 .pred.rel "mutex",p6,p7
658 { .mfi
659       nop.m         0
660 (p6)  fma.s.s0      f8 = FR_A2,FR_r,f0 // result if 2^(-40) <= |x| < 1/256
661       nop.i         0
663 { .mfb
664       nop.m         0
665 (p7)  fma.s.s0      f8 = FR_A2,FR_r,FR_NxLn2pT  // result if |x| >= 1/256
666       br.ret.sptk   b0                          // Exit if |x| >= 2^(-40)
670 .align 32
671 log1p_unorm:
672 // Here if x=unorm
673 { .mfb
674       getf.exp      GR_signexp_x = FR_NormX // recompute biased exponent
675       nop.f         0
676       br.cond.sptk  log1p_common
680 .align 32
681 log1p_eq_minus_1:
682 // Here if x=-1
683 { .mfi
684       nop.m         0
685       fmerge.s      FR_X = f8,f8 // keep input argument for subsequent
686                                  // call of __libm_error_support#
687       nop.i         0
691 { .mfi
692       mov           GR_TAG = 142  // set libm error in case of log1p(-1).
693       frcpa.s0      f8,p0 = f8,f0 // log1p(-1) should be equal to -INF.
694                                       // We can get it using frcpa because it
695                                       // sets result to the IEEE-754 mandated
696                                       // quotient of f8/f0.
697       nop.i         0
699 { .mib
700       nop.m         0
701       nop.i         0
702       br.cond.sptk  log_libm_err
706 .align 32
707 log1p_lt_minus_1:
708 // Here if x < -1
709 { .mfi
710       nop.m         0
711       fmerge.s      FR_X = f8,f8
712       nop.i         0
716 { .mfi
717       mov           GR_TAG = 143  // set libm error in case of x < -1.
718       frcpa.s0      f8,p0 = f0,f0 // log1p(x) x < -1 should be equal to NaN.
719                                   // We can get it using frcpa because it
720                                   // sets result to the IEEE-754 mandated
721                                   // quotient of f0/f0 i.e. NaN.
722       nop.i         0
726 .align 32
727 log_libm_err:
728 { .mmi
729       alloc         r32 = ar.pfs,1,4,4,0
730       mov           GR_Parameter_TAG = GR_TAG
731       nop.i         0
735 GLOBAL_IEEE754_END(log1pf)
738 LOCAL_LIBM_ENTRY(__libm_error_region)
739 .prologue
740 { .mfi
741         add   GR_Parameter_Y = -32,sp         // Parameter 2 value
742         nop.f 0
743 .save   ar.pfs,GR_SAVE_PFS
744         mov  GR_SAVE_PFS = ar.pfs             // Save ar.pfs
746 { .mfi
747 .fframe 64
748         add sp = -64,sp                       // Create new stack
749         nop.f 0
750         mov GR_SAVE_GP = gp                   // Save gp
752 { .mmi
753         stfs [GR_Parameter_Y] = FR_Y,16       // STORE Parameter 2 on stack
754         add GR_Parameter_X = 16,sp            // Parameter 1 address
755 .save   b0, GR_SAVE_B0
756         mov GR_SAVE_B0 = b0                   // Save b0
758 .body
759 { .mib
760         stfs [GR_Parameter_X] = FR_X          // STORE Parameter 1 on stack
761         add   GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
762         nop.b 0
764 { .mib
765         stfs [GR_Parameter_Y] = FR_RESULT     // STORE Parameter 3 on stack
766         add   GR_Parameter_Y = -16,GR_Parameter_Y
767         br.call.sptk b0=__libm_error_support# // Call error handling function
769 { .mmi
770         add   GR_Parameter_RESULT = 48,sp
771         nop.m 0
772         nop.i 0
774 { .mmi
775         ldfs  f8 = [GR_Parameter_RESULT]      // Get return result off stack
776 .restore sp
777         add   sp = 64,sp                      // Restore stack pointer
778         mov   b0 = GR_SAVE_B0                 // Restore return address
780 { .mib
781         mov   gp = GR_SAVE_GP                 // Restore gp
782         mov   ar.pfs = GR_SAVE_PFS            // Restore ar.pfs
783         br.ret.sptk     b0                    // Return
785 LOCAL_LIBM_END(__libm_error_region)
787 .type   __libm_error_support#,@function
788 .global __libm_error_support#