OSDN Git Service

util: Generalize fast integer division to be variable bit-width
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 6 Oct 2018 01:29:31 +0000 (20:29 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 10 Oct 2018 18:13:12 +0000 (13:13 -0500)
commit7cde4dbcd750dabc74185da058844d43928fa206
tree83898ac62fd7cf4f7ddbd1a15b131011676f525d
parent64eb0738d4e35e9ceb4bf99b028bdd5e12c59c34
util: Generalize fast integer division to be variable bit-width

There's nothing inherently fixed-width in the code.  All that's required
to generalize it is to make everything internally 64-bit and pass
UINT_BITS in as a parameter to util_compute_fast_[us]div_info.  With
that, it can now handle 8, 16, 32, and 64-bit integer division by a
constant.

We also add support for division by 1 and by other powers of 2.  This is
useful if you want to divide by a uniform value in a shader where you
have the opportunity to adjust the uniform on the CPU before passing it
in.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/util/fast_idiv_by_const.c
src/util/fast_idiv_by_const.h