.. | .. |
---|
558 | 558 | return crc; |
---|
559 | 559 | } |
---|
560 | 560 | |
---|
561 | | -/* Does linear interpolation between powers of two */ |
---|
| 561 | +/* |
---|
| 562 | + * A stepwise-linear pseudo-exponential. This returns 1 << (x >> |
---|
| 563 | + * frac_bits), with the less-significant bits filled in by linear |
---|
| 564 | + * interpolation. |
---|
| 565 | + * |
---|
| 566 | + * This can also be interpreted as a floating-point number format, |
---|
| 567 | + * where the low frac_bits are the mantissa (with implicit leading |
---|
| 568 | + * 1 bit), and the more significant bits are the exponent. |
---|
| 569 | + * The return value is 1.mantissa * 2^exponent. |
---|
| 570 | + * |
---|
| 571 | + * The way this is used, fract_bits is 6 and the largest possible |
---|
| 572 | + * input is CONGESTED_MAX-1 = 1023 (exponent 16, mantissa 0x1.fc), |
---|
| 573 | + * so the maximum output is 0x1fc00. |
---|
| 574 | + */ |
---|
562 | 575 | static inline unsigned int fract_exp_two(unsigned int x, |
---|
563 | 576 | unsigned int fract_bits) |
---|
564 | 577 | { |
---|
565 | | - unsigned int fract = x & ~(~0 << fract_bits); |
---|
| 578 | + unsigned int mantissa = 1 << fract_bits; /* Implicit bit */ |
---|
566 | 579 | |
---|
567 | | - x >>= fract_bits; |
---|
568 | | - x = 1 << x; |
---|
569 | | - x += (x * fract) >> fract_bits; |
---|
570 | | - |
---|
571 | | - return x; |
---|
| 580 | + mantissa += x & (mantissa - 1); |
---|
| 581 | + x >>= fract_bits; /* The exponent */ |
---|
| 582 | + /* Largest intermediate value 0x7f0000 */ |
---|
| 583 | + return mantissa << x >> fract_bits; |
---|
572 | 584 | } |
---|
573 | 585 | |
---|
574 | 586 | void bch_bio_map(struct bio *bio, void *base); |
---|