4 // Copyright (c) 2001 - 2005, Intel Corporation
5 // All rights reserved.
7 // Contributed 2001 by the Intel Numerics Group, Intel Corporation
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
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
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.
41 //==============================================================
42 // 08/14/01 Initial version
43 // 05/20/02 Cleaned up namespace and sf0 syntax
44 // 02/06/03 Reordered header: .section, .global, .proc, .align
45 // 03/31/05 Reformatted delimiters between data tables
48 //==============================================================
51 // Overview of operation
52 //==============================================================
58 // Return erff(x) = +/-0.0
60 // 2. 0.0 < |x| < 0.125
61 // Return erff(x) = x *Pol3(x^2),
62 // where Pol3(x^2) = C3*x^6 + C2*x^4 + C1*x^2 + C0
64 // 3. 0.125 <= |x| < 4.0
65 // Return erff(x) = sign(x)*PolD(x)*PolC(|x|) + sign(x)*PolA(|x|),
66 // where sign(x)*PolD(x) = sign(x)*(|x|^7 + D2*x^6 + D1*|x|^5 + D0*x^4),
67 // PolC(|x|) = B0*x^4 + C3*|x|^3 + C2*|x|^2 + C1*|x| + C0,
68 // PolA(|x|) = A3|x|^3 + A2*x^2 + A1*|x| + A0
70 // Actually range 0.125<=|x|< 4.0 is splitted to 5 subranges.
71 // For each subrange there is particular set of coefficients.
72 // Below is the list of subranges:
73 // 3.1 0.125 <= |x| < 0.25
74 // 3.2 0.25 <= |x| < 0.5
75 // 3.3 0.5 <= |x| < 1.0
76 // 3.4 1.0 <= |x| < 2.0
77 // 3.5 2.0 <= |x| < 4.0
79 // 4. 4.0 <= |x| < +INF
80 // Return erff(x) = sign(x)*(1.0d - 2^(-52))
83 // Return erff(x) = sign(x) * 1.0
86 // Return erff(x) = QNaN
88 // 7. x is positive denormal
89 // Return erff(x) = C0*x - x^2,
90 // where C0 = 2.0/sqrt(Pi)
92 // 8. x is negative denormal
93 // Return erff(x) = C0*x + x^2,
94 // where C0 = 2.0/sqrt(Pi)
97 //==============================================================
98 // Floating Point registers used:
102 // General registers used:
103 // r32 -> r45, r2, r3
105 // Predicate registers used:
106 // p0, p6 -> p12, p14, p15
108 // p6 to filter out case when x = [Q,S]NaN or +/-0
109 // p7 to filter out case when x = denormal
110 // p8 set if |x| >= 0.3125, used also to process denormal input
111 // p9 to filter out case when |x| = inf
112 // p10 to filter out case when |x| < 0.125
113 // p11 to filter out case when 0.125 <= |x| < 4.0
114 // p12 to filter out case when |x| >= 4.0
115 // p14 set to 1 for positive x
116 // p15 set to 1 for negative x
119 //==============================================================
137 //==============================================================
168 //==============================================================
174 LOCAL_OBJECT_START(erff_data)
175 // Polynomial coefficients for the erf(x), 0.125 <= |x| < 0.25
176 data8 0xBE4218BB56B49E66 // C0
177 data8 0x3F7AFB8315DA322B // C1
178 data8 0x3F615D6EBEE0CA32 // C2
179 data8 0xBF468D71CF4F0918 // C3
180 data8 0x40312115B0932F24 // D0
181 data8 0xC0160D6CD0991EA3 // D1
182 data8 0xBFE04A567A6DBE4A // D2
183 data8 0xBF4207BC640D1509 // B0
184 // Polynomial coefficients for the erf(x), 0.25 <= |x| < 0.5
185 data8 0x3F90849356383F58 // C0
186 data8 0x3F830BD5BA240F09 // C1
187 data8 0xBF3FA4970E2BCE23 // C2
188 data8 0xBF6061798E58D0FD // C3
189 data8 0xBF68C0D83DD22E02 // D0
190 data8 0x401C0A9EE4108F94 // D1
191 data8 0xC01056F9B5E387F5 // D2
192 data8 0x3F1C9744E36A5706 // B0
193 // Polynomial coefficients for the erf(x), 0.5 <= |x| < 1.0
194 data8 0x3F85F7D419A13DE3 // C0
195 data8 0x3F791A13FF66D45A // C1
196 data8 0x3F46B17B16B5929F // C2
197 data8 0xBF5124947A8BF45E // C3
198 data8 0x3FA1B3FD95EA9564 // D0
199 data8 0x40250CECD79A020A // D1
200 data8 0xC0190DC96FF66CCD // D2
201 data8 0x3F4401AE28BA4DD5 // B0
202 // Polynomial coefficients for the erf(x), 1.0 <= |x| < 2.0
203 data8 0xBF49E07E3584C3AE // C0
204 data8 0x3F3166621131445C // C1
205 data8 0xBF65B7FC1EAC2099 // C2
206 data8 0x3F508C6BD211D736 // C3
207 data8 0xC053FABD70601067 // D0
208 data8 0x404A06640EE87808 // D1
209 data8 0xC0283F30817A3F08 // D2
210 data8 0xBF2F6DBBF4D6257F // B0
211 // Polynomial coefficients for the erf(x), 2.0 <= |x| < 4.0
212 data8 0xBF849855D67E9407 // C0
213 data8 0x3F5ECA5FEC01C70C // C1
214 data8 0xBF483110C30FABA4 // C2
215 data8 0x3F1618DA72860403 // C3
216 data8 0xC08A5C9D5FE8B9F6 // D0
217 data8 0x406EFF5F088CEC4B // D1
218 data8 0xC03A5743DF38FDE0 // D2
219 data8 0xBEE397A9FA5686A2 // B0
220 // Polynomial coefficients for the erf(x), -0.125 < x < 0.125
221 data8 0x3FF20DD7504270CB // C0
222 data8 0xBFD8127465AFE719 // C1
223 data8 0x3FBCE2D77791DD77 // C2
224 data8 0xBF9B582755CDF345 // C3
225 // Polynomial coefficients for the erf(x), 0.125 <= |x| < 0.25
226 data8 0xBD54E7E451AF0E36 // A0
227 data8 0x3FF20DD75043FE20 // A1
228 data8 0xBE05680ACF8280E4 // A2
229 data8 0xBFD812745E92C3D3 // A3
230 // Polynomial coefficients for the erf(x), 0.25 <= |x| < 0.5
231 data8 0xBE1ACEC2859CB55F // A0
232 data8 0x3FF20DD75E8D2B64 // A1
233 data8 0xBEABC6A83208FCFC // A2
234 data8 0xBFD81253E42E7B99 // A3
235 // Polynomial coefficients for the erf(x), 0.5 <= |x| < 1.0
236 data8 0x3EABD5A2482B4979 // A0
237 data8 0x3FF20DCAA52085D5 // A1
238 data8 0x3F13A994A348795B // A2
239 data8 0xBFD8167B2DFCDE44 // A3
240 // Polynomial coefficients for the erf(x), 1.0 <= |x| < 2.0
241 data8 0xBF5BA377DDAB4E17 // A0
242 data8 0x3FF2397F1D8FC0ED // A1
243 data8 0xBF9945BFC1915C21 // A2
244 data8 0xBFD747AAABB690D8 // A3
245 // Polynomial coefficients for the erf(x), 2.0 <= |x| < 4.0
246 data8 0x3FF0E2920E0391AF // A0
247 data8 0xC00D249D1A95A5AE // A1
248 data8 0x40233905061C3803 // A2
249 data8 0xC027560B851F7690 // A3
251 data8 0x3FEFFFFFFFFFFFFF // 1.0 - epsilon
252 data8 0x3FF20DD750429B6D // C0 = 2.0/sqrt(Pi)
253 LOCAL_OBJECT_END(erff_data)
257 GLOBAL_LIBM_ENTRY(erff)
260 alloc r32 = ar.pfs, 0, 14, 0, 0
261 fmerge.s fAbsArg = f1, f8 // |x|
262 addl rMask = 0x806, r0
265 addl rDataPtr = @ltoff(erff_data), gp
266 fma.s1 fArgSqr = f8, f8, f0 // x^2
267 adds rSignBit = 0x1, r0
272 getf.s rArg = f8 // x in GR
273 fclass.m p7,p0 = f8, 0x0b // is x denormal ?
274 // sign bit and 2 most bits in significand
275 shl rMask = rMask, 20
278 ld8 rDataPtr = [rDataPtr]
280 adds rBias2 = 0x1F0, r0
286 fmerge.s fSignumX = f8, f1 // signum(x)
287 shl rSignBit = rSignBit, 31 // mask for sign bit
290 adds rBound = 0x3E0, r0
292 adds rSaturation = 0x408, r0
297 andcm rOffset2 = rArg, rMask
298 fclass.m p6,p0 = f8, 0xc7 // is x [S,Q]NaN or +/-0 ?
299 shl rBound = rBound, 20 // 0.125f in GR
302 andcm rAbsArg = rArg, rSignBit // |x| in GR
304 (p7) br.cond.spnt erff_denormal // branch out if x is denormal
309 adds rCoeffAddr2 = 352, rDataPtr
310 fclass.m p9,p0 = f8, 0x23 // is x +/- inf?
311 shr rOffset2 = rOffset2, 21
314 cmp.lt p10, p8 = rAbsArg, rBound // |x| < 0.125?
316 adds rCoeffAddr3 = 16, rDataPtr
321 (p8) sub rBias = rOffset2, rBias2
322 fma.s1 fArg4 = fArgSqr, fArgSqr, f0 // x^4
323 shl rSaturation = rSaturation, 20// 4.0 in GR (saturation bound)
326 (p10) adds rBias = 0x14, r0
327 (p6) fma.s.s0 f8 = f8,f1,f8 // NaN or +/-0
328 (p6) br.ret.spnt b0 // exit for x = NaN or +/-0
333 shladd rCoeffAddr1 = rBias, 4, rDataPtr
334 fma.s1 fArg3Sgn = fArgSqr, f8, f0 // sign(x)*|x|^3
336 cmp.lt p11, p12 = rAbsArg, rSaturation
339 shladd rCoeffAddr3 = rBias, 4, rCoeffAddr3
340 fma.s1 fArg3 = fArgSqr, fAbsArg, f0 // |x|^3
341 shladd rCoeffAddr2 = rBias, 3, rCoeffAddr2
346 (p11) ldfpd fC0, fC1 = [rCoeffAddr1]
347 (p9) fmerge.s f8 = f8,f1 // +/- inf
348 (p12) adds rDataPtr = 512, rDataPtr
351 (p11) ldfpd fC2, fC3 = [rCoeffAddr3], 16
353 (p9) br.ret.spnt b0 // exit for x = +/- inf
358 (p11) ldfpd fA0, fA1 = [rCoeffAddr2], 16
363 add rCoeffAddr1 = 48, rCoeffAddr1
370 (p11) ldfpd fD0, fD1 = [rCoeffAddr3]
375 (p11) ldfpd fD2, fB0 = [rCoeffAddr1]
377 fma.s1 fArgSqrSgn = fArgSqr, fSignumX, f0
378 (p10) br.cond.spnt erff_near_zero
383 (p11) ldfpd fA2, fA3 = [rCoeffAddr2], 16
384 fcmp.lt.s1 p15, p14 = f8,f0
388 (p12) ldfd fA0 = [rDataPtr]
389 fma.s1 fArg4Sgn = fArg4, fSignumX, f0 // sign(x)*|x|^4
390 (p12) br.cond.spnt erff_saturation
395 fma.s1 fArg7Sgn = fArg4, fArg3Sgn, f0 // sign(x)*|x|^7
400 fma.s1 fArg6Sgn = fArg3, fArg3Sgn, f0 // sign(x)*|x|^6
407 fma.s1 fPolC = fC3, fAbsArg, fC2 // C3*|x| + C2
412 fma.s1 fPolCTmp = fC1, fAbsArg, fC0 // C1*|x| + C0
418 fma.s1 fPolA = fA1, fAbsArg, fA0 // A1*|x| + A0
425 fma.s1 fPolD = fD1, fAbsArg, fD0 // D1*|x| + D0
430 // sign(x)*(|x|^7 + D2*x^6)
431 fma.s1 fPolDTmp = fArg6Sgn, fD2, fArg7Sgn
437 fma.s1 fPolATmp = fA3, fAbsArg, fA2 // A3*|x| + A2
442 fma.s1 fB0 = fB0, fArg4, f0 // B0*x^4
448 // C3*|x|^3 + C2*x^2 + C1*|x| + C0
449 fma.s1 fPolC = fPolC, fArgSqr, fPolCTmp
456 // PolD = sign(x)*(|x|^7 + D2*x^6 + D1*|x|^5 + D0*x^4)
457 fma.d.s1 fPolD = fPolD, fArg4Sgn, fPolDTmp
464 // PolA = A3|x|^3 + A2*x^2 + A1*|x| + A0
465 fma.d.s1 fPolA = fPolATmp, fArgSqr, fPolA
472 // PolC = B0*x^4 + C3*|x|^3 + C2*|x|^2 + C1*|x| + C0
473 fma.d.s1 fPolC = fPolC, f1, fB0
480 (p14) fma.s.s0 f8 = fPolC, fPolD, fPolA // for positive x
485 (p15) fms.s.s0 f8 = fPolC, fPolD, fPolA // for negative x
486 br.ret.sptk b0 // Exit for 0.125 <=|x|< 4.0
490 // Here if |x| < 0.125
494 fma.s1 fPolC = fC3, fArgSqr, fC2 // C3*x^2 + C2
499 fma.s1 fPolCTmp = fC1, fArgSqr, fC0 // C1*x^2 + C0
505 fma.s1 fPolC = fPolC, fArg4, fPolCTmp // C3*x^6 + C2*x^4 + C1*x^2 + C0
511 // x*(C3*x^6 + C2*x^4 + C1*x^2 + C0)
512 fma.s.s0 f8 = fPolC, f8, f0
513 br.ret.sptk b0 // Exit for |x| < 0.125
516 // Here if 4.0 <= |x| < +inf
520 fma.s.s0 f8 = fA0, fSignumX, f0 // sign(x)*(1.0d - 2^(-52))
521 // Exit for 4.0 <= |x| < +inf
522 br.ret.sptk b0 // Exit for 4.0 <=|x|< +inf
526 // Here if x is single precision denormal
529 adds rDataPtr = 520, rDataPtr // address of C0
530 fclass.m p7,p8 = f8, 0x0a // is x -denormal ?
535 ldfd fC0 = [rDataPtr] // C0
542 fma.s1 fC0 = fC0,f8,f0 // C0*x
548 (p7) fma.s.s0 f8 = f8,f8,fC0 // -denormal
553 (p8) fnma.s.s0 f8 = f8,f8,fC0 // +denormal
554 br.ret.sptk b0 // Exit for denormal
558 GLOBAL_LIBM_END(erff)