1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
|
/******************************************************************************
Copyright (c) 2007-2024, Intel Corp.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#define BASE_NAME pow
#include "dpml_ux.h"
#if !defined(MAKE_INCLUDE)
# include STR(BUILD_FILE_NAME)
#endif
/*
** The DPML supports two different varieties of the power function: one for
** which 0^0 and (-x)^integer are exceptions (fortran semantics) and one for
** which 0^0 is 1 and (-x)^integer is computed as if by successive
** multiplications (C semantics). Both of these routines call a common
** interface routine which unpacks the unpacks the argument and performs any
** necessary argument screening. The common interface routine then calls an
** evaluation routine to actually compute the function result.
**
**
** BASIC ALGORITHM
** ---------------
**
** The power function x^y is computed as 2^[y*log2(x)]. The key point in the
** algorithm is to insure a sufficient number of accurate bits in the product
** y*log2(x) to guarantee the accuracy of the final result. In particular,
** if we write:
**
** y*log2(x) = I + h |h| < 1/2 (1)
**
** Then
**
** x^y = 2^[y*log2(x)]
** = 2^(I + h)
** = (2^I)*(2^h)
**
** Since the multiplication by 2^I can be done by incrementing the exponent
** field of 2^h, the basic design criteria is to insure a sufficient number
** of bits in h. For this design, we would like h to have 7 guard bits. That
** means we want the total number of good bits in h to be about 120. Since I
** can contain as many as 14 bits, this means that y*log(x) must contain at
** least 134 good bits. This of course is a problem, because the unpacked
** format only has 128 fraction bits. The approach we take is to represent
** log2(x) in high and low pieces.
*/
/*
** UX_POW is the common evaluation routine for the both the fortran and C
** power functions. It assumes that all exceptional arguments, except those
** that might cause overflow or underflow, have been screened out.
*/
#if !defined(UX_POW)
# define UX_POW __INTERNAL_NAME(ux_pow__)
#endif
void
UX_POW( UX_FLOAT * x, UX_FLOAT * y, UX_FLOAT * result)
{
WORD cnt;
UX_SIGN_TYPE sign;
UX_EXPONENT_TYPE exponent;
UX_FRACTION_DIGIT_TYPE _Z, LOG2_HI, tmp_digit, I, inc;
UX_FLOAT tmp[3], log2_hi, log2_lo, z, z_lo, u, r, w, h;
/*
** COMPUTING LOG IN HI AND LOW PIECES
** -----------------------------------
**
** Given x = 2^n*g, where 1/sqrt(2) <= g < sqrt(2), we can compute log2(x)
** as:
** 2(g - 1) 2
** z = ---------- w = z
** (g + 1)ln2
** 2k
** __Inf [z*ln2/2)^2]
** log2(x) = n + z > -------------
** /__k=0 (2k+1)
**
**
** log2(x) ~ n + z + z^3*p(z^2)
**
**
** Letting z = z_hi + z_lo, then we can write
**
** log2(x) ~ n + (z_hi + z_lo) + z*w*p(w)
** = (n + z_hi) + (z_lo + z*w*p(w))
** = L_hi + L_lo. (3)
**
** The trick here is to define z_hi, so that n + z_hi is exactly
** representable in one digit. This involves computing z to extended
** precision which is a fairly complicated process. We begin by
** putting x in th form x = 2^n*g where 1/sqrt(2) < g <= sqrt(2)
*/
exponent = G_UX_EXPONENT(x);
tmp_digit = G_UX_MSD(x);
if (tmp_digit <= ONE_OVER_SQRT_2)
exponent--;
UX_DECR_EXPONENT(x, exponent);
/*
** In preporation for computing z_hi and z_lo, we compute z as
**
** t0 <-- g + 1
** t1 <-- g - 1
** r <-- 2/(t0*ln2)
** z <-- t1*r
**
** At this point, we can also compute the polynomial, z^3*p(z^2)
*/
UX_COPY( UX_ONE, result);
ADDSUB(x, result, ADD_SUB, tmp);
DIVIDE( UX_TWO_OVER_LN2, &tmp[0], FULL_PRECISION, &r);
MULTIPLY( &r, &tmp[1], &z);
/*
** If the binary exponent of z is i, the binary exponent of n is j, and k
** is the number of bits in a fraction digit, then we want to take the high
** k-(j-i) bits of z and combine them with n to create log2_hi. If n is
** zero, just take log2_hi to be the high k bits of z. We denote the
** high bits of z used to make log2_hi as integer, Z and let z_hi = 2^i*Z/K,
** where K = 2^k.
**
** Get the necessary bits of z and compute n + high bits of z as the
** integer LOG2_HI
*/
_Z = G_UX_MSD(&z);
if (exponent == 0)
{
LOG2_HI = _Z;
exponent = G_UX_EXPONENT(&z);
sign = G_UX_SIGN(&z);
}
else
{ /* n != 0, convert n to unpacked */
cnt = WORD_TO_UX(exponent, &tmp[2]);
exponent = BITS_PER_UX_FRACTION_DIGIT_TYPE - cnt;
cnt = exponent - G_UX_EXPONENT(&z);
LOG2_HI = G_UX_MSD(&tmp[2]);
sign = G_UX_SIGN(&tmp[2]);
/* Take high bits from z */
if (cnt >= BITS_PER_WORD)
_Z = 0;
else
{
tmp_digit = (_Z >> cnt);
_Z = tmp_digit << cnt;
tmp_digit = (G_UX_SIGN(&z) != G_UX_SIGN(&tmp[2])) ?
-tmp_digit : tmp_digit;
LOG2_HI += tmp_digit;
}
}
/*
** Compute log2_lo = z^3*p(z)
*/
MULTIPLY( &z, &z, &tmp[2]);
EVALUATE_RATIONAL(
&tmp[2],
POW_LOG2_COEF_ARRAY,
POW_LOG2_COEF_ARRAY_DEGREE,
NUMERATOR_FLAGS( POST_MULTIPLY ),
&log2_lo);
MULTIPLY( &z, &log2_lo, &log2_lo);
/*
** If we denote the k most significant digit of ln2/2 as L (i.e.
** ln2/2 ~ L/(2*K)),
** then we can define
**
** LO(ln2/2) = ln2/2 - L/(2*K)
**
** Then we can obtain an approximation to z_lo by:
**
** z_lo = z - z_hi
** = t1/[t0*(ln2/2)] - z_hi
** = (t1 - t0*(ln2/2)*z_hi)/[t0*(ln2/2)]
** = { t1 - t0*[L/(2*K) + LO(ln2/2)]*z_hi }/[t0*(ln2/2)]
** = { t1 - t0*[2^(i-1)*(L*Z)/K^2 + LO(ln2/2)*z_hi}/[t0*(ln2/2)]
** = { t1 - t0*[2^(i-1)*L*Z/K^2 + t0*z_hi*LO(ln2/2)] }/[t0*(ln2/2)]
**
** We now define
**
** u = 2^(i-1)*(L*Z)/K^2
**
** So that z_lo can now be written as;
**
** z_lo = { t1 - t0*[(2^i)*L*Z/K^2 + t0*z_hi*LO(ln2/2)] }/[t0*(ln2/2)]
** = [ t1 - t0*( u + t0*z_hi*LO(ln2/2)) ]/[t0*(ln2/2)]
** = [ (t1 - t0*u) - t0*z_hi*LO(ln2/2)]/[t0*(ln2/2)]
** = (t1 - t0*u)/[t0*(ln2/2)] - t0*z_hi*LO(ln2/2)/[t0*(ln2/2)]
** = (t1 - t0*u)*r - z_hi*LO(ln2/2)/(ln2/2)
** = (t1 - t0*u)*r - z_hi*2*LO(ln2)/ln2
**
** With some care taken to prevent a loss of significance when computing
** t1 - t0*u.
*/
if (_Z != 0)
{
/*
** We used some bits from Z so compute z_lo and add it to
** log2_lo. Start the computation by getting u equal to the
** the high part of z*ln2 = 2^(i-1)*Z*L/K^2, also create z_hi
** in unpacked format
*/
CLR_UX_LOW_FRACTION(&z);
P_UX_MSD(&z, _Z);
EXTENDED_DIGIT_MULTIPLY( _Z, MSD_OF_LN2, _Z, tmp_digit);
UX_SET_SIGN_EXP_MSD( &u, G_UX_SIGN(&z), G_UX_EXPONENT(&z)-1, _Z);
P_UX_FRACTION_DIGIT( &u, 1, tmp_digit);
/*
** Compute t1 - t0*u carefully by using the extended multiply
**
** The value of z_lo is actually computed into the location
** z so we can handle the Z = 0 (i.e. z_lo = z) case in the
** main flow
*/
EXTENDED_MULTIPLY( &tmp[0], &u, &tmp[0], &tmp[2]);
ADDSUB(&tmp[1], &tmp[0], SUB, &tmp[0]);
ADDSUB(&tmp[0], &tmp[2], SUB, &tmp[0]);
/*
** Now compute = (t0 - t1*u)*r - z_hi*(ln2_lo/ln2) into the same
** location as z. This way the add for the Z == 0 and != 0 cases
** join up for the last add.
*/
MULTIPLY(&tmp[0], &r, &tmp[0]);
MULTIPLY(&z, UX_LN2_LO_OVER_LN2, &tmp[1]);
ADDSUB(&tmp[0], &tmp[1], SUB, &z);
}
ADDSUB(&z, &log2_lo, ADD, &log2_lo);
/*
** Compute I = rint(y*log2(x)) and h = y*log2(x) - I. Start
** by obtaining I from y*log2_hi.
**
** When x is very close to 1 and |y| is large, the current value
** of log2_hi doesn't have a enough significant bits to compute
** I. So before we start, we take some of the high bits of log2_lo
** and put them in log2_hi
*/
inc = G_UX_MSD(&log2_lo);
cnt = exponent - G_UX_EXPONENT(&log2_lo);
if ( cnt < BITS_PER_UX_FRACTION_DIGIT_TYPE)
{
tmp_digit = inc & MAKE_MASK(cnt, 0);
P_UX_MSD(&log2_lo, tmp_digit);
inc >>= cnt;
inc = (sign ^ G_UX_SIGN(&log2_lo)) ? -inc : inc;
LOG2_HI += inc;
}
/*
** Now that there are enough bits in log2_hi, compute I from the
** product of y*log2_hi. In the process, screen for outrageous overflow
** or underflow and create an unpacked form of log2_hi for future use.
*/
UX_SET_SIGN_EXP_MSD(&tmp[0], sign, exponent, LOG2_HI);
exponent += G_UX_EXPONENT(y);
if ( exponent > (signed) (F_EXP_WIDTH + 2))
goto overflow_underflow;
/*
** Get I by multiplying the high digit of y with LOG2_HI and rounding
** to the nearest integer. We compute y*log2_hi(x) here so it can be
** shared with the code for I = 0 and I != 0
*/
I = 0;
sign ^= G_UX_SIGN(y);
EXTENDED_MULTIPLY( &tmp[0], y, &h, &tmp[0]);
if (exponent >= 0)
{
UMULH( LOG2_HI, G_UX_MSD(y), I );
cnt = BITS_PER_UX_FRACTION_DIGIT_TYPE - exponent;
inc = SET_BIT(cnt - 1);
tmp_digit = I + inc;
inc += inc;
if (tmp_digit >= I)
I = tmp_digit & -inc;
else
{ /* A carry out occurred on the increment */
cnt--;
I = UX_MSB;
exponent++;
}
/*
** Now we need to compute
**
** h = y*log2(x) - I
** = y*[log2_hi(x) + log2_lo(x)] - I
** = [y*log2_hi(x) - I] + y*log2_lo(x)
**
** for I != 0.
*/
UX_SET_SIGN_EXP_MSD(&tmp[1], sign, exponent, I);
ADDSUB(&h, &tmp[1], SUB, &h);
ADDSUB(&h, &tmp[0], ADD, &h);
}
MULTIPLY(y, &log2_lo, &tmp[0]);
ADDSUB(&tmp[0], &h, ADD, &h);
/*
** Evaluate 2^h and do scaling
*/
EVALUATE_RATIONAL(
&h,
POW2_COEF_ARRAY,
POW2_COEF_ARRAY_DEGREE,
NUMERATOR_FLAGS(STANDARD),
result);
I >>= cnt;
tmp_digit = -I;
I = sign ? tmp_digit : I;
UX_INCR_EXPONENT(result, I);
return;
overflow_underflow:
exponent = (sign ^ G_UX_SIGN(y)) ?
UX_UNDERFLOW_EXPONENT : UX_OVERFLOW_EXPONENT;
UX_SET_SIGN_EXP_MSD(result, 0, exponent, UX_MSB);
return;
}
/*
** C_UX_POW is the common interface routine is responsible for unpacking the
** arguments and processing exceptional input. A big part of the exceptional
** input processing is the definition and accessing of the class-to-action
** array. However, there are two sets of exceptional cases that are not handled
** by the UNPACK routines. They are:
**
** (1) x is +/- Normal and y is +/- Infinity
** (2) x is -Normal or -Denormal and y is +/- Normal.
**
** In the first case, we need to determine is |x| is less than, equal or
** greater than 1 and return 0, INVALID or Infinity respectively. In the
** second case, we need to determine if y is an integer. If not, signal
** invalid. Otherwise, compute |x|^y and set the sign of the result according
** to the parity of y.
*/
#if !defined(C_UX_POW)
# define C_UX_POW __INTERNAL_NAME(C_ux_pow__)
#endif
static void
C_UX_POW(
_X_FLOAT * packed_x, _X_FLOAT * packed_y,
U_WORD const * class_to_action_array,
_X_FLOAT * packed_result OPT_EXCEPTION_INFO_DECLARATION )
{
WORD x_fp_class, y_fp_class, index;
UX_SIGN_TYPE sign;
UX_EXPONENT_TYPE exponent;
UX_FRACTION_DIGIT_TYPE tmp_digit;
WORD underflow_error, overflow_error;
WORD local_class_action_array[3], *p;
UX_FLOAT unpacked_x, unpacked_y, unpacked_result, tmp;
/*
** Initialize unpacked result to underflow. We will use
** the underflow logic in the pack routine to report errors
** detected here. Also initialize error codes
*/
P_UX_EXPONENT(&unpacked_result, UX_UNDERFLOW_EXPONENT);
P_UX_MSD(&unpacked_result, UX_MSB);
underflow_error = POWER_UNDERFLOW;
overflow_error = POWER_POS_OVERFLOW;
/* Unpack x and y */
x_fp_class = UNPACK2(
packed_x,
packed_y,
&unpacked_x,
&unpacked_y,
class_to_action_array,
packed_result
OPT_EXCEPTION_INFO_ARGUMENT );
if (0 >= x_fp_class)
return;
/*
** OK, now we need to screen for the two sets of exceptional
** cases not covered by the class to action mappings.
*/
sign = 0;
y_fp_class = x_fp_class & MAKE_MASK(F_C_CLASS_BIT_WIDTH, 0);
x_fp_class = ( x_fp_class >> F_C_CLASS_BIT_WIDTH) &
MAKE_MASK(F_C_CLASS_BIT_WIDTH, 0);
if (F_C_INF == F_C_BASE_CLASS(y_fp_class))
{
exponent = G_UX_EXPONENT(&unpacked_x);
if ((exponent == 1) && UX_FRACTION_IS_ONE_HALF(&unpacked_x))
{
underflow_error = POWER_ONE_TO_INF;
goto pack_it;
}
sign = F_C_IS_NEG_CLASS(y_fp_class) ^ (exponent <= 0);
if ((!sign) && F_C_IS_NEG_CLASS(x_fp_class))
{
underflow_error = POWER_NEG_BASE;
goto pack_it;
}
tmp_digit = sign ? 0 : F_EXP_MASK;
goto return_zero_or_inf;
}
else if (F_C_IS_NEG_CLASS(x_fp_class))
{
index = UX_RND_TO_INT(&unpacked_y, RZ_BIT_VECTOR | FRACTION_RESULT,
NOT_USED, &tmp);
if ((G_UX_MSD(&tmp) != 0) && (x_fp_class != F_C_NEG_INF) &&
(x_fp_class != F_C_NEG_ZERO))
{ /* y was not an integer */
underflow_error = POWER_NEG_BASE;
goto pack_it;
}
if (index & 1)
{
sign = UX_SIGN_BIT;
overflow_error = POWER_NEG_OVERFLOW;
}
if (SET_BIT(x_fp_class) &
( SET_BIT(F_C_NEG_INF) | SET_BIT(F_C_NEG_ZERO) ))
{
tmp_digit = (((sign) && (G_UX_MSD(&tmp) != 0)) ?
F_SIGN_BIT_MASK : 0);
return_zero_or_inf:
P_X_DIGIT(packed_result, 0, tmp_digit);
P_X_DIGIT(packed_result, 1, 0);
# if (BITS_PER_DIGIT == 32)
P_X_DIGIT(packed_result, 2, 0);
P_X_DIGIT(packed_result, 3, 0);
# endif
return;
}
P_UX_SIGN(&unpacked_x, 0);
}
UX_POW(&unpacked_x, &unpacked_y, &unpacked_result);
P_UX_SIGN(&unpacked_result, sign);
pack_it:
PACK(
&unpacked_result,
packed_result,
underflow_error,
overflow_error
OPT_EXCEPTION_INFO_ARGUMENT );
}
#undef F_ENTRY_NAME
#define F_ENTRY_NAME F_POW_NAME
X_XX_PROTO(F_ENTRY_NAME, packed_result, packed_x, packed_y)
{
EXCEPTION_INFO_DECL
DECLARE_X_FLOAT(packed_result)
INIT_EXCEPTION_INFO;
C_UX_POW(
PASS_ARG_X_FLOAT(packed_x),
PASS_ARG_X_FLOAT(packed_y),
ANSI_C_POW_CLASS_TO_ACTION_MAP,
PASS_RET_X_FLOAT(packed_result)
OPT_EXCEPTION_INFO );
RETURN_X_FLOAT(packed_result);
}
#undef F_ENTRY_NAME
#define F_ENTRY_NAME F_POW_E_NAME
X_XX_PROTO(F_ENTRY_NAME, packed_result, packed_x, packed_y)
{
EXCEPTION_INFO_DECL
DECLARE_X_FLOAT(packed_result)
INIT_EXCEPTION_INFO;
C_UX_POW(
PASS_ARG_X_FLOAT(packed_x),
PASS_ARG_X_FLOAT(packed_y),
FORTRAN_POW_CLASS_TO_ACTION_MAP,
PASS_RET_X_FLOAT(packed_result)
OPT_EXCEPTION_INFO );
RETURN_X_FLOAT(packed_result);
}
/*
** UX_EXP2 is the internal routine that evaluates exp2 = 2^x.
**
** First, screen for certain overflow and underflow (expon > F_EXP_WIDTH + 3)
** and for tiny x's where 2^x ~ 1 (exponent < -F_PRECISION). Then, isolate
** any integer part I of x (exponent will be > 0), convert it to UX and
** subtract from x. Use the rational approx of 2^f from the pow code.
** Finally, add (signed) I to the exponent of the result.
**
*/
#if !defined(UX_EXP2)
# define UX_EXP2 __INTERNAL_NAME(ux_exp2__)
#endif
static void
UX_EXP2( UX_FLOAT * x, UX_FLOAT * result)
{
WORD cnt;
UX_SIGN_TYPE sign;
UX_EXPONENT_TYPE exponent, scale;
UX_FRACTION_DIGIT_TYPE tmp_digit, I, inc;
UX_FLOAT w, h;
exponent = G_UX_EXPONENT(x);
sign = G_UX_SIGN(x);
cnt = 0;
if ( (UX_UNSIGNED_EXPONENT_TYPE) (exponent + 114) > (18 + 114))
{
if ( exponent > 0)
{ /* exponent > 18 , definite overflow or underflow */
UX_COPY(x, result);
scale = sign ? UX_UNDERFLOW_EXPONENT : UX_OVERFLOW_EXPONENT;
P_UX_EXPONENT(result, scale);
}
else
{ /* x is close to 0, just return 1 */
UX_COPY( UX_ONE, result);
}
return;
}
I = 0;
if (exponent >= 0)
{
I = G_UX_MSD(x);
cnt = BITS_PER_UX_FRACTION_DIGIT_TYPE - exponent;
inc = SET_BIT(cnt - 1);
I >>= (cnt - 1);
I <<= (cnt - 1);
tmp_digit = I + inc;
inc += inc;
if (tmp_digit >= I)
I = tmp_digit & -inc;
else
{ /* A carry out occurred on the increment */
cnt--;
I = UX_MSB;
exponent++;
}
UX_SET_SIGN_EXP_MSD(&w, sign, exponent, I);
ADDSUB(x, &w, SUB, &h);
}
else
{
UX_COPY(x, &h);
}
EVALUATE_RATIONAL(
&h,
POW2_COEF_ARRAY,
POW2_COEF_ARRAY_DEGREE,
NUMERATOR_FLAGS(STANDARD),
result);
I >>= cnt;
tmp_digit = -I;
I = sign ? tmp_digit : I;
UX_INCR_EXPONENT(result, I);
return;
}
/*
** F_EXP2_NAME is the user level packed x-float routine
*/
#undef F_ENTRY_NAME
#define F_ENTRY_NAME F_EXP2_NAME
X_X_PROTO(F_ENTRY_NAME, packed_result, packed_argument)
{
WORD fp_class;
UX_FLOAT unpacked_argument, unpacked_result;
EXCEPTION_INFO_DECL
DECLARE_X_FLOAT(packed_result)
INIT_EXCEPTION_INFO;
fp_class = UNPACK(
PASS_ARG_X_FLOAT(packed_argument),
& unpacked_argument,
EXP2_CLASS_TO_ACTION_MAP,
PASS_RET_X_FLOAT(packed_result)
OPT_EXCEPTION_INFO );
if (0 > fp_class)
RETURN_X_FLOAT(packed_result);
UX_EXP2( &unpacked_argument, &unpacked_result);
PACK(
&unpacked_result,
PASS_RET_X_FLOAT(packed_result),
EXP2_UNDERFLOW,
EXP2_OVERFLOW
OPT_EXCEPTION_INFO );
RETURN_X_FLOAT(packed_result);
}
#if defined(MAKE_INCLUDE)
@divert -append divertText
precision = ceil(UX_PRECISION/8) + 4;
START_TABLE;
/*
** As previously noted, not all of the error cases can be encoded in the
** class to action mapping. For these cases, we return unpacked results
** and left C_UX_POW figure out what to do.
*/
TABLE_COMMENT("ansi-c class-to-action-mapping");
PRINT_CLASS_TO_ACTION_TBL_DEF( "ANSI_C_POW_CLASS_TO_ACTION_MAP");
/* Index 0: for x, just unpack and get fp_class */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(1) + 0);
/* Index 1: Class to index map */
PRINT_64_TBL_ITEM(
CLASS_TO_INDEX( F_C_SIG_NAN, 2) +
CLASS_TO_INDEX( F_C_QUIET_NAN, 3) +
CLASS_TO_INDEX( F_C_POS_INF, 4) +
CLASS_TO_INDEX( F_C_NEG_INF, 5) +
CLASS_TO_INDEX( F_C_POS_NORM, 6) +
CLASS_TO_INDEX( F_C_NEG_NORM, 7) +
CLASS_TO_INDEX( F_C_POS_DENORM, 8) +
CLASS_TO_INDEX( F_C_NEG_DENORM, 9) +
CLASS_TO_INDEX( F_C_POS_ZERO, 10) +
CLASS_TO_INDEX( F_C_NEG_ZERO , 11) );
/* Index 2: mapping for y when x is SNaN */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(10) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 3: mapping for y when x is QNaN */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(9) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 4: mapping for y when x is +Inf */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(8) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 5: mapping for y when x is -Inf */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(7) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 6: mapping for y when x is +Norm */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(6) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 7: mapping for y when x is -Norm */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(5) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 8: mapping for y when x is +Denorm */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(4) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 9: mapping for y when x is -Denorm */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(3) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 10: mapping for y when x is +Zero */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(2) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_ERROR, 6) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 6) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 11: mapping for y when x is -Zero */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(1) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_ERROR, 6) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 6) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
TABLE_COMMENT("data for the above mapping");
PRINT_U_TBL_ITEM( /* data 1 */ NULL );
PRINT_U_TBL_ITEM( /* data 2 */ ZERO );
PRINT_U_TBL_ITEM( /* data 3 */ ONE );
PRINT_U_TBL_ITEM( /* data 4 */ INF );
PRINT_U_TBL_ITEM( /* data 5 */ POWER_NEG_BASE );
PRINT_U_TBL_ITEM( /* data 6 */ POWER_ZERO_TO_NEG );
TABLE_COMMENT("fortran class-to-action-mapping");
PRINT_CLASS_TO_ACTION_TBL_DEF( "FORTRAN_POW_CLASS_TO_ACTION_MAP");
/* Index 0: for x */
PRINT_64_TBL_ITEM(
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 0) );
/* Index 1: Index map for unpacking y */
PRINT_64_TBL_ITEM( CLASS_TO_INDEX( F_C_SIG_NAN, 0) +
CLASS_TO_INDEX( F_C_QUIET_NAN, 0) +
CLASS_TO_INDEX( F_C_POS_INF, 3) +
CLASS_TO_INDEX( F_C_NEG_INF, 2) +
CLASS_TO_INDEX( F_C_POS_NORM, 4) +
CLASS_TO_INDEX( F_C_NEG_NORM, 2) +
CLASS_TO_INDEX( F_C_POS_DENORM, 5) +
CLASS_TO_INDEX( F_C_NEG_DENORM, 2) +
CLASS_TO_INDEX( F_C_POS_ZERO, 6) +
CLASS_TO_INDEX( F_C_NEG_ZERO , 7) );
/* Index 2: mapping for y when x is negative and not zero */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(6) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_ERROR, 5) );
/* Index 3: mapping for y when x is +Inf */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(5) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_ERROR, 5) );
/* Index 4: mapping for y when x is +Norm */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(4) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 5: mapping for y when x is +Denorm */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(3) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 3) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 3) );
/* Index 6: mapping for y when x is +Zero */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(2) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_VALUE, 4) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_ERROR, 6) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 6) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_ERROR, 5) );
/* Index 7: mapping for y when x is -Zero */
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(1) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 1) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_NORM, RETURN_NEGATIVE, 2) +
CLASS_TO_ACTION( F_C_NEG_NORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 2) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_ERROR, 5) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_ERROR, 5) );
TABLE_COMMENT("data for the above mapping");
PRINT_U_TBL_ITEM( /* Data 1 */ NULL );
PRINT_U_TBL_ITEM( /* Data 2 */ ZERO );
PRINT_U_TBL_ITEM( /* Data 3 */ ONE );
PRINT_U_TBL_ITEM( /* Data 4 */ INF );
PRINT_U_TBL_ITEM( /* Data 5 */ POWER_NEG_BASE );
PRINT_U_TBL_ITEM( /* Data 6 */ POWER_ZERO_TO_NEG );
TABLE_COMMENT("exp2 class-to-action-mapping");
PRINT_CLASS_TO_ACTION_TBL_DEF( "EXP2_CLASS_TO_ACTION_MAP\t");
PRINT_64_TBL_ITEM( CLASS_TO_ACTION_DISP(1) +
CLASS_TO_ACTION( F_C_SIG_NAN, RETURN_QUIET_NAN, 0) +
CLASS_TO_ACTION( F_C_QUIET_NAN, RETURN_VALUE, 0) +
CLASS_TO_ACTION( F_C_POS_INF, RETURN_ERROR, 3) +
CLASS_TO_ACTION( F_C_NEG_INF, RETURN_ERROR, 2) +
CLASS_TO_ACTION( F_C_POS_DENORM, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_NEG_DENORM, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_POS_ZERO, RETURN_VALUE, 1) +
CLASS_TO_ACTION( F_C_NEG_ZERO , RETURN_VALUE, 1) );
TABLE_COMMENT("Data for the class to action mappings");
PRINT_U_TBL_ITEM( /* data 1 */ ONE );
PRINT_U_TBL_ITEM( /* data 2 */ EXP2_OF_NEG_INF );
PRINT_U_TBL_ITEM( /* data 3 */ EXP2_OF_INF );
TABLE_COMMENT("high word of sqrt(2) and ln2");
tmp = trunc(bldexp(1/sqrt(2), BITS_PER_UX_FRACTION_DIGIT_TYPE));
PRINT_UX_FRACTION_DIGIT_TBL_VDEF_ITEM( "ONE_OVER_SQRT_2\t\t", tmp);
log2_hi = trunc(bldexp(log(2), BITS_PER_UX_FRACTION_DIGIT_TYPE));
PRINT_UX_FRACTION_DIGIT_TBL_VDEF_ITEM( "MSD_OF_LN2\t\t", log2_hi);
TABLE_COMMENT("1, 1/ln2 and log2_lo/ln2 in unpacked format");
PRINT_UX_TBL_ADEF_ITEM( "UX_ONE\t\t\t", 1);
tmp = 2/log(2);
PRINT_UX_TBL_ADEF_ITEM( "UX_TWO_OVER_LN2\t\t", tmp);
save_precision = precision;
precision = ceil(3*UX_PRECISION/16) + 8;
tmp = log(2);
tmp = (tmp - bldexp(log2_hi, -BITS_PER_UX_FRACTION_DIGIT_TYPE))/tmp;
PRINT_UX_TBL_ADEF_ITEM( "UX_LN2_LO_OVER_LN2\t", tmp);
precision = save_precision;
ln2 = log(2);
scale = ln2/2;
zero_value = scale*scale/3;
inv_scale = 1/scale;
function __log2(x)
{
if (x == 0)
return zero_value;
else
return (inv_scale*atanh(x*scale) - x)/(x*x*x);
}
max_arg = 2*(sqrt(2) - 1)^2/log(2);
save_precision = precision;
precision = precision = ceil(UX_PRECISION/8) + 8;
TABLE_COMMENT("Fixed point coefficients for log2 evaluation");
remes(REMES_FIND_POLYNOMIAL + REMES_RELATIVE_WEIGHT + REMES_SQUARE_ARG,
0, max_arg, __log2, UX_PRECISION, °ree, &ux_rational_coefs);
precision = save_precision;
PRINT_FIXED_128_TBL_ADEF("POW_LOG2_COEF_ARRAY\t");
PRINT_WORD_DEF("POW_LOG2_COEF_ARRAY_DEGREE", degree);
print_ux_rational_coefs(degree, 0, 0);
scale = log(2);
function __2_pow(x)
{
if (x == 0)
return 1;
else
return exp(x*scale);
}
max_arg = .5;
save_precision = precision;
precision = precision = ceil(UX_PRECISION/8) + 8;
TABLE_COMMENT("Fixed point coefficients for 2^h evaluation");
remes(REMES_FIND_POLYNOMIAL + REMES_RELATIVE_WEIGHT + REMES_LINEAR_ARG,
-max_arg, max_arg, __2_pow, UX_PRECISION, °ree, &ux_rational_coefs);
precision = save_precision;
PRINT_FIXED_128_TBL_ADEF("POW2_COEF_ARRAY\t\t");
PRINT_WORD_DEF("POW2_COEF_ARRAY_DEGREE\t", degree);
print_ux_rational_coefs(degree, 0, 0);
END_TABLE;
@end_divert
@eval my $tableText; \
my $outText = MphocEval( GetStream( "divertText" ) ); \
my $defineText = Egrep( "\\#define", $outText, \$tableText ); \
$outText = "$tableText\n\n$defineText"; \
my $headerText = GetHeaderText( STR(BUILD_FILE_NAME), \
"Definitions and constants for floating " . \
"point power routines", __FILE__ ); \
print "$headerText\n$outText\n";
#endif
|