radv: enable radv_no_dynamic_bounds for Path of Exile
[mesa.git] / src / util / fast_idiv_by_const.h
index 231311f84be2d3d361364389c10075d123c7b3a5..638b52a3ffbb8428adc7066429ae87a363bf8dbd 100644 (file)
@@ -98,8 +98,8 @@ util_compute_fast_sdiv_info(int64_t D, unsigned SINT_BITS);
  *   emit("result >>>= UINT_BITS")
  *   if m.post_shift > 0: emit("result >>>= m.post_shift")
  *
- * The shifts by UINT_BITS may be "free" if the high half of the full multiply
- * is put in a separate register.
+ * This second version works even if D is 1.  The shifts by UINT_BITS may be
+ * "free" if the high half of the full multiply is put in a separate register.
  *
  * saturated_increment(n) means "increment n unless it would wrap to 0," i.e.
  *   if n == (1 << UINT_BITS)-1: result = n
@@ -135,7 +135,13 @@ static inline uint32_t
 util_fast_udiv32(uint32_t n, struct util_fast_udiv_info info)
 {
    n = n >> info.pre_shift;
-   /* For non-power-of-two divisors, use a 32-bit ADD that clamps to UINT_MAX. */
+   /* If the divisor is not 1, you can instead use a 32-bit ADD that clamps
+    * to UINT_MAX. Dividing by 1 needs the full 64-bit ADD.
+    *
+    * If you have unsigned 64-bit MAD with 32-bit inputs, you can do:
+    *    increment = increment ? multiplier : 0; // on the CPU
+    *    (n * multiplier + increment) // on the GPU using unsigned 64-bit MAD
+    */
    n = (((uint64_t)n + info.increment) * info.multiplier) >> 32;
    n = n >> info.post_shift;
    return n;