[Mesa-dev] [PATCH 07/13] nir/lower_double_ops: lower ceil()

Jason Ekstrand jason at jlekstrand.net
Tue Apr 19 22:48:36 UTC 2016


Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

On Tue, Apr 12, 2016 at 1:05 AM, Samuel Iglesias Gonsálvez <
siglesias at igalia.com> wrote:

> From: Iago Toral Quiroga <itoral at igalia.com>
>
> At least i965 hardware does not have native support for ceil on doubles.
> ---
>  src/compiler/nir/nir.h                  |  1 +
>  src/compiler/nir/nir_lower_double_ops.c | 27 +++++++++++++++++++++++++++
>  2 files changed, 28 insertions(+)
>
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index b7231a7..7c9e498 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -2288,6 +2288,7 @@ typedef enum {
>     nir_lower_drsq = (1 << 2),
>     nir_lower_dtrunc = (1 << 3),
>     nir_lower_dfloor = (1 << 4),
> +   nir_lower_dceil = (1 << 5),
>  } nir_lower_doubles_options;
>
>  void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options
> options);
> diff --git a/src/compiler/nir/nir_lower_double_ops.c
> b/src/compiler/nir/nir_lower_double_ops.c
> index e1ec6da..66e2be4 100644
> --- a/src/compiler/nir/nir_lower_double_ops.c
> +++ b/src/compiler/nir/nir_lower_double_ops.c
> @@ -398,6 +398,25 @@ lower_floor(nir_builder *b, nir_ssa_def *src)
>                                src));
>  }
>
> +static nir_ssa_def *
> +lower_ceil(nir_builder *b, nir_ssa_def *src)
> +{
> +   /* if x < 0,                    ceil(x) = trunc(x)
> +    * else if (x - trunc(x) == 0), ceil(x) = x
> +    * else,                        ceil(x) = trunc(x) + 1
> +    */
> +   nir_ssa_def *tr = nir_ftrunc(b, src);
> +   return nir_bcsel(b,
> +                    nir_flt(b, src, nir_imm_double(b, 0.0)),
> +                    tr,
> +                    nir_bcsel(b,
> +                              nir_fne(b,
> +                                      nir_fsub(b, src, tr),
> +                                      nir_imm_double(b, 0.0)),
> +                              nir_fadd(b, tr, nir_imm_double(b, 1.0)),
> +                              src));
> +}
> +
>  static void
>  lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options
> options)
>  {
> @@ -431,6 +450,11 @@ lower_doubles_instr(nir_alu_instr *instr,
> nir_lower_doubles_options options)
>           return;
>        break;
>
> +   case nir_op_fceil:
> +      if (!(options & nir_lower_dceil))
> +         return;
> +      break;
> +
>     default:
>        return;
>     }
> @@ -460,6 +484,9 @@ lower_doubles_instr(nir_alu_instr *instr,
> nir_lower_doubles_options options)
>     case nir_op_ffloor:
>        result = lower_floor(&bld, src);
>        break;
> +   case nir_op_fceil:
> +      result = lower_ceil(&bld, src);
> +      break;
>     default:
>        unreachable("unhandled opcode");
>     }
> --
> 2.5.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160419/13e5e6e3/attachment.html>


More information about the mesa-dev mailing list