[Mesa-dev] [PATCH] i965/fs: Replace nested ternary with if ladder.

Kenneth Graunke kenneth at whitecape.org
Thu Nov 12 17:54:59 PST 2015


On Thursday, November 12, 2015 05:46:58 PM Matt Turner wrote:
> Since the types of the expression were
> 
>    bool ? src_reg : (bool ? brw_reg : brw_reg)
> 
> the result of the second (nested) ternary would be implicitly
> converted to a src_reg by the src_reg(struct brw_reg) constructor. I.e.,
> 
>    bool ? src_reg : src_reg(bool ? brw_reg : brw_reg)
> 
> In the next patch, I make backend_reg (the parent of src_reg) inherit
> from brw_reg, which changes this expression to return brw_reg, which
> throws away any fields that exist in the classes derived from brw_reg.
> I.e.,
> 
>    src_reg(bool ? brw_reg(src_reg) : bool ? brw_reg : brw_reg)
> 
> Generally this code was gross, and wasn't actually shorter or easier to
> read than an if ladder.
> ---
>  src/mesa/drivers/dri/i965/brw_fs_builder.h | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_builder.h b/src/mesa/drivers/dri/i965/brw_fs_builder.h
> index f121f34..d5763f6 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_builder.h
> +++ b/src/mesa/drivers/dri/i965/brw_fs_builder.h
> @@ -224,12 +224,13 @@ namespace brw {
>        src_reg
>        sample_mask_reg() const
>        {
> -         const bool uses_kill =
> -            (shader->stage == MESA_SHADER_FRAGMENT &&
> -             ((brw_wm_prog_data *)shader->stage_prog_data)->uses_kill);
> -         return (shader->stage != MESA_SHADER_FRAGMENT ? src_reg(0xffff) :
> -                 uses_kill ? brw_flag_reg(0, 1) :
> -                 retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UD));
> +         if (shader->stage != MESA_SHADER_FRAGMENT) {
> +            return src_reg(0xffff);
> +         } else if (((brw_wm_prog_data *)shader->stage_prog_data)->uses_kill) {
> +            return brw_flag_reg(0, 1);
> +         } else {
> +            return retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UD);
> +         }
>        }
>  
>        /**
> 

Looks good to me.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20151112/6da2e3b8/attachment.sig>


More information about the mesa-dev mailing list