58 #define FPLIB_IDC 128 // Input Denormal
59 #define FPLIB_IXC 16 // Inexact
60 #define FPLIB_UFC 8 // Underflow
61 #define FPLIB_OFC 4 // Overflow
62 #define FPLIB_DZC 2 // Division by Zero
63 #define FPLIB_IOC 1 // Invalid Operation
65 static inline uint16_t
68 return shift < 16 ? x << shift : 0;
71 static inline uint16_t
74 return shift < 16 ? x >> shift : 0;
77 static inline uint32_t
80 return shift < 32 ? x << shift : 0;
83 static inline uint32_t
86 return shift < 32 ? x >> shift : 0;
89 static inline uint64_t
92 return shift < 64 ? x << shift : 0;
95 static inline uint64_t
98 return shift < 64 ? x >> shift : 0;
102 lsl128(uint64_t *
r0, uint64_t *r1, uint64_t x0, uint64_t x1, uint32_t
shift)
107 }
else if (shift < 64) {
108 *r1 = x1 << shift | x0 >> (64 -
shift);
110 }
else if (shift < 128) {
111 *r1 = x0 << (shift - 64);
120 lsr128(uint64_t *
r0, uint64_t *r1, uint64_t x0, uint64_t x1, uint32_t
shift)
125 }
else if (shift < 64) {
126 *r0 = x0 >> shift | x1 << (64 -
shift);
128 }
else if (shift < 128) {
129 *r0 = x1 >> (shift - 64);
140 uint32_t
mask = ((uint32_t)1 << 31) - 1;
142 uint64_t
a1 = a >> 31 &
mask;
143 uint64_t b0 = b &
mask;
144 uint64_t
b1 = b >> 31 &
mask;
145 uint64_t p0 = a0 * b0;
146 uint64_t p2 = a1 *
b1;
147 uint64_t p1 = (a0 +
a1) * (b0 + b1) - p0 - p2;
149 uint64_t s1 = (s0 >> 31) + p1;
150 uint64_t s2 = (s1 >> 31) + p2;
151 *x0 = (s0 &
mask) | (s1 & mask) << 31 | s2 << 62;
156 void mul64x32(uint64_t *x0, uint64_t *x1, uint64_t
a, uint32_t
b)
158 uint64_t
t0 = (uint64_t)(uint32_t)a *
b;
159 uint64_t
t1 = (t0 >> 32) + (a >> 32) *
b;
160 *x0 = t1 << 32 | (uint32_t)t0;
165 add128(uint64_t *x0, uint64_t *x1, uint64_t
a0, uint64_t
a1, uint64_t b0,
169 *x1 = a1 + b1 + (*x0 <
a0);
173 sub128(uint64_t *x0, uint64_t *x1, uint64_t
a0, uint64_t
a1, uint64_t b0,
177 *x1 = a1 - b1 - (*x0 >
a0);
183 return (a1 < b1 ? -1 : a1 > b1 ? 1 : a0 < b0 ? -1 : a0 > b0 ? 1 : 0);
186 static inline uint16_t
195 for (shift = 8;
shift; shift >>= 1) {
196 if (!(mnt >> (16 - shift))) {
204 static inline uint32_t
213 for (shift = 16;
shift; shift >>= 1) {
214 if (!(mnt >> (32 - shift))) {
222 static inline uint64_t
231 for (shift = 32;
shift; shift >>= 1) {
232 if (!(mnt >> (64 - shift))) {
257 for (shift = 32;
shift; shift >>= 1) {
258 if (!(x1 >> (64 - shift))) {
259 x1 = x1 << shift | x0 >> (64 -
shift);
269 static inline uint16_t
272 return sgn << 15 | exp << 10 | (mnt & (((uint16_t)1 << 10) - 1));
275 static inline uint32_t
278 return sgn << 31 | exp << 23 | (mnt & (((uint32_t)1 << 23) - 1));
281 static inline uint64_t
284 return (uint64_t)sgn << 63 | exp << 52 | (mnt & (((uint64_t)1 << 52) - 1));
287 static inline uint16_t
293 static inline uint32_t
299 static inline uint64_t
305 static inline uint16_t
311 static inline uint32_t
317 static inline uint64_t
323 static inline uint16_t
329 static inline uint32_t
335 static inline uint64_t
341 static inline uint16_t
344 return fp16_pack(0, 31, (uint16_t)1 << 9);
347 static inline uint32_t
350 return fp32_pack(0, 255, (uint32_t)1 << 22);
353 static inline uint64_t
356 return fp64_pack(0, 2047, (uint64_t)1 << 51);
365 *mnt = x & (((uint16_t)1 << 10) - 1);
369 *mnt |= (uint16_t)1 << 10;
381 *exp = x >> 23 & 255;
382 *mnt = x & (((uint32_t)1 << 23) - 1);
386 *mnt |= (uint32_t)1 << 23;
401 *exp = x >> 52 & 2047;
402 *mnt = x & (((uint64_t)1 << 52) - 1);
406 *mnt |= (uint64_t)1 << 52;
416 static inline uint32_t
419 if (!(a >> 22 & 1)) {
421 a |= (uint32_t)1 << 22;
426 static inline uint64_t
429 if (!(a >> 51 & 1)) {
431 a |= (uint64_t)1 << 51;
439 int a_exp = a >> 23 & 255;
440 uint32_t a_mnt = a & (((uint32_t)1 << 23) - 1);
441 int b_exp = b >> 23 & 255;
442 uint32_t b_mnt = b & (((uint32_t)1 << 23) - 1);
445 if (a_exp == 255 && a_mnt && !(a_mnt >> 22 & 1))
447 if (b_exp == 255 && b_mnt && !(b_mnt >> 22 & 1))
451 if (a_exp == 255 && a_mnt)
453 if (b_exp == 255 && b_mnt)
462 int a_exp = a >> 52 & 2047;
463 uint64_t a_mnt = a & (((uint64_t)1 << 52) - 1);
464 int b_exp = b >> 52 & 2047;
465 uint64_t b_mnt = b & (((uint64_t)1 << 52) - 1);
468 if (a_exp == 2047 && a_mnt && !(a_mnt >> 51 & 1))
470 if (b_exp == 2047 && b_mnt && !(b_mnt >> 51 & 1))
474 if (a_exp == 2047 && a_mnt)
476 if (b_exp == 2047 && b_mnt)
485 int a_exp = a >> 23 & 255;
486 uint32_t a_mnt = a & (((uint32_t)1 << 23) - 1);
487 int b_exp = b >> 23 & 255;
488 uint32_t b_mnt = b & (((uint32_t)1 << 23) - 1);
489 int c_exp = c >> 23 & 255;
490 uint32_t c_mnt = c & (((uint32_t)1 << 23) - 1);
493 if (a_exp == 255 && a_mnt && !(a_mnt >> 22 & 1))
495 if (b_exp == 255 && b_mnt && !(b_mnt >> 22 & 1))
497 if (c_exp == 255 && c_mnt && !(c_mnt >> 22 & 1))
501 if (a_exp == 255 && a_mnt)
503 if (b_exp == 255 && b_mnt)
505 if (c_exp == 255 && c_mnt)
514 int a_exp = a >> 52 & 2047;
515 uint64_t a_mnt = a & (((uint64_t)1 << 52) - 1);
516 int b_exp = b >> 52 & 2047;
517 uint64_t b_mnt = b & (((uint64_t)1 << 52) - 1);
518 int c_exp = c >> 52 & 2047;
519 uint64_t c_mnt = c & (((uint64_t)1 << 52) - 1);
522 if (a_exp == 2047 && a_mnt && !(a_mnt >> 51 & 1))
524 if (b_exp == 2047 && b_mnt && !(b_mnt >> 51 & 1))
526 if (c_exp == 2047 && c_mnt && !(c_mnt >> 51 & 1))
530 if (a_exp == 2047 && a_mnt)
532 if (b_exp == 2047 && b_mnt)
534 if (c_exp == 2047 && c_mnt)
552 mnt = (uint16_t)1 << 12 | mnt >> 4 | ((mnt & 31) != 0);
560 int_mant =
lsr16(mnt, 3 - exp);
561 error = (
lsr16(mnt, 1 - exp) & 3) | !!(mnt & (
lsl16(1, 1 - exp) - 1));
564 if (!biased_exp && error) {
569 if ((rm ==
FPLIB_RN && (error == 3 ||
570 (error == 2 && (int_mant & 1)))) ||
573 if (int_mant == (uint32_t)1 << 10) {
577 if (int_mant == (uint32_t)1 << 11) {
590 if (biased_exp >= 31) {
600 if (biased_exp >= 32) {
610 return fp16_pack(sgn, biased_exp, int_mant);
629 mnt = (uint32_t)1 << 25 | mnt >> 7 | ((mnt & 255) != 0);
637 int_mant =
lsr32(mnt, 3 - exp);
638 error = (
lsr32(mnt, 1 - exp) & 3) | !!(mnt & (
lsl32(1, 1 - exp) - 1));
641 if (!biased_exp && error) {
646 if ((rm ==
FPLIB_RN && (error == 3 ||
647 (error == 2 && (int_mant & 1)))) ||
650 if (int_mant == (uint32_t)1 << 23) {
654 if (int_mant == (uint32_t)1 << 24) {
666 if (biased_exp >= 255) {
680 return fp32_pack(sgn, biased_exp, int_mant);
686 return fp32_round_(sgn, exp, mnt, mode & 3, mode, flags);
705 mnt = (uint64_t)1 << 54 | mnt >> 10 | ((mnt & 0x3ff) != 0);
713 int_mant =
lsr64(mnt, 3 - exp);
714 error = (
lsr64(mnt, 1 - exp) & 3) | !!(mnt & (
lsl64(1, 1 - exp) - 1));
717 if (!biased_exp && error) {
722 if ((rm ==
FPLIB_RN && (error == 3 ||
723 (error == 2 && (int_mant & 1)))) ||
726 if (int_mant == (uint64_t)1 << 52) {
730 if (int_mant == (uint64_t)1 << 53) {
742 if (biased_exp >= 2047) {
756 return fp64_pack(sgn, biased_exp, int_mant);
762 return fp64_round_(sgn, exp, mnt, mode & 3, mode, flags);
768 int a_sgn, a_exp, b_sgn, b_exp;
769 uint32_t a_mnt, b_mnt;
771 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
772 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
774 if ((a_exp == 255 && (uint32_t)(a_mnt << 9)) ||
775 (b_exp == 255 && (uint32_t)(b_mnt << 9))) {
776 if ((a_exp == 255 && (uint32_t)(a_mnt << 9) && !(a >> 22 & 1)) ||
777 (b_exp == 255 && (uint32_t)(b_mnt << 9) && !(b >> 22 & 1)))
781 return a == b || (!a_mnt && !b_mnt);
787 int a_sgn, a_exp, b_sgn, b_exp;
788 uint32_t a_mnt, b_mnt;
790 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
791 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
793 if ((a_exp == 255 && (uint32_t)(a_mnt << 9)) ||
794 (b_exp == 255 && (uint32_t)(b_mnt << 9))) {
798 if (!a_mnt && !b_mnt)
803 return a_sgn ^ (a_exp > b_exp);
805 return a_sgn ^ (a_mnt > b_mnt);
812 int a_sgn, a_exp, b_sgn, b_exp;
813 uint32_t a_mnt, b_mnt;
815 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
816 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
818 if ((a_exp == 255 && (uint32_t)(a_mnt << 9)) ||
819 (b_exp == 255 && (uint32_t)(b_mnt << 9))) {
823 if (!a_mnt && !b_mnt)
828 return a_sgn ^ (a_exp > b_exp);
830 return a_sgn ^ (a_mnt > b_mnt);
837 int a_sgn, a_exp, b_sgn, b_exp;
838 uint64_t a_mnt, b_mnt;
840 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
841 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
843 if ((a_exp == 2047 && (uint64_t)(a_mnt << 12)) ||
844 (b_exp == 2047 && (uint64_t)(b_mnt << 12))) {
845 if ((a_exp == 2047 && (uint64_t)(a_mnt << 12) && !(a >> 51 & 1)) ||
846 (b_exp == 2047 && (uint64_t)(b_mnt << 12) && !(b >> 51 & 1)))
850 return a == b || (!a_mnt && !b_mnt);
856 int a_sgn, a_exp, b_sgn, b_exp;
857 uint64_t a_mnt, b_mnt;
859 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
860 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
862 if ((a_exp == 2047 && (uint64_t)(a_mnt << 12)) ||
863 (b_exp == 2047 && (uint64_t)(b_mnt << 12))) {
867 if (!a_mnt && !b_mnt)
872 return a_sgn ^ (a_exp > b_exp);
874 return a_sgn ^ (a_mnt > b_mnt);
881 int a_sgn, a_exp, b_sgn, b_exp;
882 uint64_t a_mnt, b_mnt;
884 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
885 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
887 if ((a_exp == 2047 && (uint64_t)(a_mnt << 12)) ||
888 (b_exp == 2047 && (uint64_t)(b_mnt << 12))) {
892 if (!a_mnt && !b_mnt)
897 return a_sgn ^ (a_exp > b_exp);
899 return a_sgn ^ (a_mnt > b_mnt);
906 int a_sgn, a_exp, b_sgn, b_exp, x_sgn, x_exp;
907 uint32_t a_mnt, b_mnt,
x, x_mnt;
909 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
910 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
919 if (a_exp == 255 && b_exp == 255 && a_sgn != b_sgn) {
922 }
else if (a_exp == 255) {
924 }
else if (b_exp == 255) {
926 }
else if (!a_mnt && !b_mnt && a_sgn == b_sgn) {
932 if (a_exp >= b_exp) {
933 b_mnt = (
lsr32(b_mnt, a_exp - b_exp) |
934 !!(b_mnt & (
lsl32(1, a_exp - b_exp) - 1)));
937 a_mnt = (
lsr32(a_mnt, b_exp - a_exp) |
938 !!(a_mnt & (
lsl32(1, b_exp - a_exp) - 1)));
943 if (a_sgn == b_sgn) {
944 x_mnt = a_mnt + b_mnt;
945 }
else if (a_mnt >= b_mnt) {
946 x_mnt = a_mnt - b_mnt;
949 x_mnt = b_mnt - a_mnt;
959 return fp32_round(x_sgn, x_exp + 5, x_mnt << 1, mode, flags);
965 int a_sgn, a_exp, b_sgn, b_exp, x_sgn, x_exp;
966 uint64_t a_mnt, b_mnt,
x, x_mnt;
968 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
969 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
978 if (a_exp == 2047 && b_exp == 2047 && a_sgn != b_sgn) {
981 }
else if (a_exp == 2047) {
983 }
else if (b_exp == 2047) {
985 }
else if (!a_mnt && !b_mnt && a_sgn == b_sgn) {
991 if (a_exp >= b_exp) {
992 b_mnt = (
lsr64(b_mnt, a_exp - b_exp) |
993 !!(b_mnt & (
lsl64(1, a_exp - b_exp) - 1)));
996 a_mnt = (
lsr64(a_mnt, b_exp - a_exp) |
997 !!(a_mnt & (
lsl64(1, b_exp - a_exp) - 1)));
1002 if (a_sgn == b_sgn) {
1003 x_mnt = a_mnt + b_mnt;
1004 }
else if (a_mnt >= b_mnt) {
1005 x_mnt = a_mnt - b_mnt;
1008 x_mnt = b_mnt - a_mnt;
1018 return fp64_round(x_sgn, x_exp + 8, x_mnt << 1, mode, flags);
1024 int a_sgn, a_exp, b_sgn, b_exp, x_sgn, x_exp;
1025 uint32_t a_mnt, b_mnt,
x;
1028 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1029 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
1036 if ((a_exp == 255 && !b_mnt) || (b_exp == 255 && !a_mnt)) {
1039 }
else if (a_exp == 255 || b_exp == 255) {
1041 }
else if (!a_mnt || !b_mnt) {
1046 x_sgn = a_sgn ^ b_sgn;
1047 x_exp = a_exp + b_exp - 110;
1048 x_mnt = (uint64_t)a_mnt * b_mnt;
1052 x_mnt =
lsr64(x_mnt, 31) | !!
lsl64(x_mnt, 33);
1054 return fp32_round(x_sgn, x_exp, x_mnt, mode, flags);
1060 int a_sgn, a_exp, b_sgn, b_exp, x_sgn, x_exp;
1061 uint64_t a_mnt, b_mnt,
x;
1062 uint64_t x0_mnt, x1_mnt;
1064 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1065 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
1072 if ((a_exp == 2047 && !b_mnt) || (b_exp == 2047 && !a_mnt)) {
1075 }
else if (a_exp == 2047 || b_exp == 2047) {
1077 }
else if (!a_mnt || !b_mnt) {
1082 x_sgn = a_sgn ^ b_sgn;
1083 x_exp = a_exp + b_exp - 1000;
1084 mul62x62(&x0_mnt, &x1_mnt, a_mnt, b_mnt);
1088 x0_mnt = x1_mnt << 1 | !!x0_mnt;
1090 return fp64_round(x_sgn, x_exp, x0_mnt, mode, flags);
1095 int mode,
int *flags)
1097 int a_sgn, a_exp, b_sgn, b_exp, c_sgn, c_exp, x_sgn, x_exp, y_sgn, y_exp;
1098 uint32_t a_mnt, b_mnt, c_mnt,
x;
1099 uint64_t x_mnt, y_mnt;
1101 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1102 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
1103 fp32_unpack(&c_sgn, &c_exp, &c_mnt, c, mode, flags);
1108 if (a_exp == 255 && (a_mnt >> 22 & 1) &&
1109 ((!b_mnt && c_exp == 255 && !(uint32_t)(c_mnt << 9)) ||
1110 (!c_mnt && b_exp == 255 && !(uint32_t)(b_mnt << 9)))) {
1120 if ((b_exp == 255 && !c_mnt) ||
1121 (c_exp == 255 && !b_mnt) ||
1122 (a_exp == 255 && (b_exp == 255 || c_exp == 255) &&
1123 (a_sgn != (b_sgn ^ c_sgn)))) {
1129 if (b_exp == 255 || c_exp == 255)
1131 if (!a_mnt && (!b_mnt || !c_mnt) && a_sgn == (b_sgn ^ c_sgn))
1136 x_mnt = (uint64_t)a_mnt << 27;
1139 y_sgn = b_sgn ^ c_sgn;
1140 y_exp = b_exp + c_exp - 113;
1141 y_mnt = (uint64_t)b_mnt * c_mnt << 3;
1147 if (x_exp >= y_exp) {
1148 y_mnt = (
lsr64(y_mnt, x_exp - y_exp) |
1149 !!(y_mnt & (
lsl64(1, x_exp - y_exp) - 1)));
1152 x_mnt = (
lsr64(x_mnt, y_exp - x_exp) |
1153 !!(x_mnt & (
lsl64(1, y_exp - x_exp) - 1)));
1156 if (x_sgn == y_sgn) {
1157 x_mnt = x_mnt + y_mnt;
1158 }
else if (x_mnt >= y_mnt) {
1159 x_mnt = x_mnt - y_mnt;
1162 x_mnt = y_mnt - x_mnt;
1172 x_mnt = x_mnt >> 31 | !!(uint32_t)(x_mnt << 1);
1174 return fp32_round(x_sgn, x_exp + scale, x_mnt, mode, flags);
1179 int mode,
int *flags)
1181 int a_sgn, a_exp, b_sgn, b_exp, c_sgn, c_exp, x_sgn, x_exp, y_sgn, y_exp;
1182 uint64_t a_mnt, b_mnt, c_mnt,
x;
1183 uint64_t x0_mnt, x1_mnt, y0_mnt, y1_mnt;
1185 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1186 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
1187 fp64_unpack(&c_sgn, &c_exp, &c_mnt, c, mode, flags);
1192 if (a_exp == 2047 && (a_mnt >> 51 & 1) &&
1193 ((!b_mnt && c_exp == 2047 && !(uint64_t)(c_mnt << 12)) ||
1194 (!c_mnt && b_exp == 2047 && !(uint64_t)(b_mnt << 12)))) {
1204 if ((b_exp == 2047 && !c_mnt) ||
1205 (c_exp == 2047 && !b_mnt) ||
1206 (a_exp == 2047 && (b_exp == 2047 || c_exp == 2047) &&
1207 (a_sgn != (b_sgn ^ c_sgn)))) {
1213 if (b_exp == 2047 || c_exp == 2047)
1215 if (!a_mnt && (!b_mnt || !c_mnt) && a_sgn == (b_sgn ^ c_sgn))
1224 y_sgn = b_sgn ^ c_sgn;
1225 y_exp = b_exp + c_exp - 1003;
1226 mul62x62(&y0_mnt, &y1_mnt, b_mnt, c_mnt << 3);
1227 if (!y0_mnt && !y1_mnt) {
1232 if (x_exp >= y_exp) {
1234 lsl128(&t0, &t1, y0_mnt, y1_mnt,
1235 x_exp - y_exp < 128 ? 128 - (x_exp - y_exp) : 0);
1236 lsr128(&y0_mnt, &y1_mnt, y0_mnt, y1_mnt, x_exp - y_exp);
1237 y0_mnt |= !!(t0 |
t1);
1241 lsl128(&t0, &t1, x0_mnt, x1_mnt,
1242 y_exp - x_exp < 128 ? 128 - (y_exp - x_exp) : 0);
1243 lsr128(&x0_mnt, &x1_mnt, x0_mnt, x1_mnt, y_exp - x_exp);
1244 x0_mnt |= !!(t0 |
t1);
1247 if (x_sgn == y_sgn) {
1248 add128(&x0_mnt, &x1_mnt, x0_mnt, x1_mnt, y0_mnt, y1_mnt);
1249 }
else if (
cmp128(x0_mnt, x1_mnt, y0_mnt, y1_mnt) >= 0) {
1250 sub128(&x0_mnt, &x1_mnt, x0_mnt, x1_mnt, y0_mnt, y1_mnt);
1253 sub128(&x0_mnt, &x1_mnt, y0_mnt, y1_mnt, x0_mnt, x1_mnt);
1256 if (!x0_mnt && !x1_mnt) {
1263 x0_mnt = x1_mnt << 1 | !!x0_mnt;
1265 return fp64_round(x_sgn, x_exp + scale, x0_mnt, mode, flags);
1271 int a_sgn, a_exp, b_sgn, b_exp, x_sgn, x_exp;
1272 uint32_t a_mnt, b_mnt,
x;
1275 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1276 fp32_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
1282 if ((a_exp == 255 && b_exp == 255) || (!a_mnt && !b_mnt)) {
1286 if (a_exp == 255 || !b_mnt) {
1291 if (!a_mnt || b_exp == 255)
1296 x_sgn = a_sgn ^ b_sgn;
1297 x_exp = a_exp - b_exp + 172;
1298 x_mnt = ((uint64_t)a_mnt << 18) / b_mnt;
1299 x_mnt |= (x_mnt * b_mnt != (uint64_t)a_mnt << 18);
1303 x_mnt = x_mnt >> 31 | !!(uint32_t)(x_mnt << 1);
1305 return fp32_round(x_sgn, x_exp, x_mnt, mode, flags);
1311 int a_sgn, a_exp, b_sgn, b_exp, x_sgn, x_exp,
c;
1312 uint64_t a_mnt, b_mnt,
x, x_mnt, x0_mnt, x1_mnt;
1314 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1315 fp64_unpack(&b_sgn, &b_exp, &b_mnt, b, mode, flags);
1321 if ((a_exp == 2047 && b_exp == 2047) || (!a_mnt && !b_mnt)) {
1325 if (a_exp == 2047 || !b_mnt) {
1330 if (!a_mnt || b_exp == 2047)
1336 x_mnt = ~(uint64_t)0 / (b_mnt >> 31);
1337 mul64x32(&x0_mnt, &x1_mnt, b_mnt, x_mnt);
1338 sub128(&x0_mnt, &x1_mnt, 0, (uint64_t)1 << 32, x0_mnt, x1_mnt);
1339 lsr128(&x0_mnt, &x1_mnt, x0_mnt, x1_mnt, 32);
1340 mul64x32(&x0_mnt, &x1_mnt, x0_mnt, x_mnt);
1341 lsr128(&x0_mnt, &x1_mnt, x0_mnt, x1_mnt, 33);
1344 x_sgn = a_sgn ^ b_sgn;
1345 x_exp = a_exp - b_exp + 1031;
1346 mul62x62(&x0_mnt, &x1_mnt, x0_mnt, a_mnt >> 2);
1347 lsr128(&x0_mnt, &x1_mnt, x0_mnt, x1_mnt, 4);
1351 mul62x62(&x0_mnt, &x1_mnt, b_mnt >> 2, x_mnt + 1);
1352 c =
cmp128(x0_mnt, x1_mnt, 0, a_mnt >> 11);
1359 return fp64_round(x_sgn, x_exp, x_mnt << 1 | !!c, mode, flags);
1388 int a_sgn, a_exp, x_sgn, x_exp;
1389 uint32_t a_mnt,
x, x_mnt;
1392 fp32_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1395 if (a_exp == 255 && (uint32_t)(a_mnt << 9))
1402 if (a_exp == 255 && !a_sgn) {
1417 x = (a_mnt >> 2) + (a_mnt >> 3) + (5 << 28);
1420 x = (a_mnt / (x >> 15) + (x >> 16)) << 15;
1423 x = (a_mnt / (x >> 15) + (x >> 16)) << 15;
1426 x = ((((uint64_t)a_mnt << 32) /
x) >> 2) + (x >> 1);
1429 x_exp = (a_exp + 147) >> 1;
1430 x_mnt = ((x - (1 << 5)) >> 6) + 1;
1431 t1 = (uint64_t)x_mnt * x_mnt;
1432 t0 = (uint64_t)a_mnt << 19;
1439 return fp32_round(x_sgn, x_exp, x_mnt << 1 | (t1 != t0), mode, flags);
1445 int a_sgn, a_exp, x_sgn, x_exp,
c;
1446 uint64_t a_mnt, x_mnt,
r, x0, x1;
1449 fp64_unpack(&a_sgn, &a_exp, &a_mnt, a, mode, flags);
1452 if (a_exp == 2047 && (uint64_t)(a_mnt << 12)) {
1459 if (a_exp == 2047 && !a_sgn)
1473 x = (a_mnt >> 34) + (a_mnt >> 35) + (5 << 28);
1476 x = ((a_mnt >> 32) / (x >> 15) + (x >> 16)) << 15;
1479 x = ((a_mnt >> 32) / (x >> 15) + (x >> 16)) << 15;
1482 x = ((a_mnt /
x) >> 2) + (x >> 1);
1485 r = ((uint64_t)1 << 62) /
x;
1488 mul64x32(&x0, &x1, -(uint64_t)x * r << 1, r);
1489 lsr128(&x0, &x1, x0, x1, 31);
1492 mul62x62(&x0, &x1, a_mnt >> 10, x0 >> 2);
1493 lsl128(&x0, &x1, x0, x1, 5);
1494 lsr128(&x0, &x1, x0, x1, 56);
1496 x0 = ((uint64_t)x << 31) + (x0 >> 1);
1499 x_exp = (a_exp + 1053) >> 1;
1501 x_mnt = ((x_mnt - (1 << 8)) >> 9) + 1;
1503 lsl128(&x0, &x1, x0, x1, 19);
1504 c =
cmp128(x0, x1, 0, a_mnt);
1510 return fp64_round(x_sgn, x_exp, x_mnt << 1 | !!c, mode, flags);
1516 return (((
int) fpscr) >> 22) & 0xF;
1523 bool underflow =
false;
1540 if ((flags &
FPLIB_IXC) && !(underflow && fpscr.fz)) {
1609 return op & ~((uint32_t)1 << 31);
1616 return op & ~((uint64_t)1 << 63);
1645 int sgn1, exp1, sgn2, exp2, result;
1646 uint32_t mnt1, mnt2;
1648 fp32_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
1649 fp32_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
1651 if ((exp1 == 255 && (uint32_t)(mnt1 << 9)) ||
1652 (exp2 == 255 && (uint32_t)(mnt2 << 9))) {
1654 if ((exp1 == 255 && (uint32_t)(mnt1 << 9) && !(mnt1 >> 22 & 1)) ||
1655 (exp2 == 255 && (uint32_t)(mnt2 << 9) && !(mnt2 >> 22 & 1)) ||
1659 if (op1 == op2 || (!mnt1 && !mnt2)) {
1661 }
else if (sgn1 != sgn2) {
1662 result = sgn1 ? 8 : 2;
1663 }
else if (exp1 != exp2) {
1664 result = sgn1 ^ (exp1 < exp2) ? 8 : 2;
1666 result = sgn1 ^ (mnt1 < mnt2) ? 8 : 2;
1681 int sgn1, exp1, sgn2, exp2, result;
1682 uint64_t mnt1, mnt2;
1684 fp64_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
1685 fp64_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
1687 if ((exp1 == 2047 && (uint64_t)(mnt1 << 12)) ||
1688 (exp2 == 2047 && (uint64_t)(mnt2 << 12))) {
1690 if ((exp1 == 2047 && (uint64_t)(mnt1 << 12) && !(mnt1 >> 51 & 1)) ||
1691 (exp2 == 2047 && (uint64_t)(mnt2 << 12) && !(mnt2 >> 51 & 1)) ||
1695 if (op1 == op2 || (!mnt1 && !mnt2)) {
1697 }
else if (sgn1 != sgn2) {
1698 result = sgn1 ? 8 : 2;
1699 }
else if (exp1 != exp2) {
1700 result = sgn1 ^ (exp1 < exp2) ? 8 : 2;
1702 result = sgn1 ^ (mnt1 < mnt2) ? 8 : 2;
1714 return fp16_pack(op >> 31, 31, (uint16_t)1 << 9 | op >> 13);
1720 return fp16_pack(op >> 63, 31, (uint16_t)1 << 9 | op >> 42);
1726 return fp32_pack(op >> 15, 255, (uint32_t)1 << 22 | (uint32_t)op << 13);
1732 return fp32_pack(op >> 63, 255, (uint32_t)1 << 22 | op >> 29);
1738 return fp64_pack(op >> 15, 2047, (uint64_t)1 << 51 | (uint64_t)op << 42);
1744 return fp64_pack(op >> 31, 2047, (uint64_t)1 << 51 | (uint64_t)op << 29);
1750 return fp32_pack(sgn, 127, (uint64_t)1 << 22);
1756 return fp64_pack(sgn, 1023, (uint64_t)1 << 51);
1762 return fp32_pack(sgn, 128, (uint64_t)1 << 22);
1768 return fp64_pack(sgn, 1024, (uint64_t)1 << 51);
1796 bool alt_hp = fpscr.ahp;
1798 if (exp == 255 && (uint32_t)(mnt << 9)) {
1801 }
else if (fpscr.dn) {
1806 if (!(mnt >> 22 & 1) || alt_hp) {
1809 }
else if (exp == 255) {
1811 result = sgn << 15 | (uint16_t)0x7fff;
1820 mnt >> 7 | !!(uint32_t)(mnt << 25),
1821 rounding, mode | alt_hp << 4, &flags);
1842 bool alt_hp = fpscr.ahp;
1844 if (exp == 2047 && (uint64_t)(mnt << 12)) {
1847 }
else if (fpscr.dn) {
1852 if (!(mnt >> 51 & 1) || alt_hp) {
1855 }
else if (exp == 2047) {
1857 result = sgn << 15 | (uint16_t)0x7fff;
1866 mnt >> 36 | !!(uint64_t)(mnt << 28),
1867 rounding, mode | alt_hp << 4, &flags);
1888 if (exp == 31 && !fpscr.ahp && (uint16_t)(mnt << 6)) {
1894 if (!(mnt >> 9 & 1)) {
1897 }
else if (exp == 31 && !fpscr.ahp) {
1903 result =
fp32_pack(sgn, exp - 15 + 127 + 5, (uint32_t)mnt << 8);
1924 if (exp == 2047 && (uint64_t)(mnt << 12)) {
1930 if (!(mnt >> 51 & 1)) {
1933 }
else if (exp == 2047) {
1939 mnt >> 20 | !!(uint64_t)(mnt << 44),
1940 rounding, mode, &flags);
1961 if (exp == 31 && !fpscr.ahp && (uint16_t)(mnt << 6)) {
1967 if (!(mnt >> 9 & 1)) {
1970 }
else if (exp == 31 && !fpscr.ahp) {
1976 result =
fp64_pack(sgn, exp - 15 + 1023 + 5, (uint64_t)mnt << 37);
1997 if (exp == 255 && (uint32_t)(mnt << 9)) {
2003 if (!(mnt >> 22 & 1)) {
2006 }
else if (exp == 255) {
2012 result =
fp64_pack(sgn, exp - 127 + 1023 + 8, (uint64_t)mnt << 21);
2022 fplibMulAdd(uint32_t addend, uint32_t op1, uint32_t op2, FPSCR &fpscr)
2032 fplibMulAdd(uint64_t addend, uint64_t op1, uint64_t op2, FPSCR &fpscr)
2063 return fp32_pack(sgn, mnt >> 23 ? exp : 0, mnt);
2069 return fp64_pack(sgn, mnt >> 52 ? exp : 0, mnt);
2076 if (!((uint32_t)~(*op1 << 1) >> 23) && (uint32_t)~(*op2 << 1) >> 23)
2078 if (!((uint32_t)~(*op2 << 1) >> 23) && (uint32_t)~(*op1 << 1) >> 23)
2086 if (!((uint64_t)~(*op1 << 1) >> 52) && (uint64_t)~(*op2 << 1) >> 52)
2088 if (!((uint64_t)~(*op2 << 1) >> 52) && (uint64_t)~(*op1 << 1) >> 52)
2098 int sgn1, exp1, sgn2, exp2;
2099 uint32_t mnt1, mnt2,
x, result;
2101 fp32_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2102 fp32_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2107 result = ((sgn1 != sgn2 ? sgn2 : sgn1 ^ (op1 > op2)) ?
2121 int sgn1, exp1, sgn2, exp2;
2122 uint64_t mnt1, mnt2,
x, result;
2124 fp64_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2125 fp64_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2130 result = ((sgn1 != sgn2 ? sgn2 : sgn1 ^ (op1 > op2)) ?
2143 return fplibMax<uint32_t>(op1, op2, fpscr);
2151 return fplibMax<uint64_t>(op1, op2, fpscr);
2160 int sgn1, exp1, sgn2, exp2;
2161 uint32_t mnt1, mnt2,
x, result;
2163 fp32_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2164 fp32_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2169 result = ((sgn1 != sgn2 ? sgn1 : sgn1 ^ (op1 < op2)) ?
2183 int sgn1, exp1, sgn2, exp2;
2184 uint64_t mnt1, mnt2,
x, result;
2186 fp64_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2187 fp64_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2192 result = ((sgn1 != sgn2 ? sgn1 : sgn1 ^ (op1 < op2)) ?
2205 return fplibMin<uint32_t>(op1, op2, fpscr);
2213 return fplibMin<uint64_t>(op1, op2, fpscr);
2242 int sgn1, exp1, sgn2, exp2;
2243 uint32_t mnt1, mnt2, result;
2245 fp32_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2246 fp32_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2250 if ((exp1 == 255 && !mnt2) || (exp2 == 255 && !mnt1)) {
2252 }
else if (exp1 == 255 || exp2 == 255) {
2254 }
else if (!mnt1 || !mnt2) {
2257 result =
fp32_mul(op1, op2, mode, &flags);
2272 int sgn1, exp1, sgn2, exp2;
2273 uint64_t mnt1, mnt2, result;
2275 fp64_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2276 fp64_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2280 if ((exp1 == 2047 && !mnt2) || (exp2 == 2047 && !mnt1)) {
2282 }
else if (exp1 == 2047 || exp2 == 2047) {
2284 }
else if (!mnt1 || !mnt2) {
2287 result =
fp64_mul(op1, op2, mode, &flags);
2300 return op ^ (uint32_t)1 << 31;
2307 return op ^ (uint64_t)1 << 63;
2311 255, 253, 251, 249, 247, 245, 243, 242, 240, 238, 236, 234, 233, 231, 229, 228,
2312 226, 224, 223, 221, 219, 218, 216, 215, 213, 212, 210, 209, 207, 206, 204, 203,
2313 201, 200, 198, 197, 196, 194, 193, 192, 190, 189, 188, 186, 185, 184, 183, 181,
2314 180, 179, 178, 176, 175, 174, 173, 172, 170, 169, 168, 167, 166, 165, 164, 163,
2315 162, 160, 159, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146,
2316 145, 144, 143, 142, 141, 140, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131,
2317 131, 130, 129, 128, 127, 126, 126, 125, 124, 123, 122, 121, 121, 120, 119, 118,
2318 118, 117, 116, 115, 114, 114, 113, 112, 111, 111, 110, 109, 109, 108, 107, 106,
2319 105, 104, 103, 101, 100, 99, 97, 96, 95, 93, 92, 91, 90, 88, 87, 86,
2320 85, 84, 82, 81, 80, 79, 78, 77, 76, 75, 74, 72, 71, 70, 69, 68,
2321 67, 66, 65, 64, 63, 62, 61, 60, 60, 59, 58, 57, 56, 55, 54, 53,
2322 52, 51, 51, 50, 49, 48, 47, 46, 46, 45, 44, 43, 42, 42, 41, 40,
2323 39, 38, 38, 37, 36, 35, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28,
2324 28, 27, 26, 26, 25, 24, 24, 23, 22, 22, 21, 20, 20, 19, 19, 18,
2325 17, 17, 16, 16, 15, 14, 14, 13, 13, 12, 11, 11, 10, 10, 9, 9,
2326 8, 8, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0
2336 uint32_t mnt, result;
2340 if (exp == 255 && (uint32_t)(mnt << 9)) {
2348 }
else if (exp == 255) {
2354 result =
fp32_pack(0, (380 - exp) >> 1, mnt << 15);
2369 uint64_t mnt, result;
2373 if (exp == 2047 && (uint64_t)(mnt << 12)) {
2381 }
else if (exp == 2047) {
2387 result =
fp64_pack(0, (3068 - exp) >> 1, mnt << 44);
2401 int sgn1, exp1, sgn2, exp2;
2402 uint32_t mnt1, mnt2, result;
2404 op1 = fplibNeg<uint32_t>(op1);
2405 fp32_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2406 fp32_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2410 if ((exp1 == 255 && !mnt2) || (exp2 == 255 && !mnt1)) {
2412 }
else if (exp1 == 255 || exp2 == 255) {
2430 int sgn1, exp1, sgn2, exp2;
2431 uint64_t mnt1, mnt2, result;
2433 op1 = fplibNeg<uint64_t>(op1);
2434 fp64_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2435 fp64_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2439 if ((exp1 == 2047 && !mnt2) || (exp2 == 2047 && !mnt1)) {
2441 }
else if (exp1 == 2047 || exp2 == 2047) {
2459 int sgn1, exp1, sgn2, exp2;
2460 uint32_t mnt1, mnt2, result;
2462 op1 = fplibNeg<uint32_t>(op1);
2463 fp32_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2464 fp32_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2468 if ((exp1 == 255 && !mnt2) || (exp2 == 255 && !mnt1)) {
2470 }
else if (exp1 == 255 || exp2 == 255) {
2489 uint32_t mnt, result;
2493 if (exp == 255 && (uint32_t)(mnt << 9)) {
2495 }
else if (exp == 255) {
2500 }
else if (!((uint32_t)(op << 1) >> 22)) {
2501 bool overflow_to_inf =
false;
2504 overflow_to_inf =
true;
2507 overflow_to_inf = !sgn;
2510 overflow_to_inf = sgn;
2513 overflow_to_inf =
false;
2520 }
else if (fpscr.fz && exp >= 253) {
2526 int result_exp = 253 - exp;
2527 uint32_t fraction = (((uint32_t)1 << 19) / (mnt >> 22 | 1) + 1) >> 1;
2529 if (result_exp == 0) {
2531 }
else if (result_exp == -1) {
2535 result =
fp32_pack(sgn, result_exp, fraction);
2550 uint64_t mnt, result;
2554 if (exp == 2047 && (uint64_t)(mnt << 12)) {
2556 }
else if (exp == 2047) {
2561 }
else if (!((uint64_t)(op << 1) >> 51)) {
2562 bool overflow_to_inf =
false;
2565 overflow_to_inf =
true;
2568 overflow_to_inf = !sgn;
2571 overflow_to_inf = sgn;
2574 overflow_to_inf =
false;
2581 }
else if (fpscr.fz && exp >= 2045) {
2587 int result_exp = 2045 - exp;
2588 uint64_t fraction = (((uint32_t)1 << 19) / (mnt >> 54 | 1) + 1) >> 1;
2590 if (result_exp == 0) {
2592 }
else if (result_exp == -1) {
2596 result =
fp64_pack(sgn, result_exp, fraction);
2610 int sgn1, exp1, sgn2, exp2;
2611 uint64_t mnt1, mnt2, result;
2613 op1 = fplibNeg<uint64_t>(op1);
2614 fp64_unpack(&sgn1, &exp1, &mnt1, op1, mode, &flags);
2615 fp64_unpack(&sgn2, &exp2, &mnt2, op2, mode, &flags);
2619 if ((exp1 == 2047 && !mnt2) || (exp2 == 2047 && !mnt1)) {
2621 }
else if (exp1 == 2047 || exp2 == 2047) {
2640 uint32_t mnt, result;
2644 if (exp == 255 && (uint32_t)(mnt << 9)) {
2667 uint64_t mnt, result;
2671 if (exp == 2047 && (uint64_t)(mnt << 12)) {
2694 uint32_t mnt, result;
2700 if (exp == 255 && (uint32_t)(mnt << 9)) {
2702 }
else if (exp == 255) {
2706 }
else if (exp >= 150) {
2711 uint32_t
x = 150 - exp >= 32 ? 0 : mnt >> (150 - exp);
2712 int err = exp < 118 ? 1 :
2713 (mnt << 1 >> (149 - exp) & 3) | (mnt << 2 << (exp - 118) != 0);
2716 x += (err == 3 || (err == 2 && (x & 1)));
2738 result =
fp32_pack(sgn, exp + 8, mnt >> 8);
2757 uint64_t mnt, result;
2763 if (exp == 2047 && (uint64_t)(mnt << 12)) {
2765 }
else if (exp == 2047) {
2769 }
else if (exp >= 1075) {
2774 uint64_t
x = 1075 - exp >= 64 ? 0 : mnt >> (1075 - exp);
2775 int err = exp < 1011 ? 1 :
2776 (mnt << 1 >> (1074 - exp) & 3) | (mnt << 2 << (exp - 1011) != 0);
2779 x += (err == 3 || (err == 2 && (x & 1)));
2801 result =
fp64_pack(sgn, exp + 11, mnt >> 11);
2860 if (exp > 1023 + 63) {
2862 return ((uint64_t)!u << 63) - !sgn;
2865 x =
lsr64(mnt << 11, 1023 + 63 - exp);
2866 err = (exp > 1023 + 63 - 2 ? 0 :
2867 (
lsr64(mnt << 11, 1023 + 63 - 2 - exp) & 3) |
2868 !!(mnt << 11 & (
lsl64(1, 1023 + 63 - 2 - exp) - 1)));
2872 x += (err == 3 || (err == 2 && (x & 1)));
2889 if (u ? sgn && x : x > ((uint64_t)1 << 63) - !sgn) {
2891 return ((uint64_t)!u << 63) - !sgn;
2898 return sgn ? -x :
x;
2905 uint64_t
x =
FPToFixed_64(sgn, exp, mnt, u, rounding, flags);
2906 if (u ? x >= (uint64_t)1 << 32 :
2907 !(x < (uint64_t)1 << 31 ||
2908 (uint64_t)-x <= (uint64_t)1 << 31)) {
2910 x = ((uint32_t)!u << 31) - !sgn;
2921 uint32_t mnt, result;
2927 if (exp == 255 && (uint32_t)(mnt << 9)) {
2932 (uint64_t)mnt << (52 - 23), u, rounding, &flags);
2953 if (exp == 2047 && (uint64_t)(mnt << 12)) {
2957 result =
FPToFixed_32(sgn, exp + fbits, mnt, u, rounding, &flags);
2978 if (exp == 255 && (uint32_t)(mnt << 9)) {
2983 (uint64_t)mnt << (52 - 23), u, rounding, &flags);
2997 uint64_t mnt, result;
3003 if (exp == 2047 && (uint64_t)(mnt << 12)) {
3007 result =
FPToFixed_64(sgn, exp + fbits, mnt, u, rounding, &flags);
3018 int x_sgn = !u && a >> 63;
3019 int x_exp = 190 - fbits;
3020 uint64_t x_mnt = x_sgn ? -a :
a;
3029 x_mnt = x_mnt >> 31 | !!(uint32_t)(x_mnt << 1);
3031 return fp32_round(x_sgn, x_exp, x_mnt, mode, flags);
3037 int x_sgn = !u && a >> 63;
3038 int x_exp = 1024 + 62 - fbits;
3039 uint64_t x_mnt = x_sgn ? -a :
a;
3048 return fp64_round(x_sgn, x_exp, x_mnt << 1, mode, flags);
3057 (
int)rounding | ((uint32_t)fpscr >> 22 & 12),
3069 (
int)rounding | ((uint32_t)fpscr >> 22 & 12),
static uint32_t lsr32(uint32_t x, uint32_t shift)
static uint32_t fp32_add(uint32_t a, uint32_t b, int neg, int mode, int *flags)
static int fp64_compare_gt(uint64_t a, uint64_t b, int mode, int *flags)
uint32_t fplibFPToFixed(uint32_t op, int fbits, bool u, FPRounding rounding, FPSCR &fpscr)
static uint16_t lsl16(uint16_t x, uint32_t shift)
static int cmp128(uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1)
uint32_t fplibMax(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint32_t fp32_normalise(uint32_t mnt, int *exp)
static void set_fpscr0(FPSCR &fpscr, int flags)
uint32_t fplibRecpX(uint32_t op, FPSCR &fpscr)
static uint64_t fp64_normalise(uint64_t mnt, int *exp)
static uint32_t fp32_process_NaNs(uint32_t a, uint32_t b, int mode, int *flags)
static void add128(uint64_t *x0, uint64_t *x1, uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1)
uint32_t fplibRoundInt(uint32_t op, FPRounding rounding, bool exact, FPSCR &fpscr)
static void lsl128(uint64_t *r0, uint64_t *r1, uint64_t x0, uint64_t x1, uint32_t shift)
static void mul62x62(uint64_t *x0, uint64_t *x1, uint64_t a, uint64_t b)
uint32_t fplibSub(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static void fp32_unpack(int *sgn, int *exp, uint32_t *mnt, uint32_t x, int mode, int *flags)
static uint64_t fp64_process_NaN(uint64_t a, int mode, int *flags)
Floating-point library code, which will gradually replace vfp.hh.
static uint64_t fp64_FPThree(int sgn)
static int fp64_compare_ge(uint64_t a, uint64_t b, int mode, int *flags)
static uint32_t fp32_zero(int sgn)
static int fp32_compare_eq(uint32_t a, uint32_t b, int mode, int *flags)
static uint32_t fp32_defaultNaN()
static uint64_t fp64_FPConvertNaN_16(uint16_t op)
static uint16_t fp16_pack(uint16_t sgn, uint16_t exp, uint16_t mnt)
static uint32_t fp32_round(int sgn, int exp, uint32_t mnt, int mode, int *flags)
uint32_t fplibMaxNum(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint32_t fp32_FPConvertNaN_64(uint64_t op)
static uint32_t fp32_FPOnePointFive(int sgn)
static uint16_t fp16_zero(int sgn)
int fplibCompare(uint32_t op1, uint32_t op2, bool signal_nans, FPSCR &fpscr)
static void fp64_minmaxnum(uint64_t *op1, uint64_t *op2, int sgn)
uint16_t fplibConvert(uint32_t op, FPRounding rounding, FPSCR &fpscr)
static uint32_t fp32_process_NaNs3(uint32_t a, uint32_t b, uint32_t c, int mode, int *flags)
static FPRounding FPCRRounding(FPSCR &fpscr)
static const uint8_t recip_sqrt_estimate[256]
uint32_t fplibRecipEstimate(uint32_t op, FPSCR &fpscr)
static uint64_t fp64_defaultNaN()
uint32_t fplibDiv(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint32_t fp32_process_NaN(uint32_t a, int mode, int *flags)
bool fplibCompareGE(uint32_t a, uint32_t b, FPSCR &fpscr)
static uint16_t fp16_max_normal(int sgn)
uint32_t fplibNeg(uint32_t op)
static uint32_t fp32_sqrt(uint32_t a, int mode, int *flags)
uint32_t fplibSqrt(uint32_t op, FPSCR &fpscr)
static uint64_t fp64_add(uint64_t a, uint64_t b, int neg, int mode, int *flags)
static int modeConv(FPSCR fpscr)
static void mul64x32(uint64_t *x0, uint64_t *x1, uint64_t a, uint32_t b)
static uint32_t fp32_FPTwo(int sgn)
static void fp32_minmaxnum(uint32_t *op1, uint32_t *op2, int sgn)
static uint32_t fp32_round_(int sgn, int exp, uint32_t mnt, int rm, int mode, int *flags)
static uint32_t fp32_muladd(uint32_t a, uint32_t b, uint32_t c, int scale, int mode, int *flags)
static uint32_t fp32_repack(int sgn, int exp, uint32_t mnt)
static uint64_t fp64_process_NaNs(uint64_t a, uint64_t b, int mode, int *flags)
static void sub128(uint64_t *x0, uint64_t *x1, uint64_t a0, uint64_t a1, uint64_t b0, uint64_t b1)
static uint64_t fp64_muladd(uint64_t a, uint64_t b, uint64_t c, int scale, int mode, int *flags)
static uint32_t fp32_cvtf(uint64_t a, int fbits, int u, int mode, int *flags)
static uint32_t FPToFixed_32(int sgn, int exp, uint64_t mnt, bool u, FPRounding rounding, int *flags)
uint32_t fplibMulAdd(uint32_t addend, uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint16_t fp16_round_(int sgn, int exp, uint16_t mnt, int rm, int mode, int *flags)
static uint64_t fp64_repack(int sgn, int exp, uint64_t mnt)
static uint16_t fp16_normalise(uint16_t mnt, int *exp)
static uint64_t fp64_pack(uint64_t sgn, uint64_t exp, uint64_t mnt)
static void fp64_unpack(int *sgn, int *exp, uint64_t *mnt, uint64_t x, int mode, int *flags)
uint32_t fplibAbs(uint32_t op)
static void fp128_normalise(uint64_t *mnt0, uint64_t *mnt1, int *exp)
static uint64_t FPToFixed_64(int sgn, int exp, uint64_t mnt, bool u, FPRounding rounding, int *flags)
static uint32_t fp32_FPConvertNaN_16(uint16_t op)
static void set_fpscr(FPSCR &fpscr, int flags)
static uint64_t fp64_FPConvertNaN_32(uint32_t op)
static uint64_t fp64_round_(int sgn, int exp, uint64_t mnt, int rm, int mode, int *flags)
static uint64_t fp64_zero(int sgn)
static uint32_t fp32_pack(uint32_t sgn, uint32_t exp, uint32_t mnt)
uint32_t fplibRecipStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint64_t fp64_cvtf(uint64_t a, int fbits, int u, int mode, int *flags)
static uint64_t fp64_infinity(int sgn)
static uint16_t fp16_infinity(int sgn)
uint32_t fplibAdd(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint32_t fp32_max_normal(int sgn)
uint32_t fplibRSqrtStepFused(uint32_t op1, uint32_t op2, FPSCR &fpscr)
uint32_t fplibRSqrtEstimate(uint32_t op, FPSCR &fpscr)
uint32_t fplibMin(uint32_t op1, uint32_t op2, FPSCR &fpscr)
uint32_t fplibMinNum(uint32_t op1, uint32_t op2, FPSCR &fpscr)
bool fplibCompareGT(uint32_t a, uint32_t b, FPSCR &fpscr)
static uint64_t fp64_FPOnePointFive(int sgn)
static uint32_t fp32_div(uint32_t a, uint32_t b, int mode, int *flags)
static uint64_t fp64_mul(uint64_t a, uint64_t b, int mode, int *flags)
static void lsr128(uint64_t *r0, uint64_t *r1, uint64_t x0, uint64_t x1, uint32_t shift)
uint32_t fplibMulX(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static uint64_t fp64_sqrt(uint64_t a, int mode, int *flags)
static uint64_t fp64_round(int sgn, int exp, uint64_t mnt, int mode, int *flags)
uint32_t fplibMul(uint32_t op1, uint32_t op2, FPSCR &fpscr)
static int fp64_compare_eq(uint64_t a, uint64_t b, int mode, int *flags)
static uint32_t fp32_FPThree(int sgn)
static uint64_t lsr64(uint64_t x, uint32_t shift)
bool fplibCompareEQ(uint32_t a, uint32_t b, FPSCR &fpscr)
static uint64_t fp64_div(uint64_t a, uint64_t b, int mode, int *flags)
static uint16_t fp16_defaultNaN()
static uint64_t lsl64(uint64_t x, uint32_t shift)
static uint64_t fp64_process_NaNs3(uint64_t a, uint64_t b, uint64_t c, int mode, int *flags)
static uint32_t fp32_mul(uint32_t a, uint32_t b, int mode, int *flags)
static uint32_t fp32_infinity(int sgn)
static uint64_t fp64_FPTwo(int sgn)
uint32_t fplibFixedToFP(uint64_t op, int fbits, bool u, FPRounding rounding, FPSCR &fpscr)
Floating-point convert from fixed-point.
static int fp32_compare_ge(uint32_t a, uint32_t b, int mode, int *flags)
static void fp16_unpack(int *sgn, int *exp, uint16_t *mnt, uint16_t x, int mode, int *flags)
static uint16_t fp16_FPConvertNaN_64(uint64_t op)
static int fp32_compare_gt(uint32_t a, uint32_t b, int mode, int *flags)
static uint16_t fp16_FPConvertNaN_32(uint32_t op)
static uint32_t lsl32(uint32_t x, uint32_t shift)
static uint16_t lsr16(uint16_t x, uint32_t shift)
static uint64_t fp64_max_normal(int sgn)