forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/md/bcache/util.h
....@@ -558,17 +558,29 @@
558558 return crc;
559559 }
560560
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
+ */
562575 static inline unsigned int fract_exp_two(unsigned int x,
563576 unsigned int fract_bits)
564577 {
565
- unsigned int fract = x & ~(~0 << fract_bits);
578
+ unsigned int mantissa = 1 << fract_bits; /* Implicit bit */
566579
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;
572584 }
573585
574586 void bch_bio_map(struct bio *bio, void *base);