1/* 2Copyright (c) 2014, Intel Corporation 3All rights reserved. 4 5Redistribution and use in source and binary forms, with or without 6modification, are permitted provided that the following conditions are met: 7 8 * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 11 * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 15 * Neither the name of Intel Corporation nor the names of its contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29*/ 30 31/******************************************************************************/ 32// ALGORITHM DESCRIPTION 33// --------------------- 34// 35// x=2^k * mx, mx in [1,2) 36// 37// Get B~1/mx based on the output of rcpss instruction (B0) 38// B = int((B0*2^7+0.5))/2^7 39// 40// Reduced argument: r=B*mx-1.0 (computed accurately in high and low parts) 41// 42// Result: k*log(2) - log(B) + p(r) if |x-1| >= small value (2^-6) and 43// p(r) is a degree 7 polynomial 44// -log(B) read from data table (high, low parts) 45// Result is formed from high and low parts 46// 47// Special cases: 48// log(NaN) = quiet NaN, and raise invalid exception 49// log(+INF) = that INF 50// log(0) = -INF with divide-by-zero exception raised 51// log(1) = +0 52// log(x) = NaN with invalid exception raised if x < -0, including -INF 53// 54/******************************************************************************/ 55 56#include <private/bionic_asm.h> 57# -- Begin log 58ENTRY(log) 59# parameter 1: %xmm0 60..B1.1: 61..___tag_value_log.1: 62 subq $24, %rsp 63..___tag_value_log.3: 64 movsd %xmm0, (%rsp) 65..B1.2: 66 movq $0x3ff0000000000000, %rax 67 movd %rax, %xmm2 68 movq $0x77f0000000000000, %rdx 69 movd %rdx, %xmm3 70 movl $32768, %ecx 71 movd %rcx, %xmm4 72 movq $0xffffe00000000000, %r8 73 movd %r8, %xmm5 74 movq %xmm0, %xmm1 75 pextrw $3, %xmm0, %eax 76 orpd %xmm2, %xmm0 77 movl $16352, %ecx 78 psrlq $27, %xmm0 79 lea L_tbl(%rip), %r11 80 psrld $2, %xmm0 81 rcpps %xmm0, %xmm0 82 psllq $12, %xmm1 83 pshufd $228, %xmm5, %xmm6 84 psrlq $12, %xmm1 85 subl $16, %eax 86 cmpl $32736, %eax 87 jae .L_2TAG_PACKET_0.0.2 88.L_2TAG_PACKET_1.0.2: 89 paddd %xmm4, %xmm0 90 orpd %xmm3, %xmm1 91 movd %xmm0, %edx 92 psllq $29, %xmm0 93 andpd %xmm1, %xmm5 94 andpd %xmm6, %xmm0 95 subsd %xmm5, %xmm1 96 mulpd %xmm0, %xmm5 97 andl $32752, %eax 98 subl %ecx, %eax 99 cvtsi2sd %eax, %xmm7 100 mulsd %xmm0, %xmm1 101 movq log2(%rip), %xmm6 102 movapd coeff(%rip), %xmm3 103 subsd %xmm2, %xmm5 104 andl $16711680, %edx 105 shrl $12, %edx 106 movapd (%r11,%rdx), %xmm0 107 movapd 16+coeff(%rip), %xmm4 108 addsd %xmm5, %xmm1 109 movapd 32+coeff(%rip), %xmm2 110 mulsd %xmm7, %xmm6 111 movddup %xmm1, %xmm5 112 mulsd 8+log2(%rip), %xmm7 113 mulsd %xmm1, %xmm3 114 addsd %xmm6, %xmm0 115 mulpd %xmm5, %xmm4 116 mulpd %xmm5, %xmm5 117 movddup %xmm0, %xmm6 118 addsd %xmm1, %xmm0 119 addpd %xmm2, %xmm4 120 mulpd %xmm5, %xmm3 121 subsd %xmm0, %xmm6 122 mulsd %xmm1, %xmm4 123 pshufd $238, %xmm0, %xmm2 124 addsd %xmm6, %xmm1 125 mulsd %xmm5, %xmm5 126 addsd %xmm2, %xmm7 127 addpd %xmm3, %xmm4 128 addsd %xmm7, %xmm1 129 mulpd %xmm5, %xmm4 130 addsd %xmm4, %xmm1 131 pshufd $238, %xmm4, %xmm5 132 addsd %xmm5, %xmm1 133 addsd %xmm1, %xmm0 134 jmp ..B1.5 135.L_2TAG_PACKET_0.0.2: 136 movq (%rsp), %xmm0 137 movq (%rsp), %xmm1 138 addl $16, %eax 139 cmpl $32768, %eax 140 jae .L_2TAG_PACKET_2.0.2 141 cmpl $16, %eax 142 jb .L_2TAG_PACKET_3.0.2 143.L_2TAG_PACKET_4.0.2: 144 addsd %xmm0, %xmm0 145 jmp ..B1.5 146.L_2TAG_PACKET_5.0.2: 147 ja .L_2TAG_PACKET_4.0.2 148 cmpl $0, %edx 149 ja .L_2TAG_PACKET_4.0.2 150 jmp .L_2TAG_PACKET_6.0.2 151.L_2TAG_PACKET_3.0.2: 152 xorpd %xmm1, %xmm1 153 addsd %xmm0, %xmm1 154 movd %xmm1, %edx 155 psrlq $32, %xmm1 156 movd %xmm1, %ecx 157 orl %ecx, %edx 158 cmpl $0, %edx 159 je .L_2TAG_PACKET_7.0.2 160 xorpd %xmm1, %xmm1 161 movl $18416, %eax 162 pinsrw $3, %eax, %xmm1 163 mulsd %xmm1, %xmm0 164 movq %xmm0, %xmm1 165 pextrw $3, %xmm0, %eax 166 orpd %xmm2, %xmm0 167 psrlq $27, %xmm0 168 movl $18416, %ecx 169 psrld $2, %xmm0 170 rcpps %xmm0, %xmm0 171 psllq $12, %xmm1 172 pshufd $228, %xmm5, %xmm6 173 psrlq $12, %xmm1 174 jmp .L_2TAG_PACKET_1.0.2 175.L_2TAG_PACKET_2.0.2: 176 movd %xmm1, %edx 177 psrlq $32, %xmm1 178 movd %xmm1, %ecx 179 addl %ecx, %ecx 180 cmpl $-2097152, %ecx 181 jae .L_2TAG_PACKET_5.0.2 182 orl %ecx, %edx 183 cmpl $0, %edx 184 je .L_2TAG_PACKET_7.0.2 185.L_2TAG_PACKET_6.0.2: 186 xorpd %xmm1, %xmm1 187 xorpd %xmm0, %xmm0 188 movl $32752, %eax 189 pinsrw $3, %eax, %xmm1 190 mulsd %xmm1, %xmm0 191 movl $3, 16(%rsp) 192 jmp .L_2TAG_PACKET_8.0.2 193.L_2TAG_PACKET_7.0.2: 194 xorpd %xmm1, %xmm1 195 xorpd %xmm0, %xmm0 196 movl $49136, %eax 197 pinsrw $3, %eax, %xmm0 198 divsd %xmm1, %xmm0 199 movl $2, 16(%rsp) 200.L_2TAG_PACKET_8.0.2: 201 movq %xmm0, 8(%rsp) 202..B1.3: 203 movq 8(%rsp), %xmm0 204.L_2TAG_PACKET_9.0.2: 205..B1.5: 206 addq $24, %rsp 207..___tag_value_log.4: 208 ret 209..___tag_value_log.5: 210END(log) 211# -- End log 212 .section .rodata, "a" 213 .align 16 214 .align 16 215L_tbl: 216 .long 4277811200 217 .long 1072049730 218 .long 2479318832 219 .long 1026487127 220 .long 2854492160 221 .long 1072033410 222 .long 215631550 223 .long 1025638968 224 .long 1547061248 225 .long 1072017216 226 .long 2886781435 227 .long 1026423395 228 .long 649825280 229 .long 1072001146 230 .long 4281533405 231 .long 1024038923 232 .long 646346752 233 .long 1071985198 234 .long 1562735921 235 .long 1023790276 236 .long 2203734016 237 .long 1071969370 238 .long 1838397691 239 .long 3173936209 240 .long 1872169984 241 .long 1071953661 242 .long 3981202460 243 .long 1022325013 244 .long 669557760 245 .long 1071938069 246 .long 4182597802 247 .long 3173174122 248 .long 4076413952 249 .long 1071922591 250 .long 1209029111 251 .long 3170736207 252 .long 556125184 253 .long 1071907228 254 .long 821086028 255 .long 3173437049 256 .long 204914688 257 .long 1071891976 258 .long 2097025986 259 .long 3171071798 260 .long 387545088 261 .long 1071876834 262 .long 3142936996 263 .long 3173092218 264 .long 2912783360 265 .long 1071861800 266 .long 2502420140 267 .long 1024505919 268 .long 1144260608 269 .long 1071846874 270 .long 3315658140 271 .long 3173469843 272 .long 1471209472 273 .long 1071832053 274 .long 129621009 275 .long 3172443877 276 .long 1829683200 277 .long 1071817336 278 .long 3885467693 279 .long 1025535275 280 .long 288676864 281 .long 1071802722 282 .long 86139472 283 .long 3171639793 284 .long 3636378624 285 .long 1071788208 286 .long 1850238587 287 .long 1024654342 288 .long 1606817792 289 .long 1071773795 290 .long 3388899795 291 .long 3173675586 292 .long 1236164608 293 .long 1071759480 294 .long 3983599207 295 .long 1020046558 296 .long 1089616896 297 .long 1071745262 298 .long 4171974224 299 .long 1024773198 300 .long 4143093760 301 .long 1071731139 302 .long 2727587401 303 .long 3173965207 304 .long 600267776 305 .long 1071717112 306 .long 3147685042 307 .long 3173353031 308 .long 2249313280 309 .long 1071703177 310 .long 125835074 311 .long 1025255832 312 .long 3805303808 313 .long 1071689334 314 .long 2289991207 315 .long 1025460331 316 .long 87278592 317 .long 1071675583 318 .long 1106114045 319 .long 1025933602 320 .long 3195405312 321 .long 1071661920 322 .long 3885316576 323 .long 3171206239 324 .long 3853649920 325 .long 1071648346 326 .long 2977069852 327 .long 3171236771 328 .long 2944026624 329 .long 1071625048 330 .long 1008093493 331 .long 1023444474 332 .long 3993180160 333 .long 1071598247 334 .long 1862355595 335 .long 1024642533 336 .long 1454641152 337 .long 1071571617 338 .long 1514603089 339 .long 1026500596 340 .long 3286085632 341 .long 1071545154 342 .long 1400028424 343 .long 3173279056 344 .long 438773760 345 .long 1071518858 346 .long 120727864 347 .long 3172148914 348 .long 1212979200 349 .long 1071492725 350 .long 1625055594 351 .long 3172901933 352 .long 1189017600 353 .long 1071466754 354 .long 3920062376 355 .long 1025727407 356 .long 403064832 357 .long 1071440943 358 .long 1053271728 359 .long 3171391427 360 .long 3343210496 361 .long 1071415289 362 .long 3243395502 363 .long 3173627613 364 .long 1765777408 365 .long 1071389792 366 .long 2145968512 367 .long 1026354304 368 .long 461430784 369 .long 1071364449 370 .long 4094322285 371 .long 1026021467 372 .long 71706624 373 .long 1071339258 374 .long 763632021 375 .long 1024496933 376 .long 1380503552 377 .long 1071314217 378 .long 1383547992 379 .long 3173088453 380 .long 1015732224 381 .long 1071289325 382 .long 3198646877 383 .long 1025390322 384 .long 35977216 385 .long 1071264580 386 .long 2141026805 387 .long 1025754693 388 .long 3927306240 389 .long 1071239979 390 .long 282116272 391 .long 3173394334 392 .long 1125341184 393 .long 1071215523 394 .long 2768427504 395 .long 3172279059 396 .long 1666971648 397 .long 1071191208 398 .long 786837629 399 .long 3172427445 400 .long 2827694080 401 .long 1071167033 402 .long 3857122416 403 .long 3173014241 404 .long 2003683328 405 .long 1071142997 406 .long 859010954 407 .long 1026545007 408 .long 1004017664 409 .long 1071119098 410 .long 3356644970 411 .long 3173458064 412 .long 1753020416 413 .long 1071095334 414 .long 788338552 415 .long 1026157693 416 .long 1992718336 417 .long 1071071704 418 .long 1239179443 419 .long 1026394889 420 .long 3870234624 421 .long 1071048206 422 .long 2082614663 423 .long 1024926053 424 .long 1050437632 425 .long 1071024840 426 .long 660007840 427 .long 1025548499 428 .long 188395520 429 .long 1071001603 430 .long 3878792704 431 .long 3173889571 432 .long 3747176448 433 .long 1070978493 434 .long 144991708 435 .long 3171552042 436 .long 1405669376 437 .long 1070955511 438 .long 3999088879 439 .long 1025486317 440 .long 121151488 441 .long 1070932654 442 .long 2170865497 443 .long 1026473584 444 .long 2652319744 445 .long 1070909920 446 .long 453695652 447 .long 3173916809 448 .long 3262236672 449 .long 1070887309 450 .long 157800053 451 .long 3173984206 452 .long 601221120 453 .long 1070864820 454 .long 3968917661 455 .long 1023992886 456 .long 1999843328 457 .long 1070842450 458 .long 3053895004 459 .long 1024998228 460 .long 1992167424 461 .long 1070820199 462 .long 2968614856 463 .long 1024552653 464 .long 3788726272 465 .long 1070798065 466 .long 3542170808 467 .long 3173573242 468 .long 2094829568 469 .long 1070776048 470 .long 1246758132 471 .long 1026202874 472 .long 288675840 473 .long 1070754146 474 .long 3747328950 475 .long 1026331585 476 .long 1829681152 477 .long 1070732357 478 .long 3125197546 479 .long 1024100318 480 .long 1666869248 481 .long 1070710681 482 .long 1363656119 483 .long 1026336493 484 .long 3417110528 485 .long 1070689116 486 .long 4154791553 487 .long 1026267853 488 .long 2183653376 489 .long 1070667662 490 .long 1671819292 491 .long 3173785870 492 .long 1734434816 493 .long 1070646317 494 .long 373091049 495 .long 1025972363 496 .long 1615681536 497 .long 1070625080 498 .long 384650897 499 .long 1022926043 500 .long 1445382144 501 .long 1070603950 502 .long 344320330 503 .long 3172397196 504 .long 1823715328 505 .long 1070569756 506 .long 3389841200 507 .long 1025231852 508 .long 3839688704 509 .long 1070527917 510 .long 1706790417 511 .long 3167363349 512 .long 4293332992 513 .long 1070486286 514 .long 1614935088 515 .long 1019351591 516 .long 2966720512 517 .long 1070444861 518 .long 4145393717 519 .long 3173711658 520 .long 4066729984 521 .long 1070403639 522 .long 1974925028 523 .long 3171437182 524 .long 3337621504 525 .long 1070362619 526 .long 3314953170 527 .long 3169971314 528 .long 943448064 529 .long 1070321799 530 .long 1498682038 531 .long 3173862340 532 .long 1465634816 533 .long 1070281176 534 .long 1319952810 535 .long 3171693965 536 .long 1015734272 537 .long 1070240749 538 .long 1347821929 539 .long 3173544515 540 .long 118001664 541 .long 1070200516 542 .long 1751482746 543 .long 1026134093 544 .long 3707174912 545 .long 1070160474 546 .long 1486946159 547 .long 1023930920 548 .long 3946381312 549 .long 1070120623 550 .long 2867408081 551 .long 3171368276 552 .long 1699848192 553 .long 1070080961 554 .long 2590187139 555 .long 1025379803 556 .long 2235846656 557 .long 1070041485 558 .long 1888568069 559 .long 3172754960 560 .long 2339729408 561 .long 1070002194 562 .long 3852214753 563 .long 3173323149 564 .long 3196850176 565 .long 1069963086 566 .long 742141560 567 .long 1025101707 568 .long 1800683520 569 .long 1069924160 570 .long 3949500444 571 .long 3172102179 572 .long 3835801600 573 .long 1069885413 574 .long 3848895943 575 .long 1025913832 576 .long 2201202688 577 .long 1069846845 578 .long 1425913464 579 .long 1025868665 580 .long 2778279936 581 .long 1069808453 582 .long 2120889677 583 .long 3173831128 584 .long 2954203136 585 .long 1069770236 586 .long 592147081 587 .long 1019621288 588 .long 210141184 589 .long 1069732193 590 .long 3414275233 591 .long 1023647084 592 .long 709476352 593 .long 1069694321 594 .long 2413027164 595 .long 1024462115 596 .long 2116284416 597 .long 1069656619 598 .long 1144559924 599 .long 1026336654 600 .long 2183651328 601 .long 1069619086 602 .long 3459057650 603 .long 1025634168 604 .long 3047047168 605 .long 1069581720 606 .long 1879674924 607 .long 3173508573 608 .long 970711040 609 .long 1069541521 610 .long 1335954173 611 .long 3173332182 612 .long 2198478848 613 .long 1069467449 614 .long 2951103968 615 .long 3173892200 616 .long 1669611520 617 .long 1069393703 618 .long 531044147 619 .long 1025149248 620 .long 29114368 621 .long 1069320280 622 .long 3327831251 623 .long 1025918673 624 .long 2376949760 625 .long 1069247176 626 .long 737634533 627 .long 3172176000 628 .long 1085390848 629 .long 1069174390 630 .long 3108243400 631 .long 3171828406 632 .long 1566130176 633 .long 1069101918 634 .long 985483226 635 .long 1025708380 636 .long 792780800 637 .long 1069029758 638 .long 4184866295 639 .long 1024426204 640 .long 183156736 641 .long 1068957907 642 .long 2845699378 643 .long 1022107277 644 .long 1301782528 645 .long 1068886362 646 .long 1012735262 647 .long 3173804294 648 .long 1562411008 649 .long 1068815121 650 .long 2197086703 651 .long 3170187813 652 .long 2815549440 653 .long 1068744181 654 .long 2782613207 655 .long 1026345054 656 .long 2756124672 657 .long 1068673540 658 .long 2929486205 659 .long 3173037800 660 .long 3511050240 661 .long 1068603195 662 .long 1443733147 663 .long 3173331549 664 .long 3047047168 665 .long 1068533144 666 .long 1879674924 667 .long 3172459997 668 .long 3221667840 669 .long 1068427825 670 .long 1338588027 671 .long 3171815742 672 .long 3453861888 673 .long 1068288883 674 .long 1205348359 675 .long 3172624626 676 .long 3506110464 677 .long 1068150514 678 .long 893105198 679 .long 1025571866 680 .long 346013696 681 .long 1068012714 682 .long 3495569021 683 .long 3172563349 684 .long 4074029056 685 .long 1067875476 686 .long 3961106338 687 .long 3171065595 688 .long 3559784448 689 .long 1067738798 690 .long 1975385384 691 .long 3173783155 692 .long 797769728 693 .long 1067602675 694 .long 3760305787 695 .long 1026047642 696 .long 2313633792 697 .long 1067467101 698 .long 1559353171 699 .long 1023480256 700 .long 3960766464 701 .long 1067213778 702 .long 1067365107 703 .long 1025865926 704 .long 684261376 705 .long 1066944805 706 .long 844762164 707 .long 3173687482 708 .long 630718464 709 .long 1066676905 710 .long 2458269694 711 .long 1024033081 712 .long 1486061568 713 .long 1066410070 714 .long 115537874 715 .long 3173243995 716 .long 2743664640 717 .long 1065886792 718 .long 3665098304 719 .long 3173471607 720 .long 1971912704 721 .long 1065357333 722 .long 2577214440 723 .long 3171993451 724 .long 1498939392 725 .long 1064306693 726 .long 3409036923 727 .long 1025599151 728 .long 0 729 .long 0 730 .long 0 731 .long 2147483648 732 .type L_tbl,@object 733 .size L_tbl,2064 734 .align 16 735log2: 736 .long 4277811200 737 .long 1067855426 738 .long 2479318832 739 .long 1022292823 740 .type log2,@object 741 .size log2,16 742 .align 16 743coeff: 744 .long 2454267026 745 .long 1069697316 746 .long 0 747 .long 3218079744 748 .long 1030730101 749 .long 3217380702 750 .long 1431655765 751 .long 1070945621 752 .long 2576980378 753 .long 1070176665 754 .long 0 755 .long 3219128320 756 .type coeff,@object 757 .size coeff,48 758 .data 759 .section .note.GNU-stack, "" 760// -- Begin DWARF2 SEGMENT .eh_frame 761 .section .eh_frame,"a",@progbits 762.eh_frame_seg: 763 .align 1 764 .4byte 0x00000014 765 .8byte 0x00527a0100000000 766 .8byte 0x08070c1b01107801 767 .4byte 0x00000190 768 .4byte 0x0000001c 769 .4byte 0x0000001c 770 .4byte ..___tag_value_log.1-. 771 .4byte ..___tag_value_log.5-..___tag_value_log.1 772 .2byte 0x0400 773 .4byte ..___tag_value_log.3-..___tag_value_log.1 774 .2byte 0x200e 775 .byte 0x04 776 .4byte ..___tag_value_log.4-..___tag_value_log.3 777 .2byte 0x080e 778 .byte 0x00 779# End 780