Changeset c67aff2 in mainline for uspace/lib/softfloat/generic/softfloat.c
 Timestamp:
 20110806T07:04:50Z (13 years ago)
 Branches:
 lfn, master, serial, ticket/834toolchainupdate, topic/msimupgrade, topic/simplifydevexport
 Children:
 d3e241a, e0e922d
 Parents:
 9a6034a
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

uspace/lib/softfloat/generic/softfloat.c
r9a6034a rc67aff2 1 1 /* 2 2 * Copyright (c) 2005 Josef Cejka 3 * Copyright (c) 2011 Petr Koupy 3 4 * All rights reserved. 4 5 * … … 32 33 * @{ 33 34 */ 34 /** @file 35 /** @file Softfloat API. 35 36 */ 36 37 … … 83 84 } 84 85 86 long double __addtf3(long double a, long double b) 87 { 88 float128 ta, tb; 89 ta.ld = a; 90 tb.ld = b; 91 if (ta.parts.sign != tb.parts.sign) { 92 if (ta.parts.sign) { 93 ta.parts.sign = 0; 94 return subFloat128(tb, ta).ld; 95 }; 96 tb.parts.sign = 0; 97 return subFloat128(ta, tb).ld; 98 } 99 return addFloat128(ta, tb).ld; 100 } 101 85 102 float __subsf3(float a, float b) 86 103 { … … 107 124 } 108 125 126 long double __subtf3(long double a, long double b) 127 { 128 float128 ta, tb; 129 ta.ld = a; 130 tb.ld = b; 131 if (ta.parts.sign != tb.parts.sign) { 132 tb.parts.sign = !tb.parts.sign; 133 return addFloat128(ta, tb).ld; 134 } 135 return subFloat128(ta, tb).ld; 136 } 137 109 138 float __mulsf3(float a, float b) 110 139 { … … 123 152 } 124 153 154 long double __multf3(long double a, long double b) 155 { 156 float128 ta, tb; 157 ta.ld = a; 158 tb.ld = b; 159 return mulFloat128(ta, tb).ld; 160 } 161 125 162 float __divsf3(float a, float b) 126 163 { … … 139 176 } 140 177 178 long double __divtf3(long double a, long double b) 179 { 180 float128 ta, tb; 181 ta.ld = a; 182 tb.ld = b; 183 return divFloat128(ta, tb).ld; 184 } 185 141 186 float __negsf2(float a) 142 187 { … … 149 194 double __negdf2(double a) 150 195 { 151 float64 fa; 152 fa.d = a; 153 fa.parts.sign = !fa.parts.sign; 154 return fa.d; 196 float64 da; 197 da.d = a; 198 da.parts.sign = !da.parts.sign; 199 return da.d; 200 } 201 202 long double __negtf2(long double a) 203 { 204 float128 ta; 205 ta.ld = a; 206 ta.parts.sign = !ta.parts.sign; 207 return ta.ld; 155 208 } 156 209 … … 164 217 } 165 218 219 long double __extendsftf2(float a) 220 { 221 float32 fa; 222 fa.f = a; 223 return convertFloat32ToFloat128(fa).ld; 224 } 225 226 long double __extenddftf2(double a) 227 { 228 float64 da; 229 da.d = a; 230 return convertFloat64ToFloat128(da).ld; 231 } 232 166 233 float __truncdfsf2(double a) 167 234 { … … 171 238 } 172 239 240 float __trunctfsf2(long double a) 241 { 242 float128 ta; 243 ta.ld = a; 244 return convertFloat128ToFloat32(ta).f; 245 } 246 247 double __trunctfdf2(long double a) 248 { 249 float128 ta; 250 ta.ld = a; 251 return convertFloat128ToFloat64(ta).d; 252 } 253 173 254 int __fixsfsi(float a) 174 255 { … … 178 259 return float32_to_int(fa); 179 260 } 261 180 262 int __fixdfsi(double a) 181 263 { … … 184 266 185 267 return float64_to_int(da); 268 } 269 270 int __fixtfsi(long double a) 271 { 272 float128 ta; 273 ta.ld = a; 274 275 return float128_to_int(ta); 186 276 } 187 277 … … 193 283 return float32_to_long(fa); 194 284 } 285 195 286 long __fixdfdi(double a) 196 287 { … … 199 290 200 291 return float64_to_long(da); 292 } 293 294 long __fixtfdi(long double a) 295 { 296 float128 ta; 297 ta.ld = a; 298 299 return float128_to_long(ta); 201 300 } 202 301 … … 208 307 return float32_to_longlong(fa); 209 308 } 309 210 310 long long __fixdfti(double a) 211 311 { … … 216 316 } 217 317 318 long long __fixtfti(long double a) 319 { 320 float128 ta; 321 ta.ld = a; 322 323 return float128_to_longlong(ta); 324 } 325 218 326 unsigned int __fixunssfsi(float a) 219 327 { … … 223 331 return float32_to_uint(fa); 224 332 } 333 225 334 unsigned int __fixunsdfsi(double a) 226 335 { … … 229 338 230 339 return float64_to_uint(da); 340 } 341 342 unsigned int __fixunstfsi(long double a) 343 { 344 float128 ta; 345 ta.ld = a; 346 347 return float128_to_uint(ta); 231 348 } 232 349 … … 238 355 return float32_to_ulong(fa); 239 356 } 357 240 358 unsigned long __fixunsdfdi(double a) 241 359 { … … 244 362 245 363 return float64_to_ulong(da); 364 } 365 366 unsigned long __fixunstfdi(long double a) 367 { 368 float128 ta; 369 ta.ld = a; 370 371 return float128_to_ulong(ta); 246 372 } 247 373 … … 253 379 return float32_to_ulonglong(fa); 254 380 } 381 255 382 unsigned long long __fixunsdfti(double a) 256 383 { … … 259 386 260 387 return float64_to_ulonglong(da); 388 } 389 390 unsigned long long __fixunstfti(long double a) 391 { 392 float128 ta; 393 ta.ld = a; 394 395 return float128_to_ulonglong(ta); 261 396 } 262 397 … … 268 403 return fa.f; 269 404 } 405 270 406 double __floatsidf(int i) 271 407 { … … 275 411 return da.d; 276 412 } 413 414 long double __floatsitf(int i) 415 { 416 float128 ta; 417 418 ta = int_to_float128(i); 419 return ta.ld; 420 } 277 421 278 422 float __floatdisf(long i) … … 283 427 return fa.f; 284 428 } 429 285 430 double __floatdidf(long i) 286 431 { … … 290 435 return da.d; 291 436 } 437 438 long double __floatditf(long i) 439 { 440 float128 ta; 441 442 ta = long_to_float128(i); 443 return ta.ld; 444 } 292 445 293 446 float __floattisf(long long i) … … 298 451 return fa.f; 299 452 } 453 300 454 double __floattidf(long long i) 301 455 { … … 306 460 } 307 461 462 long double __floattitf(long long i) 463 { 464 float128 ta; 465 466 ta = longlong_to_float128(i); 467 return ta.ld; 468 } 469 308 470 float __floatunsisf(unsigned int i) 309 471 { … … 313 475 return fa.f; 314 476 } 477 315 478 double __floatunsidf(unsigned int i) 316 479 { … … 320 483 return da.d; 321 484 } 485 486 long double __floatunsitf(unsigned int i) 487 { 488 float128 ta; 489 490 ta = uint_to_float128(i); 491 return ta.ld; 492 } 322 493 323 494 float __floatundisf(unsigned long i) … … 328 499 return fa.f; 329 500 } 501 330 502 double __floatundidf(unsigned long i) 331 503 { … … 335 507 return da.d; 336 508 } 509 510 long double __floatunditf(unsigned long i) 511 { 512 float128 ta; 513 514 ta = ulong_to_float128(i); 515 return ta.ld; 516 } 337 517 338 518 float __floatuntisf(unsigned long long i) … … 343 523 return fa.f; 344 524 } 525 345 526 double __floatuntidf(unsigned long long i) 346 527 { … … 351 532 } 352 533 534 long double __floatuntitf(unsigned long long i) 535 { 536 float128 ta; 537 538 ta = ulonglong_to_float128(i); 539 return ta.ld; 540 } 541 353 542 /* Comparison functions */ 354 /* Comparison functions */355 356 /* a<b .. 1357 * a=b .. 0358 * a>b .. 1359 * */360 543 361 544 int __cmpsf2(float a, float b) … … 364 547 fa.f = a; 365 548 fb.f = b; 366 if ( (isFloat32NaN(fa))  (isFloat32NaN(fb)) ) { 549 550 if ((isFloat32NaN(fa))  (isFloat32NaN(fb))) { 367 551 return 1; /* no special constant for unordered  maybe signaled? */ 368 }; 369 552 } 370 553 371 554 if (isFloat32eq(fa, fb)) { 372 555 return 0; 373 } ;556 } 374 557 375 558 if (isFloat32lt(fa, fb)) { 376 559 return 1; 377 }; 560 } 561 378 562 return 1; 379 563 } 380 564 565 int __cmpdf2(double a, double b) 566 { 567 float64 da, db; 568 da.d = a; 569 db.d = b; 570 571 if ((isFloat64NaN(da))  (isFloat64NaN(db))) { 572 return 1; /* no special constant for unordered  maybe signaled? */ 573 } 574 575 if (isFloat64eq(da, db)) { 576 return 0; 577 } 578 579 if (isFloat64lt(da, db)) { 580 return 1; 581 } 582 583 return 1; 584 } 585 586 int __cmptf2(long double a, long double b) 587 { 588 float128 ta, tb; 589 ta.ld = a; 590 tb.ld = b; 591 592 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 593 return 1; /* no special constant for unordered  maybe signaled? */ 594 } 595 596 if (isFloat128eq(ta, tb)) { 597 return 0; 598 } 599 600 if (isFloat128lt(ta, tb)) { 601 return 1; 602 } 603 604 return 1; 605 } 606 381 607 int __unordsf2(float a, float b) 382 608 { … … 384 610 fa.f = a; 385 611 fb.f = b; 386 return ( (isFloat32NaN(fa))  (isFloat32NaN(fb)) ); 387 } 388 389 /** 390 * @return zero, if neither argument is a NaN and are equal 391 * */ 612 return ((isFloat32NaN(fa))  (isFloat32NaN(fb))); 613 } 614 615 int __unorddf2(double a, double b) 616 { 617 float64 da, db; 618 da.d = a; 619 db.d = b; 620 return ((isFloat64NaN(da))  (isFloat64NaN(db))); 621 } 622 623 int __unordtf2(long double a, long double b) 624 { 625 float128 ta, tb; 626 ta.ld = a; 627 tb.ld = b; 628 return ((isFloat128NaN(ta))  (isFloat128NaN(tb))); 629 } 630 392 631 int __eqsf2(float a, float b) 393 632 { … … 395 634 fa.f = a; 396 635 fb.f = b; 397 if ( (isFloat32NaN(fa))  (isFloat32NaN(fb))) {398 /* TODO: sigNaNs */399 return 1; 400 };636 if ((isFloat32NaN(fa))  (isFloat32NaN(fb))) { 637 /* TODO: sigNaNs */ 638 return 1; 639 } 401 640 return isFloat32eq(fa, fb)  1; 402 641 } 403 642 404 /* strange behavior, but it was in gcc documentation */ 643 int __eqdf2(double a, double b) 644 { 645 float64 da, db; 646 da.d = a; 647 db.d = b; 648 if ((isFloat64NaN(da))  (isFloat64NaN(db))) { 649 /* TODO: sigNaNs */ 650 return 1; 651 } 652 return isFloat64eq(da, db)  1; 653 } 654 655 int __eqtf2(long double a, long double b) 656 { 657 float128 ta, tb; 658 ta.ld = a; 659 tb.ld = b; 660 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 661 /* TODO: sigNaNs */ 662 return 1; 663 } 664 return isFloat128eq(ta, tb)  1; 665 } 666 405 667 int __nesf2(float a, float b) 406 668 { 669 /* strange behavior, but it was in gcc documentation */ 407 670 return __eqsf2(a, b); 408 671 } 409 672 410 /* return value >= 0 if a>=b and neither is NaN */ 673 int __nedf2(double a, double b) 674 { 675 /* strange behavior, but it was in gcc documentation */ 676 return __eqdf2(a, b); 677 } 678 679 int __netf2(long double a, long double b) 680 { 681 /* strange behavior, but it was in gcc documentation */ 682 return __eqtf2(a, b); 683 } 684 411 685 int __gesf2(float a, float b) 412 686 { … … 414 688 fa.f = a; 415 689 fb.f = b; 416 if ( (isFloat32NaN(fa))  (isFloat32NaN(fb)) ) { 417 /* TODO: sigNaNs*/ 418 return 1; 419 }; 690 691 if ((isFloat32NaN(fa))  (isFloat32NaN(fb))) { 692 /* TODO: sigNaNs */ 693 return 1; 694 } 420 695 421 696 if (isFloat32eq(fa, fb)) { 422 697 return 0; 423 } ;698 } 424 699 425 700 if (isFloat32gt(fa, fb)) { 426 701 return 1; 427 };702 } 428 703 429 704 return 1; 430 705 } 431 706 432 /** Return negative value, if a<b and neither is NaN*/ 707 int __gedf2(double a, double b) 708 { 709 float64 da, db; 710 da.d = a; 711 db.d = b; 712 713 if ((isFloat64NaN(da))  (isFloat64NaN(db))) { 714 /* TODO: sigNaNs */ 715 return 1; 716 } 717 718 if (isFloat64eq(da, db)) { 719 return 0; 720 } 721 722 if (isFloat64gt(da, db)) { 723 return 1; 724 } 725 726 return 1; 727 } 728 729 int __getf2(long double a, long double b) 730 { 731 float128 ta, tb; 732 ta.ld = a; 733 tb.ld = b; 734 735 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 736 /* TODO: sigNaNs */ 737 return 1; 738 } 739 740 if (isFloat128eq(ta, tb)) { 741 return 0; 742 } 743 744 if (isFloat128gt(ta, tb)) { 745 return 1; 746 } 747 748 return 1; 749 } 750 433 751 int __ltsf2(float a, float b) 434 752 { … … 436 754 fa.f = a; 437 755 fb.f = b; 438 if ( (isFloat32NaN(fa))  (isFloat32NaN(fb)) ) { 439 /* TODO: sigNaNs*/ 440 return 1; 441 }; 756 757 if ((isFloat32NaN(fa))  (isFloat32NaN(fb))) { 758 /* TODO: sigNaNs */ 759 return 1; 760 } 761 442 762 if (isFloat32lt(fa, fb)) { 443 763 return 1; 444 }; 764 } 765 445 766 return 0; 446 767 } 447 768 448 /* return value <= 0 if a<=b and neither is NaN */ 769 int __ltdf2(double a, double b) 770 { 771 float64 da, db; 772 da.d = a; 773 db.d = b; 774 775 if ((isFloat64NaN(da))  (isFloat64NaN(db))) { 776 /* TODO: sigNaNs */ 777 return 1; 778 } 779 780 if (isFloat64lt(da, db)) { 781 return 1; 782 } 783 784 return 0; 785 } 786 787 int __lttf2(long double a, long double b) 788 { 789 float128 ta, tb; 790 ta.ld = a; 791 tb.ld = b; 792 793 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 794 /* TODO: sigNaNs */ 795 return 1; 796 } 797 798 if (isFloat128lt(ta, tb)) { 799 return 1; 800 } 801 802 return 0; 803 } 804 449 805 int __lesf2(float a, float b) 450 806 { … … 452 808 fa.f = a; 453 809 fb.f = b; 454 if ( (isFloat32NaN(fa))  (isFloat32NaN(fb)) ) { 455 /* TODO: sigNaNs*/ 456 return 1; 457 }; 810 811 if ((isFloat32NaN(fa))  (isFloat32NaN(fb))) { 812 /* TODO: sigNaNs */ 813 return 1; 814 } 458 815 459 816 if (isFloat32eq(fa, fb)) { 460 817 return 0; 461 } ;818 } 462 819 463 820 if (isFloat32lt(fa, fb)) { 464 821 return 1; 465 };822 } 466 823 467 824 return 1; 468 825 } 469 826 470 /** Return positive value, if a>b and neither is NaN*/ 827 int __ledf2(double a, double b) 828 { 829 float64 da, db; 830 da.d = a; 831 db.d = b; 832 833 if ((isFloat64NaN(da))  (isFloat64NaN(db))) { 834 /* TODO: sigNaNs */ 835 return 1; 836 } 837 838 if (isFloat64eq(da, db)) { 839 return 0; 840 } 841 842 if (isFloat64lt(da, db)) { 843 return 1; 844 } 845 846 return 1; 847 } 848 849 int __letf2(long double a, long double b) 850 { 851 float128 ta, tb; 852 ta.ld = a; 853 tb.ld = b; 854 855 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 856 /* TODO: sigNaNs */ 857 return 1; 858 } 859 860 if (isFloat128eq(ta, tb)) { 861 return 0; 862 } 863 864 if (isFloat128lt(ta, tb)) { 865 return 1; 866 } 867 868 return 1; 869 } 870 471 871 int __gtsf2(float a, float b) 472 872 { … … 474 874 fa.f = a; 475 875 fb.f = b; 476 if ( (isFloat32NaN(fa))  (isFloat32NaN(fb)) ) { 477 /* TODO: sigNaNs*/ 478 return 1; 479 }; 876 877 if ((isFloat32NaN(fa))  (isFloat32NaN(fb))) { 878 /* TODO: sigNaNs */ 879 return 1; 880 } 881 480 882 if (isFloat32gt(fa, fb)) { 481 883 return 1; 482 }; 884 } 885 483 886 return 0; 484 887 } 485 888 486 /* Other functions */ 487 488 float __powisf2(float a, int b) 489 { 490 /* TODO: */ 491 float32 fa; 492 fa.binary = FLOAT32_NAN; 493 return fa.f; 494 } 889 int __gtdf2(double a, double b) 890 { 891 float64 da, db; 892 da.d = a; 893 db.d = b; 894 895 if ((isFloat64NaN(da))  (isFloat64NaN(db))) { 896 /* TODO: sigNaNs */ 897 return 1; 898 } 899 900 if (isFloat64gt(da, db)) { 901 return 1; 902 } 903 904 return 0; 905 } 906 907 int __gttf2(long double a, long double b) 908 { 909 float128 ta, tb; 910 ta.ld = a; 911 tb.ld = b; 912 913 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 914 /* TODO: sigNaNs */ 915 return 1; 916 } 917 918 if (isFloat128gt(ta, tb)) { 919 return 1; 920 } 921 922 return 0; 923 } 924 925 926 927 #ifdef SPARC_SOFTFLOAT 928 929 /* SPARC quadrupleprecision wrappers */ 930 931 void _Qp_add(long double *c, long double *a, long double *b) 932 { 933 *c = __addtf3(*a, *b); 934 } 935 936 void _Qp_sub(long double *c, long double *a, long double *b) 937 { 938 *c = __subtf3(*a, *b); 939 } 940 941 void _Qp_mul(long double *c, long double *a, long double *b) 942 { 943 *c = __multf3(*a, *b); 944 } 945 946 void _Qp_div(long double *c, long double *a, long double *b) 947 { 948 *c = __divtf3(*a, *b); 949 } 950 951 void _Qp_neg(long double *c, long double *a) 952 { 953 *c = __negtf2(*a); 954 } 955 956 void _Qp_stoq(long double *c, float a) 957 { 958 *c = __extendsftf2(a); 959 } 960 961 void _Qp_dtoq(long double *c, double a) 962 { 963 *c = __extenddftf2(a); 964 } 965 966 float _Qp_qtos(long double *a) 967 { 968 return __trunctfsf2(*a); 969 } 970 971 double _Qp_qtod(long double *a) 972 { 973 return __trunctfdf2(*a); 974 } 975 976 int _Qp_qtoi(long double *a) 977 { 978 return __fixtfsi(*a); 979 } 980 981 unsigned int _Qp_qtoui(long double *a) 982 { 983 return __fixunstfsi(*a); 984 } 985 986 long _Qp_qtox(long double *a) 987 { 988 return __fixtfdi(*a); 989 } 990 991 unsigned long _Qp_qtoux(long double *a) 992 { 993 return __fixunstfdi(*a); 994 } 995 996 void _Qp_itoq(long double *c, int a) 997 { 998 *c = __floatsitf(a); 999 } 1000 1001 void _Qp_uitoq(long double *c, unsigned int a) 1002 { 1003 *c = __floatunsitf(a); 1004 } 1005 1006 void _Qp_xtoq(long double *c, long a) 1007 { 1008 *c = __floatditf(a); 1009 } 1010 1011 void _Qp_uxtoq(long double *c, unsigned long a) 1012 { 1013 *c = __floatunditf(a); 1014 } 1015 1016 int _Qp_cmp(long double *a, long double *b) 1017 { 1018 float128 ta, tb; 1019 ta.ld = *a; 1020 tb.ld = *b; 1021 1022 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1023 return 3; 1024 } 1025 1026 if (isFloat128eq(ta, tb)) { 1027 return 0; 1028 } 1029 1030 if (isFloat128lt(ta, tb)) { 1031 return 1; 1032 } 1033 1034 return 2; 1035 } 1036 1037 int _Qp_cmpe(long double *a, long double *b) 1038 { 1039 /* strange, but is defined this way in SPARC Compliance Definition */ 1040 return _Qp_cmp(a, b); 1041 } 1042 1043 int _Qp_feq(long double *a, long double *b) 1044 { 1045 float128 ta, tb; 1046 ta.ld = *a; 1047 tb.ld = *b; 1048 1049 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1050 return 0; 1051 } 1052 1053 return isFloat128eq(ta, tb); 1054 } 1055 1056 int _Qp_fge(long double *a, long double *b) 1057 { 1058 float128 ta, tb; 1059 ta.ld = *a; 1060 tb.ld = *b; 1061 1062 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1063 return 0; 1064 } 1065 1066 return isFloat128eq(ta, tb)  isFloat128gt(ta, tb); 1067 } 1068 1069 int _Qp_fgt(long double *a, long double *b) 1070 { 1071 float128 ta, tb; 1072 ta.ld = *a; 1073 tb.ld = *b; 1074 1075 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1076 return 0; 1077 } 1078 1079 return isFloat128gt(ta, tb); 1080 } 1081 1082 int _Qp_fle(long double*a, long double *b) 1083 { 1084 float128 ta, tb; 1085 ta.ld = *a; 1086 tb.ld = *b; 1087 1088 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1089 return 0; 1090 } 1091 1092 return isFloat128eq(ta, tb)  isFloat128lt(ta, tb); 1093 } 1094 1095 int _Qp_flt(long double *a, long double *b) 1096 { 1097 float128 ta, tb; 1098 ta.ld = *a; 1099 tb.ld = *b; 1100 1101 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1102 return 0; 1103 } 1104 1105 return isFloat128lt(ta, tb); 1106 } 1107 1108 int _Qp_fne(long double *a, long double *b) 1109 { 1110 float128 ta, tb; 1111 ta.ld = *a; 1112 tb.ld = *b; 1113 1114 if ((isFloat128NaN(ta))  (isFloat128NaN(tb))) { 1115 return 1; 1116 } 1117 1118 return !isFloat128eq(ta, tb); 1119 } 1120 1121 #endif 495 1122 496 1123 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.