[Mesa-dev] [PATCH v2 16/24] i965: Use LZD to implement nir_op_ifind_msb on Gen < 7

Matt Turner mattst88 at gmail.com
Mon Jul 11 22:15:59 UTC 2016


On Thu, Jul 7, 2016 at 10:16 AM, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
>
> v2: Retype LZD source as UD to avoid potential problems with 0x80000000.
> Suggested by Matt.  Also update comment about problem values with
> LZD(abs(x)).  Suggested by Curro.
>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/mesa/drivers/dri/i965/brw_fs_nir.cpp   | 54 ++++++++++++++++++++++------
>  src/mesa/drivers/dri/i965/brw_vec4_nir.cpp | 57 ++++++++++++++++++++++++------
>  2 files changed, 90 insertions(+), 21 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> index 65f6406..93d5e9d 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> @@ -623,8 +623,36 @@ emit_find_msb_using_lzd(const fs_builder &bld,
>                          bool is_signed)
>  {
>     fs_inst *inst;
> +   fs_reg temp = src;
>
> -   bld.LZD(retype(result, BRW_REGISTER_TYPE_UD), src);
> +   if (is_signed) {
> +      /* LZD of an absolute value source almost always does the right
> +       * thing.  There are two problem values:
> +       *
> +       * * 0x80000000.  Since abs(0x80000000) == 0x80000000, LZD returns
> +       *   0.  However, findMSB(int(0x80000000)) == 30.
> +       *
> +       * * 0xffffffff.  Since abs(0xffffffff) == 1, LZD returns
> +       *   31.  Section 8.8 (Integer Functions) of the GLSL 4.50 spec says:
> +       *
> +       *    For a value of zero or negative one, -1 will be returned.
> +       *
> +       * * Negative powers of two.  LZD(abs(-(1<<x))) returns x, but
> +       *   findMSB(-(1<<x)) should return x-1.
> +       *

Might be nice to add these cases to the piglit tests.

15-17 are

Reviewed-by: Matt Turner <mattst88 at gmail.com>

That should be the whole series, minus the RFC at the end.


More information about the mesa-dev mailing list