It's reasonably well-known that you can replace an unsigned integer division by a constant with a sequence of multiply (by constant), adds, and shifts. This little series implements such an optimization for NIR. As can be seen from the last patch, there really aren't that many shaders affected by this and most of them are because we are finally optimizing signed integer division by powers of two. However, it seems like a good thing to have in our pockets none-the-less, especially for 64-bit where divisions turn into manually implementing the division algorithm.
Jason Ekstrand (6): util: Add a simple big math library util: Add a uint inverse helper nir: Allow [iu]mul_high on non-32-bit types nir/lower_int64: Add support for [iu]mul_high nir: Add a pass for lowering integer division by constants i965: Enable nir_opt_idiv_const for all bit sizes configure.ac | 1 + src/compiler/Makefile.sources | 1 + src/compiler/nir/meson.build | 1 + src/compiler/nir/nir.h | 3 + src/compiler/nir/nir_constant_expressions.py | 1 + src/compiler/nir/nir_lower_int64.c | 54 +++++ src/compiler/nir/nir_opcodes.py | 43 +++- src/compiler/nir/nir_opt_idiv_const.c | 192 ++++++++++++++++ src/intel/compiler/brw_nir.c | 4 +- src/util/Makefile.am | 3 +- src/util/Makefile.sources | 1 + src/util/bigmath.h | 95 ++++++++ src/util/meson.build | 2 + src/util/tests/uint_inverse/Makefile.am | 43 ++++ src/util/tests/uint_inverse/meson.build | 30 +++ .../tests/uint_inverse/uint_inverse_test.cpp | 83 +++++++ src/util/uint_inverse.h | 206 ++++++++++++++++++ 17 files changed, 757 insertions(+), 6 deletions(-) create mode 100644 src/compiler/nir/nir_opt_idiv_const.c create mode 100644 src/util/bigmath.h create mode 100644 src/util/tests/uint_inverse/Makefile.am create mode 100644 src/util/tests/uint_inverse/meson.build create mode 100644 src/util/tests/uint_inverse/uint_inverse_test.cpp create mode 100644 src/util/uint_inverse.h -- 2.17.1 _______________________________________________ mesa-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-dev
