Changeset 1b20da0 in mainline for uspace/lib/softfloat
- Timestamp:
- 2018-02-28T17:52:03Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3061bc1
- Parents:
- df6ded8
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:26:03)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:52:03)
- Location:
- uspace/lib/softfloat
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/add.c
rdf6ded8 r1b20da0 60 60 } 61 61 62 if (b.parts.exp == FLOAT32_MAX_EXPONENT) { 62 if (b.parts.exp == FLOAT32_MAX_EXPONENT) { 63 63 return b; 64 64 } … … 77 77 } 78 78 79 if (a.parts.exp == FLOAT32_MAX_EXPONENT) { 79 if (a.parts.exp == FLOAT32_MAX_EXPONENT) { 80 80 return a; 81 81 } … … 105 105 } else { 106 106 /* add hidden bit to second operand */ 107 frac2 |= FLOAT32_HIDDEN_BIT_MASK; 107 frac2 |= FLOAT32_HIDDEN_BIT_MASK; 108 108 } 109 109 … … 129 129 frac1 += (0x1 << 5); 130 130 131 if (frac1 & (FLOAT32_HIDDEN_BIT_MASK << 7)) { 131 if (frac1 & (FLOAT32_HIDDEN_BIT_MASK << 7)) { 132 132 /* rounding overflow */ 133 133 ++exp1; … … 145 145 146 146 /* Clear hidden bit and shift */ 147 a.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 147 a.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 148 148 return a; 149 149 } … … 190 190 191 191 /* a is infinity and b not */ 192 if (a.parts.exp == FLOAT64_MAX_EXPONENT) { 192 if (a.parts.exp == FLOAT64_MAX_EXPONENT) { 193 193 return a; 194 194 } … … 203 203 /* both are denormalized */ 204 204 frac1 += frac2; 205 if (frac1 & FLOAT64_HIDDEN_BIT_MASK) { 205 if (frac1 & FLOAT64_HIDDEN_BIT_MASK) { 206 206 /* result is not denormalized */ 207 207 a.parts.exp = 1; … … 217 217 if (exp2 == 0) { 218 218 /* ... is denormalized */ 219 --expdiff; 219 --expdiff; 220 220 } else { 221 221 /* is not denormalized */ … … 242 242 243 243 /* rounding - if first bit after fraction is set then round up */ 244 frac1 += (0x1 << 5); 245 246 if (frac1 & (FLOAT64_HIDDEN_BIT_MASK << 7)) { 244 frac1 += (0x1 << 5); 245 246 if (frac1 & (FLOAT64_HIDDEN_BIT_MASK << 7)) { 247 247 /* rounding overflow */ 248 248 ++exp1; -
uspace/lib/softfloat/common.c
rdf6ded8 r1b20da0 59 59 * Take fraction shifted by 10 bits to the left, round it, normalize it 60 60 * and detect exceptions 61 * 61 * 62 62 * @param cexp Exponent with bias. 63 63 * @param cfrac Fraction shifted 10 bits to the left with added hidden bit. … … 93 93 } 94 94 95 cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 95 cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 96 96 97 97 if (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1)))) { … … 99 99 ((cfrac >> (64 - FLOAT64_FRACTION_SIZE - 2)) & (~FLOAT64_HIDDEN_BIT_MASK)); 100 100 return result; 101 } 101 } 102 102 } else { 103 cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 103 cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 104 104 } 105 105 … … 121 121 result.parts.exp = (uint32_t) cexp; 122 122 123 result.parts.fraction = 123 result.parts.fraction = 124 124 ((cfrac >> (64 - FLOAT64_FRACTION_SIZE - 2)) & (~FLOAT64_HIDDEN_BIT_MASK)); 125 125 126 return result; 126 return result; 127 127 } 128 128 129 129 /** 130 130 * Take fraction, round it, normalize it and detect exceptions 131 * 131 * 132 132 * @param cexp Exponent with bias. 133 133 * @param cfrac_hi High part of the fraction shifted 14 bits to the left … … 139 139 * @return Finished quadruple-precision float. 140 140 */ 141 float128 finish_float128(int32_t cexp, uint64_t cfrac_hi, uint64_t cfrac_lo, 141 float128 finish_float128(int32_t cexp, uint64_t cfrac_hi, uint64_t cfrac_lo, 142 142 char sign, uint64_t shift_out) 143 143 { … … 228 228 result.parts.frac_lo = tmp_lo; 229 229 230 return result; 230 return result; 231 231 } 232 232 … … 242 242 } 243 243 244 /** 244 /** 245 245 * Counts leading zeroes in 32bit unsigned integer. 246 246 * … … 290 290 (*fraction) += (0x1 << (32 - FLOAT32_FRACTION_SIZE - 3)); 291 291 292 if ((*fraction) & 292 if ((*fraction) & 293 293 (FLOAT32_HIDDEN_BIT_MASK << (32 - FLOAT32_FRACTION_SIZE - 1))) { 294 294 /* rounding overflow */ … … 324 324 325 325 /* See if there was a carry to bit 63. */ 326 if ((*fraction) & 326 if ((*fraction) & 327 327 (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1))) { 328 328 /* rounding overflow */ … … 589 589 /** 590 590 * Multiplication of two 64-bit unsigned integers. 591 * 591 * 592 592 * @param a First input operand. 593 593 * @param b Second input operand. … … 622 622 /** 623 623 * Multiplication of two 128-bit unsigned integers. 624 * 624 * 625 625 * @param a_hi High part of the first input operand. 626 626 * @param a_lo Low part of the first input operand. … … 656 656 * Estimate the quotient of 128-bit unsigned divident and 64-bit unsigned 657 657 * divisor. 658 * 658 * 659 659 * @param a_hi High part of the divident. 660 660 * @param a_lo Low part of the divident. -
uspace/lib/softfloat/comparison.c
rdf6ded8 r1b20da0 257 257 * @return 1 if a is lower than b, 0 otherwise. 258 258 */ 259 int is_float32_lt(float32 a, float32 b) 259 int is_float32_lt(float32 a, float32 b) 260 260 { 261 261 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { … … 351 351 * @return 1 if a is greater than b, 0 otherwise. 352 352 */ 353 int is_float32_gt(float32 a, float32 b) 353 int is_float32_gt(float32 a, float32 b) 354 354 { 355 355 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { -
uspace/lib/softfloat/conversion.c
rdf6ded8 r1b20da0 225 225 /* denormalized */ 226 226 227 frac = a.parts.fraction; 227 frac = a.parts.fraction; 228 228 frac |= FLOAT64_HIDDEN_BIT_MASK; /* denormalize and set hidden bit */ 229 229 … … 420 420 frac |= FLOAT32_HIDDEN_BIT_MASK; 421 421 /* shift fraction to left so hidden bit will be the most significant bit */ 422 frac <<= 32 - FLOAT32_FRACTION_SIZE - 1; 422 frac <<= 32 - FLOAT32_FRACTION_SIZE - 1; 423 423 424 424 frac >>= 32 - (a.parts.exp - FLOAT32_BIAS) - 1; … … 606 606 607 607 /* 608 * FIXME: Im not sure what to return if overflow/underflow happens 608 * FIXME: Im not sure what to return if overflow/underflow happens 609 609 * - now its the biggest or the smallest int 610 610 */ … … 625 625 626 626 /* 627 * FIXME: Im not sure what to return if overflow/underflow happens 627 * FIXME: Im not sure what to return if overflow/underflow happens 628 628 * - now its the biggest or the smallest int 629 629 */ -
uspace/lib/softfloat/div.c
rdf6ded8 r1b20da0 151 151 152 152 cfrac = (afrac << 32) / bfrac; 153 if ((cfrac & 0x3F) == 0) { 153 if ((cfrac & 0x3F) == 0) { 154 154 cfrac |= (bfrac * cfrac != afrac << 32); 155 155 } … … 195 195 } 196 196 197 result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 197 result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 198 198 199 199 return result; … … 208 208 * 209 209 */ 210 float64 div_float64(float64 a, float64 b) 210 float64 div_float64(float64 a, float64 b) 211 211 { 212 212 float64 result; 213 213 int64_t aexp, bexp, cexp; 214 uint64_t afrac, bfrac, cfrac; 214 uint64_t afrac, bfrac, cfrac; 215 215 uint64_t remlo, remhi; 216 216 uint64_t tmplo, tmphi; … … 291 291 /* normalize it*/ 292 292 aexp++; 293 /* afrac is nonzero => it must stop */ 293 /* afrac is nonzero => it must stop */ 294 294 while (!(afrac & FLOAT64_HIDDEN_BIT_MASK)) { 295 295 afrac <<= 1; … … 300 300 if (bexp == 0) { 301 301 bexp++; 302 /* bfrac is nonzero => it must stop */ 302 /* bfrac is nonzero => it must stop */ 303 303 while (!(bfrac & FLOAT64_HIDDEN_BIT_MASK)) { 304 304 bfrac <<= 1; … … 315 315 } 316 316 317 cexp = aexp - bexp + FLOAT64_BIAS - 2; 317 cexp = aexp - bexp + FLOAT64_BIAS - 2; 318 318 319 319 cfrac = div128est(afrac, 0x0ll, bfrac); -
uspace/lib/softfloat/mul.c
rdf6ded8 r1b20da0 181 181 } 182 182 183 result.parts.exp = exp; 183 result.parts.exp = exp; 184 184 result.parts.fraction = frac1 & ((1 << FLOAT32_FRACTION_SIZE) - 1); 185 185
Note:
See TracChangeset
for help on using the changeset viewer.