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