nvhw/pgraph_celsius: Nailed down core rcp algorithm.
This is just the core, computing the mantissa for values other than exact PoT.
Functions for complete rcp/rcc ops are to be done later.
@@ -435,3 +435,21 @@ uint32_t pgraph_celsius_xfrm_add4(uint32_t *v) {
return r;
}
+uint32_t pgraph_celsius_xfrm_rcp_core(uint32_t x) {
+ static const uint8_t lut[0x40] = {
+ 0x3f, 0x3d, 0x3b, 0x39, 0x37, 0x35, 0x34, 0x32, 0x30, 0x2f, 0x2d, 0x2c, 0x2b, 0x29, 0x28, 0x27,
+ 0x25, 0x24, 0x23, 0x22, 0x20, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16, 0x15,
+ 0x14, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0f, 0x0e, 0x0d, 0x0c, 0x0c, 0x0b, 0x0a, 0x0a, 0x09,
+ 0x08, 0x08, 0x07, 0x06, 0x06, 0x05, 0x05, 0x04, 0x03, 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00,
+ };
+ if (x >= 0x800000)
+ abort();
+ x += 0x800000;
+ uint32_t s0 = lut[x >> 17 & 0x3f] | 0x40;
+ uint32_t s1 = ((1u << 31) - s0 * x) * s0 >> 24;
+ uint32_t s2 = ((1ull << 37) - (uint64_t)s1 * x) * s1 >> 25;
+ s2 -= 0x800000;
+ if (s2 >= 0x800000)
+ abort();
+ return s2;
+}
