1.file "acos.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// 08/17/00 New and much faster algorithm. 43// 08/30/00 Avoided bank conflicts on loads, shortened |x|=1 and x=0 paths, 44// fixed mfb split issue stalls. 45// 05/20/02 Cleaned up namespace and sf0 syntax 46// 08/02/02 New and much faster algorithm II 47// 02/06/03 Reordered header: .section, .global, .proc, .align 48 49// Description 50//========================================= 51// The acos function computes the principal value of the arc cosine of x. 52// acos(0) returns Pi/2, acos(1) returns 0, acos(-1) returns Pi. 53// A doman error occurs for arguments not in the range [-1,+1]. 54// 55// The acos function returns the arc cosine in the range [0, Pi] radians. 56// 57// There are 8 paths: 58// 1. x = +/-0.0 59// Return acos(x) = Pi/2 + x 60// 61// 2. 0.0 < |x| < 0.625 62// Return acos(x) = Pi/2 - x - x^3 *PolA(x^2) 63// where PolA(x^2) = A3 + A5*x^2 + A7*x^4 +...+ A35*x^32 64// 65// 3. 0.625 <=|x| < 1.0 66// Return acos(x) = Pi/2 - asin(x) = 67// = Pi/2 - sign(x) * ( Pi/2 - sqrt(R) * PolB(R)) 68// Where R = 1 - |x|, 69// PolB(R) = B0 + B1*R + B2*R^2 +...+B12*R^12 70// 71// sqrt(R) is approximated using the following sequence: 72// y0 = (1 + eps)/sqrt(R) - initial approximation by frsqrta, 73// |eps| < 2^(-8) 74// Then 3 iterations are used to refine the result: 75// H0 = 0.5*y0 76// S0 = R*y0 77// 78// d0 = 0.5 - H0*S0 79// H1 = H0 + d0*H0 80// S1 = S0 + d0*S0 81// 82// d1 = 0.5 - H1*S1 83// H2 = H1 + d0*H1 84// S2 = S1 + d0*S1 85// 86// d2 = 0.5 - H2*S2 87// S3 = S3 + d2*S3 88// 89// S3 approximates sqrt(R) with enough accuracy for this algorithm 90// 91// So, the result should be reconstracted as follows: 92// acos(x) = Pi/2 - sign(x) * (Pi/2 - S3*PolB(R)) 93// 94// But for optimization purposes the reconstruction step is slightly 95// changed: 96// acos(x) = Cpi + sign(x)*PolB(R)*S2 - sign(x)*d2*S2*PolB(R) 97// where Cpi = 0 if x > 0 and Cpi = Pi if x < 0 98// 99// 4. |x| = 1.0 100// Return acos(1.0) = 0.0, acos(-1.0) = Pi 101// 102// 5. 1.0 < |x| <= +INF 103// A doman error occurs for arguments not in the range [-1,+1] 104// 105// 6. x = [S,Q]NaN 106// Return acos(x) = QNaN 107// 108// 7. x is denormal 109// Return acos(x) = Pi/2 - x, 110// 111// 8. x is unnormal 112// Normalize input in f8 and return to the very beginning of the function 113// 114// Registers used 115//============================================================== 116// Floating Point registers used: 117// f8, input, output 118// f6, f7, f9 -> f15, f32 -> f64 119 120// General registers used: 121// r3, r21 -> r31, r32 -> r38 122 123// Predicate registers used: 124// p0, p6 -> p14 125 126// 127// Assembly macros 128//========================================= 129// integer registers used 130// scratch 131rTblAddr = r3 132 133rPiBy2Ptr = r21 134rTmpPtr3 = r22 135rDenoBound = r23 136rOne = r24 137rAbsXBits = r25 138rHalf = r26 139r0625 = r27 140rSign = r28 141rXBits = r29 142rTmpPtr2 = r30 143rTmpPtr1 = r31 144 145// stacked 146GR_SAVE_PFS = r32 147GR_SAVE_B0 = r33 148GR_SAVE_GP = r34 149GR_Parameter_X = r35 150GR_Parameter_Y = r36 151GR_Parameter_RESULT = r37 152GR_Parameter_TAG = r38 153 154// floating point registers used 155FR_X = f10 156FR_Y = f1 157FR_RESULT = f8 158 159 160// scratch 161fXSqr = f6 162fXCube = f7 163fXQuadr = f9 164f1pX = f10 165f1mX = f11 166f1pXRcp = f12 167f1mXRcp = f13 168fH = f14 169fS = f15 170// stacked 171fA3 = f32 172fB1 = f32 173fA5 = f33 174fB2 = f33 175fA7 = f34 176fPiBy2 = f34 177fA9 = f35 178fA11 = f36 179fB10 = f35 180fB11 = f36 181fA13 = f37 182fA15 = f38 183fB4 = f37 184fB5 = f38 185fA17 = f39 186fA19 = f40 187fB6 = f39 188fB7 = f40 189fA21 = f41 190fA23 = f42 191fB3 = f41 192fB8 = f42 193fA25 = f43 194fA27 = f44 195fB9 = f43 196fB12 = f44 197fA29 = f45 198fA31 = f46 199fA33 = f47 200fA35 = f48 201fBaseP = f49 202fB0 = f50 203fSignedS = f51 204fD = f52 205fHalf = f53 206fR = f54 207fCloseTo1Pol = f55 208fSignX = f56 209fDenoBound = f57 210fNormX = f58 211fX8 = f59 212fRSqr = f60 213fRQuadr = f61 214fR8 = f62 215fX16 = f63 216fCpi = f64 217 218// Data tables 219//============================================================== 220RODATA 221.align 16 222LOCAL_OBJECT_START(acos_base_range_table) 223// Ai: Polynomial coefficients for the acos(x), |x| < .625000 224// Bi: Polynomial coefficients for the acos(x), |x| > .625000 225data8 0xBFDAAB56C01AE468 //A29 226data8 0x3FE1C470B76A5B2B //A31 227data8 0xBFDC5FF82A0C4205 //A33 228data8 0x3FC71FD88BFE93F0 //A35 229data8 0xB504F333F9DE6487, 0x00003FFF //B0 230data8 0xAAAAAAAAAAAAFC18, 0x00003FFC //A3 231data8 0x3F9F1C71BC4A7823 //A9 232data8 0x3F96E8BBAAB216B2 //A11 233data8 0x3F91C4CA1F9F8A98 //A13 234data8 0x3F8C9DDCEDEBE7A6 //A15 235data8 0x3F877784442B1516 //A17 236data8 0x3F859C0491802BA2 //A19 237data8 0x9999999998C88B8F, 0x00003FFB //A5 238data8 0x3F6BD7A9A660BF5E //A21 239data8 0x3F9FC1659340419D //A23 240data8 0xB6DB6DB798149BDF, 0x00003FFA //A7 241data8 0xBFB3EF18964D3ED3 //A25 242data8 0x3FCD285315542CF2 //A27 243data8 0xF15BEEEFF7D2966A, 0x00003FFB //B1 244data8 0x3EF0DDA376D10FB3 //B10 245data8 0xBEB83CAFE05EBAC9 //B11 246data8 0x3F65FFB67B513644 //B4 247data8 0x3F5032FBB86A4501 //B5 248data8 0x3F392162276C7CBA //B6 249data8 0x3F2435949FD98BDF //B7 250data8 0xD93923D7FA08341C, 0x00003FF9 //B2 251data8 0x3F802995B6D90BDB //B3 252data8 0x3F10DF86B341A63F //B8 253data8 0xC90FDAA22168C235, 0x00003FFF // Pi/2 254data8 0x3EFA3EBD6B0ECB9D //B9 255data8 0x3EDE18BA080E9098 //B12 256LOCAL_OBJECT_END(acos_base_range_table) 257 258.section .text 259GLOBAL_LIBM_ENTRY(acos) 260acos_unnormal_back: 261{ .mfi 262 getf.d rXBits = f8 // grab bits of input value 263 // set p12 = 1 if x is a NaN, denormal, or zero 264 fclass.m p12, p0 = f8, 0xcf 265 adds rSign = 1, r0 266} 267{ .mfi 268 addl rTblAddr = @ltoff(acos_base_range_table),gp 269 // 1 - x = 1 - |x| for positive x 270 fms.s1 f1mX = f1, f1, f8 271 addl rHalf = 0xFFFE, r0 // exponent of 1/2 272} 273;; 274{ .mfi 275 addl r0625 = 0x3FE4, r0 // high 16 bits of 0.625 276 // set p8 = 1 if x < 0 277 fcmp.lt.s1 p8, p9 = f8, f0 278 shl rSign = rSign, 63 // sign bit 279} 280{ .mfi 281 // point to the beginning of the table 282 ld8 rTblAddr = [rTblAddr] 283 // 1 + x = 1 - |x| for negative x 284 fma.s1 f1pX = f1, f1, f8 285 adds rOne = 0x3FF, r0 286} 287;; 288{ .mfi 289 andcm rAbsXBits = rXBits, rSign // bits of |x| 290 fmerge.s fSignX = f8, f1 // signum(x) 291 shl r0625 = r0625, 48 // bits of DP representation of 0.625 292} 293{ .mfb 294 setf.exp fHalf = rHalf // load A2 to FP reg 295 fma.s1 fXSqr = f8, f8, f0 // x^2 296 // branch on special path if x is a NaN, denormal, or zero 297(p12) br.cond.spnt acos_special 298} 299;; 300{ .mfi 301 adds rPiBy2Ptr = 272, rTblAddr 302 nop.f 0 303 shl rOne = rOne, 52 // bits of 1.0 304} 305{ .mfi 306 adds rTmpPtr1 = 16, rTblAddr 307 nop.f 0 308 // set p6 = 1 if |x| < 0.625 309 cmp.lt p6, p7 = rAbsXBits, r0625 310} 311;; 312{ .mfi 313 ldfpd fA29, fA31 = [rTblAddr] // A29, fA31 314 // 1 - x = 1 - |x| for positive x 315(p9) fms.s1 fR = f1, f1, f8 316 // point to coefficient of "near 1" polynomial 317(p7) adds rTmpPtr2 = 176, rTblAddr 318} 319{ .mfi 320 ldfpd fA33, fA35 = [rTmpPtr1], 16 // A33, fA35 321 // 1 + x = 1 - |x| for negative x 322(p8) fma.s1 fR = f1, f1, f8 323(p6) adds rTmpPtr2 = 48, rTblAddr 324} 325;; 326{ .mfi 327 ldfe fB0 = [rTmpPtr1], 16 // B0 328 nop.f 0 329 nop.i 0 330} 331{ .mib 332 adds rTmpPtr3 = 16, rTmpPtr2 333 // set p10 = 1 if |x| = 1.0 334 cmp.eq p10, p0 = rAbsXBits, rOne 335 // branch on special path for |x| = 1.0 336(p10) br.cond.spnt acos_abs_1 337} 338;; 339{ .mfi 340 ldfe fA3 = [rTmpPtr2], 48 // A3 or B1 341 nop.f 0 342 adds rTmpPtr1 = 64, rTmpPtr3 343} 344{ .mib 345 ldfpd fA9, fA11 = [rTmpPtr3], 16 // A9, A11 or B10, B11 346 // set p11 = 1 if |x| > 1.0 347 cmp.gt p11, p0 = rAbsXBits, rOne 348 // branch on special path for |x| > 1.0 349(p11) br.cond.spnt acos_abs_gt_1 350} 351;; 352{ .mfi 353 ldfpd fA17, fA19 = [rTmpPtr2], 16 // A17, A19 or B6, B7 354 // initial approximation of 1 / sqrt(1 - x) 355 frsqrta.s1 f1mXRcp, p0 = f1mX 356 nop.i 0 357} 358{ .mfi 359 ldfpd fA13, fA15 = [rTmpPtr3] // A13, A15 or B4, B5 360 fma.s1 fXCube = fXSqr, f8, f0 // x^3 361 nop.i 0 362} 363;; 364{ .mfi 365 ldfe fA5 = [rTmpPtr2], 48 // A5 or B2 366 // initial approximation of 1 / sqrt(1 + x) 367 frsqrta.s1 f1pXRcp, p0 = f1pX 368 nop.i 0 369} 370{ .mfi 371 ldfpd fA21, fA23 = [rTmpPtr1], 16 // A21, A23 or B3, B8 372 fma.s1 fXQuadr = fXSqr, fXSqr, f0 // x^4 373 nop.i 0 374} 375;; 376{ .mfi 377 ldfe fA7 = [rTmpPtr1] // A7 or Pi/2 378 fma.s1 fRSqr = fR, fR, f0 // R^2 379 nop.i 0 380} 381{ .mfb 382 ldfpd fA25, fA27 = [rTmpPtr2] // A25, A27 or B9, B12 383 nop.f 0 384(p6) br.cond.spnt acos_base_range; 385} 386;; 387 388{ .mfi 389 nop.m 0 390(p9) fma.s1 fH = fHalf, f1mXRcp, f0 // H0 for x > 0 391 nop.i 0 392} 393{ .mfi 394 nop.m 0 395(p9) fma.s1 fS = f1mX, f1mXRcp, f0 // S0 for x > 0 396 nop.i 0 397} 398;; 399{ .mfi 400 nop.m 0 401(p8) fma.s1 fH = fHalf, f1pXRcp, f0 // H0 for x < 0 402 nop.i 0 403} 404{ .mfi 405 nop.m 0 406(p8) fma.s1 fS = f1pX, f1pXRcp, f0 // S0 for x > 0 407 nop.i 0 408} 409;; 410{ .mfi 411 nop.m 0 412 fma.s1 fRQuadr = fRSqr, fRSqr, f0 // R^4 413 nop.i 0 414} 415;; 416{ .mfi 417 nop.m 0 418 fma.s1 fB11 = fB11, fR, fB10 419 nop.i 0 420} 421{ .mfi 422 nop.m 0 423 fma.s1 fB1 = fB1, fR, fB0 424 nop.i 0 425} 426;; 427{ .mfi 428 nop.m 0 429 fma.s1 fB5 = fB5, fR, fB4 430 nop.i 0 431} 432{ .mfi 433 nop.m 0 434 fma.s1 fB7 = fB7, fR, fB6 435 nop.i 0 436} 437;; 438{ .mfi 439 nop.m 0 440 fma.s1 fB3 = fB3, fR, fB2 441 nop.i 0 442} 443;; 444{ .mfi 445 nop.m 0 446 fnma.s1 fD = fH, fS, fHalf // d0 = 1/2 - H0*S0 447 nop.i 0 448} 449;; 450{ .mfi 451 nop.m 0 452 fma.s1 fR8 = fRQuadr, fRQuadr, f0 // R^4 453 nop.i 0 454} 455{ .mfi 456 nop.m 0 457 fma.s1 fB9 = fB9, fR, fB8 458 nop.i 0 459} 460;; 461{.mfi 462 nop.m 0 463 fma.s1 fB12 = fB12, fRSqr, fB11 464 nop.i 0 465} 466{.mfi 467 nop.m 0 468 fma.s1 fB7 = fB7, fRSqr, fB5 469 nop.i 0 470} 471;; 472{.mfi 473 nop.m 0 474 fma.s1 fB3 = fB3, fRSqr, fB1 475 nop.i 0 476} 477;; 478{ .mfi 479 nop.m 0 480 fma.s1 fH = fH, fD, fH // H1 = H0 + H0*d0 481 nop.i 0 482} 483{ .mfi 484 nop.m 0 485 fma.s1 fS = fS, fD, fS // S1 = S0 + S0*d0 486 nop.i 0 487} 488;; 489{.mfi 490 nop.m 0 491(p9) fma.s1 fCpi = f1, f0, f0 // Cpi = 0 if x > 0 492 nop.i 0 493} 494{ .mfi 495 nop.m 0 496(p8) fma.s1 fCpi = fPiBy2, f1, fPiBy2 // Cpi = Pi if x < 0 497 nop.i 0 498} 499;; 500{ .mfi 501 nop.m 0 502 fma.s1 fB12 = fB12, fRSqr, fB9 503 nop.i 0 504} 505{ .mfi 506 nop.m 0 507 fma.s1 fB7 = fB7, fRQuadr, fB3 508 nop.i 0 509} 510;; 511{.mfi 512 nop.m 0 513 fnma.s1 fD = fH, fS, fHalf // d1 = 1/2 - H1*S1 514 nop.i 0 515} 516{ .mfi 517 nop.m 0 518 fnma.s1 fSignedS = fSignX, fS, f0 // -signum(x)*S1 519 nop.i 0 520} 521;; 522{ .mfi 523 nop.m 0 524 fma.s1 fCloseTo1Pol = fB12, fR8, fB7 525 nop.i 0 526} 527;; 528{ .mfi 529 nop.m 0 530 fma.s1 fH = fH, fD, fH // H2 = H1 + H1*d1 531 nop.i 0 532} 533{ .mfi 534 nop.m 0 535 fma.s1 fS = fS, fD, fS // S2 = S1 + S1*d1 536 nop.i 0 537} 538;; 539{ .mfi 540 nop.m 0 541 // -signum(x)* S2 = -signum(x)*(S1 + S1*d1) 542 fma.s1 fSignedS = fSignedS, fD, fSignedS 543 nop.i 0 544} 545;; 546{.mfi 547 nop.m 0 548 fnma.s1 fD = fH, fS, fHalf // d2 = 1/2 - H2*S2 549 nop.i 0 550} 551;; 552{ .mfi 553 nop.m 0 554 // Cpi + signum(x)*PolB*S2 555 fnma.s1 fCpi = fSignedS, fCloseTo1Pol, fCpi 556 nop.i 0 557} 558{ .mfi 559 nop.m 0 560 // signum(x)*PolB * S2 561 fnma.s1 fCloseTo1Pol = fSignedS, fCloseTo1Pol, f0 562 nop.i 0 563} 564;; 565{ .mfb 566 nop.m 0 567 // final result for 0.625 <= |x| < 1 568 fma.d.s0 f8 = fCloseTo1Pol, fD, fCpi 569 // exit here for 0.625 <= |x| < 1 570 br.ret.sptk b0 571} 572;; 573 574 575// here if |x| < 0.625 576.align 32 577acos_base_range: 578{ .mfi 579 ldfe fCpi = [rPiBy2Ptr] // Pi/2 580 fma.s1 fA33 = fA33, fXSqr, fA31 581 nop.i 0 582} 583{ .mfi 584 nop.m 0 585 fma.s1 fA15 = fA15, fXSqr, fA13 586 nop.i 0 587} 588;; 589{ .mfi 590 nop.m 0 591 fma.s1 fA29 = fA29, fXSqr, fA27 592 nop.i 0 593} 594{ .mfi 595 nop.m 0 596 fma.s1 fA25 = fA25, fXSqr, fA23 597 nop.i 0 598} 599;; 600{ .mfi 601 nop.m 0 602 fma.s1 fA21 = fA21, fXSqr, fA19 603 nop.i 0 604} 605{ .mfi 606 nop.m 0 607 fma.s1 fA9 = fA9, fXSqr, fA7 608 nop.i 0 609} 610;; 611{ .mfi 612 nop.m 0 613 fma.s1 fA5 = fA5, fXSqr, fA3 614 nop.i 0 615} 616;; 617{ .mfi 618 nop.m 0 619 fma.s1 fA35 = fA35, fXQuadr, fA33 620 nop.i 0 621} 622{ .mfi 623 nop.m 0 624 fma.s1 fA17 = fA17, fXQuadr, fA15 625 nop.i 0 626} 627;; 628{ .mfi 629 nop.m 0 630 fma.s1 fX8 = fXQuadr, fXQuadr, f0 // x^8 631 nop.i 0 632} 633{ .mfi 634 nop.m 0 635 fma.s1 fA25 = fA25, fXQuadr, fA21 636 nop.i 0 637} 638;; 639{ .mfi 640 nop.m 0 641 fma.s1 fA9 = fA9, fXQuadr, fA5 642 nop.i 0 643} 644;; 645{ .mfi 646 nop.m 0 647 fms.s1 fCpi = fCpi, f1, f8 // Pi/2 - x 648 nop.i 0 649} 650;; 651{ .mfi 652 nop.m 0 653 fma.s1 fA35 = fA35, fXQuadr, fA29 654 nop.i 0 655} 656{ .mfi 657 nop.m 0 658 fma.s1 fA17 = fA17, fXSqr, fA11 659 nop.i 0 660} 661;; 662{ .mfi 663 nop.m 0 664 fma.s1 fX16 = fX8, fX8, f0 // x^16 665 nop.i 0 666} 667;; 668{ .mfi 669 nop.m 0 670 fma.s1 fA35 = fA35, fX8, fA25 671 nop.i 0 672} 673{ .mfi 674 nop.m 0 675 fma.s1 fA17 = fA17, fX8, fA9 676 nop.i 0 677} 678;; 679{ .mfi 680 nop.m 0 681 fma.s1 fBaseP = fA35, fX16, fA17 682 nop.i 0 683} 684;; 685{ .mfb 686 nop.m 0 687 // final result for |x| < 0.625 688 fnma.d.s0 f8 = fBaseP, fXCube, fCpi 689 // exit here for |x| < 0.625 path 690 br.ret.sptk b0 691} 692;; 693 694// here if |x| = 1 695// acos(1) = 0 696// acos(-1) = Pi 697.align 32 698acos_abs_1: 699{ .mfi 700 ldfe fPiBy2 = [rPiBy2Ptr] // Pi/2 701 nop.f 0 702 nop.i 0 703} 704;; 705.pred.rel "mutex", p8, p9 706{ .mfi 707 nop.m 0 708 // result for x = 1.0 709(p9) fma.d.s0 f8 = f1, f0, f0 // 0.0 710 nop.i 0 711} 712{.mfb 713 nop.m 0 714 // result for x = -1.0 715(p8) fma.d.s0 f8 = fPiBy2, f1, fPiBy2 // Pi 716 // exit here for |x| = 1.0 717 br.ret.sptk b0 718} 719;; 720 721// here if x is a NaN, denormal, or zero 722.align 32 723acos_special: 724{ .mfi 725 // point to Pi/2 726 adds rPiBy2Ptr = 272, rTblAddr 727 // set p12 = 1 if x is a NaN 728 fclass.m p12, p0 = f8, 0xc3 729 nop.i 0 730} 731{ .mlx 732 nop.m 0 733 // smallest positive DP normalized number 734 movl rDenoBound = 0x0010000000000000 735} 736;; 737{ .mfi 738 ldfe fPiBy2 = [rPiBy2Ptr] // Pi/2 739 // set p13 = 1 if x = 0.0 740 fclass.m p13, p0 = f8, 0x07 741 nop.i 0 742} 743{ .mfi 744 nop.m 0 745 fnorm.s1 fNormX = f8 746 nop.i 0 747} 748;; 749{ .mfb 750 // load smallest normal to FP reg 751 setf.d fDenoBound = rDenoBound 752 // answer if x is a NaN 753(p12) fma.d.s0 f8 = f8,f1,f0 754 // exit here if x is a NaN 755(p12) br.ret.spnt b0 756} 757;; 758{ .mfi 759 nop.m 0 760 // absolute value of normalized x 761 fmerge.s fNormX = f1, fNormX 762 nop.i 0 763} 764;; 765{ .mfb 766 nop.m 0 767 // final result for x = 0 768(p13) fma.d.s0 f8 = fPiBy2, f1, f8 769 // exit here if x = 0.0 770(p13) br.ret.spnt b0 771} 772;; 773// if we still here then x is denormal or unnormal 774{ .mfi 775 nop.m 0 776 // set p14 = 1 if normalized x is greater than or 777 // equal to the smallest denormalized value 778 // So, if p14 is set to 1 it means that we deal with 779 // unnormal rather than with "true" denormal 780 fcmp.ge.s1 p14, p0 = fNormX, fDenoBound 781 nop.i 0 782} 783;; 784{ .mfi 785 nop.m 0 786(p14) fcmp.eq.s0 p6, p0 = f8, f0 // Set D flag if x unnormal 787 nop.i 0 788} 789{ .mfb 790 nop.m 0 791 // normalize unnormal input 792(p14) fnorm.s1 f8 = f8 793 // return to the main path 794(p14) br.cond.sptk acos_unnormal_back 795} 796;; 797// if we still here it means that input is "true" denormal 798{ .mfb 799 nop.m 0 800 // final result if x is denormal 801 fms.d.s0 f8 = fPiBy2, f1, f8 // Pi/2 - x 802 // exit here if x is denormal 803 br.ret.sptk b0 804} 805;; 806 807// here if |x| > 1.0 808// error handler should be called 809.align 32 810acos_abs_gt_1: 811{ .mfi 812 alloc r32 = ar.pfs, 0, 3, 4, 0 // get some registers 813 fmerge.s FR_X = f8,f8 814 nop.i 0 815} 816{ .mfb 817 mov GR_Parameter_TAG = 58 // error code 818 frcpa.s0 FR_RESULT, p0 = f0,f0 819 // call error handler routine 820 br.cond.sptk __libm_error_region 821} 822;; 823GLOBAL_LIBM_END(acos) 824libm_alias_double_other (acos, acos) 825 826 827 828LOCAL_LIBM_ENTRY(__libm_error_region) 829.prologue 830{ .mfi 831 add GR_Parameter_Y=-32,sp // Parameter 2 value 832 nop.f 0 833.save ar.pfs,GR_SAVE_PFS 834 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs 835} 836{ .mfi 837.fframe 64 838 add sp=-64,sp // Create new stack 839 nop.f 0 840 mov GR_SAVE_GP=gp // Save gp 841};; 842{ .mmi 843 stfd [GR_Parameter_Y] = FR_Y,16 // STORE Parameter 2 on stack 844 add GR_Parameter_X = 16,sp // Parameter 1 address 845.save b0, GR_SAVE_B0 846 mov GR_SAVE_B0=b0 // Save b0 847};; 848.body 849{ .mib 850 stfd [GR_Parameter_X] = FR_X // STORE Parameter 1 on stack 851 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address 852 nop.b 0 853} 854{ .mib 855 stfd [GR_Parameter_Y] = FR_RESULT // STORE Parameter 3 on stack 856 add GR_Parameter_Y = -16,GR_Parameter_Y 857 br.call.sptk b0=__libm_error_support# // Call error handling function 858};; 859{ .mmi 860 add GR_Parameter_RESULT = 48,sp 861 nop.m 0 862 nop.i 0 863};; 864{ .mmi 865 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack 866.restore sp 867 add sp = 64,sp // Restore stack pointer 868 mov b0 = GR_SAVE_B0 // Restore return address 869};; 870{ .mib 871 mov gp = GR_SAVE_GP // Restore gp 872 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs 873 br.ret.sptk b0 // Return 874};; 875 876LOCAL_LIBM_END(__libm_error_region) 877.type __libm_error_support#,@function 878.global __libm_error_support# 879