Changeset a35b458 in mainline for uspace/lib/softfloat/mul.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softfloat/mul.c
r3061bc1 ra35b458 51 51 uint64_t frac1, frac2; 52 52 int32_t exp; 53 53 54 54 result.parts.sign = a.parts.sign ^ b.parts.sign; 55 55 56 56 if (is_float32_nan(a) || is_float32_nan(b)) { 57 57 /* TODO: fix SigNaNs */ … … 61 61 return result; 62 62 } 63 63 64 64 if (is_float32_signan(b)) { /* TODO: fix SigNaN */ 65 65 result.parts.fraction = b.parts.fraction; … … 67 67 return result; 68 68 } 69 69 70 70 /* set NaN as result */ 71 71 result.bin = FLOAT32_NAN; 72 72 return result; 73 73 } 74 74 75 75 if (is_float32_infinity(a)) { 76 76 if (is_float32_zero(b)) { … … 79 79 return result; 80 80 } 81 81 82 82 result.parts.fraction = a.parts.fraction; 83 83 result.parts.exp = a.parts.exp; 84 84 return result; 85 85 } 86 86 87 87 if (is_float32_infinity(b)) { 88 88 if (is_float32_zero(a)) { … … 91 91 return result; 92 92 } 93 93 94 94 result.parts.fraction = b.parts.fraction; 95 95 result.parts.exp = b.parts.exp; 96 96 return result; 97 97 } 98 98 99 99 /* exp is signed so we can easy detect underflow */ 100 100 exp = a.parts.exp + b.parts.exp; 101 101 exp -= FLOAT32_BIAS; 102 102 103 103 if (exp >= FLOAT32_MAX_EXPONENT) { 104 104 /* FIXME: overflow */ … … 108 108 return result; 109 109 } 110 110 111 111 if (exp < 0) { 112 112 /* FIXME: underflow */ … … 116 116 return result; 117 117 } 118 118 119 119 frac1 = a.parts.fraction; 120 120 if (a.parts.exp > 0) { … … 123 123 ++exp; 124 124 } 125 125 126 126 frac2 = b.parts.fraction; 127 127 128 128 if (b.parts.exp > 0) { 129 129 frac2 |= FLOAT32_HIDDEN_BIT_MASK; … … 131 131 ++exp; 132 132 } 133 133 134 134 frac1 <<= 1; /* one bit space for rounding */ 135 135 136 136 frac1 = frac1 * frac2; 137 137 138 138 /* round and return */ 139 139 while ((exp < FLOAT32_MAX_EXPONENT) && … … 143 143 frac1 >>= 1; 144 144 } 145 145 146 146 /* rounding */ 147 147 /* ++frac1; FIXME: not works - without it is ok */ 148 148 frac1 >>= 1; /* shift off rounding space */ 149 149 150 150 if ((exp < FLOAT32_MAX_EXPONENT) && 151 151 (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 1)))) { … … 153 153 frac1 >>= 1; 154 154 } 155 155 156 156 if (exp >= FLOAT32_MAX_EXPONENT) { 157 157 /* TODO: fix overflow */ … … 161 161 return result; 162 162 } 163 163 164 164 exp -= FLOAT32_FRACTION_SIZE; 165 165 166 166 if (exp <= FLOAT32_FRACTION_SIZE) { 167 167 /* denormalized number */ 168 168 frac1 >>= 1; /* denormalize */ 169 169 170 170 while ((frac1 > 0) && (exp < 0)) { 171 171 frac1 >>= 1; 172 172 ++exp; 173 173 } 174 174 175 175 if (frac1 == 0) { 176 176 /* FIXME : underflow */ … … 180 180 } 181 181 } 182 182 183 183 result.parts.exp = exp; 184 184 result.parts.fraction = frac1 & ((1 << FLOAT32_FRACTION_SIZE) - 1); 185 185 186 186 return result; 187 187 } … … 200 200 uint64_t frac1, frac2; 201 201 int32_t exp; 202 202 203 203 result.parts.sign = a.parts.sign ^ b.parts.sign; 204 204 205 205 if (is_float64_nan(a) || is_float64_nan(b)) { 206 206 /* TODO: fix SigNaNs */ … … 219 219 return result; 220 220 } 221 221 222 222 if (is_float64_infinity(a)) { 223 223 if (is_float64_zero(b)) { … … 230 230 return result; 231 231 } 232 232 233 233 if (is_float64_infinity(b)) { 234 234 if (is_float64_zero(a)) { … … 241 241 return result; 242 242 } 243 243 244 244 /* exp is signed so we can easy detect underflow */ 245 245 exp = a.parts.exp + b.parts.exp - FLOAT64_BIAS; 246 246 247 247 frac1 = a.parts.fraction; 248 248 249 249 if (a.parts.exp > 0) { 250 250 frac1 |= FLOAT64_HIDDEN_BIT_MASK; … … 252 252 ++exp; 253 253 } 254 254 255 255 frac2 = b.parts.fraction; 256 256 257 257 if (b.parts.exp > 0) { 258 258 frac2 |= FLOAT64_HIDDEN_BIT_MASK; … … 260 260 ++exp; 261 261 } 262 262 263 263 frac1 <<= (64 - FLOAT64_FRACTION_SIZE - 1); 264 264 frac2 <<= (64 - FLOAT64_FRACTION_SIZE - 2); 265 265 266 266 mul64(frac1, frac2, &frac1, &frac2); 267 267 268 268 frac1 |= (frac2 != 0); 269 269 if (frac1 & (0x1ll << 62)) { … … 271 271 exp--; 272 272 } 273 273 274 274 result = finish_float64(exp, frac1, result.parts.sign); 275 275 return result; … … 289 289 uint64_t frac1_hi, frac1_lo, frac2_hi, frac2_lo, tmp_hi, tmp_lo; 290 290 int32_t exp; 291 291 292 292 result.parts.sign = a.parts.sign ^ b.parts.sign; 293 293 294 294 if (is_float128_nan(a) || is_float128_nan(b)) { 295 295 /* TODO: fix SigNaNs */ … … 311 311 return result; 312 312 } 313 313 314 314 if (is_float128_infinity(a)) { 315 315 if (is_float128_zero(b)) { … … 324 324 return result; 325 325 } 326 326 327 327 if (is_float128_infinity(b)) { 328 328 if (is_float128_zero(a)) { … … 337 337 return result; 338 338 } 339 339 340 340 /* exp is signed so we can easy detect underflow */ 341 341 exp = a.parts.exp + b.parts.exp - FLOAT128_BIAS - 1; 342 342 343 343 frac1_hi = a.parts.frac_hi; 344 344 frac1_lo = a.parts.frac_lo; 345 345 346 346 if (a.parts.exp > 0) { 347 347 or128(frac1_hi, frac1_lo, … … 351 351 ++exp; 352 352 } 353 353 354 354 frac2_hi = b.parts.frac_hi; 355 355 frac2_lo = b.parts.frac_lo; 356 356 357 357 if (b.parts.exp > 0) { 358 358 or128(frac2_hi, frac2_lo, … … 362 362 ++exp; 363 363 } 364 364 365 365 lshift128(frac2_hi, frac2_lo, 366 366 128 - FLOAT128_FRACTION_SIZE, &frac2_hi, &frac2_lo); 367 367 368 368 tmp_hi = frac1_hi; 369 369 tmp_lo = frac1_lo; … … 372 372 add128(frac1_hi, frac1_lo, tmp_hi, tmp_lo, &frac1_hi, &frac1_lo); 373 373 frac2_hi |= (frac2_lo != 0x0ll); 374 374 375 375 if ((FLOAT128_HIDDEN_BIT_MASK_HI << 1) <= frac1_hi) { 376 376 frac2_hi >>= 1; … … 381 381 ++exp; 382 382 } 383 383 384 384 result = finish_float128(exp, frac1_hi, frac1_lo, result.parts.sign, frac2_hi); 385 385 return result; … … 392 392 float32_u ua; 393 393 ua.val = a; 394 394 395 395 float32_u ub; 396 396 ub.val = b; 397 397 398 398 float32_u res; 399 399 res.data = mul_float32(ua.data, ub.data); 400 400 401 401 return res.val; 402 402 } … … 406 406 float32_u ua; 407 407 ua.val = a; 408 408 409 409 float32_u ub; 410 410 ub.val = b; 411 411 412 412 float32_u res; 413 413 res.data = mul_float32(ua.data, ub.data); 414 414 415 415 return res.val; 416 416 } … … 424 424 float64_u ua; 425 425 ua.val = a; 426 426 427 427 float64_u ub; 428 428 ub.val = b; 429 429 430 430 float64_u res; 431 431 res.data = mul_float64(ua.data, ub.data); 432 432 433 433 return res.val; 434 434 } … … 438 438 float64_u ua; 439 439 ua.val = a; 440 440 441 441 float64_u ub; 442 442 ub.val = b; 443 443 444 444 float64_u res; 445 445 res.data = mul_float64(ua.data, ub.data); 446 446 447 447 return res.val; 448 448 } … … 456 456 float128_u ua; 457 457 ua.val = a; 458 458 459 459 float128_u ub; 460 460 ub.val = b; 461 461 462 462 float128_u res; 463 463 res.data = mul_float128(ua.data, ub.data); 464 464 465 465 return res.val; 466 466 }
Note:
See TracChangeset
for help on using the changeset viewer.