[Mesa-dev] [PATCH 1/2] tgsi/exec: fix the udiv and umod instructions

Brian Paul brianp at vmware.com
Wed Apr 10 17:09:07 PDT 2013


On 04/10/2013 04:33 PM, Zack Rusin wrote:
> Same as with llvmpipe: we can't be divind/moding by zero and we
> need to make sure that dividing/moding by zero produces 0xffffffff.
>
> Signed-off-by: Zack Rusin<zackr at vmware.com>
> ---
>   src/gallium/auxiliary/tgsi/tgsi_exec.c |   16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_exec.c b/src/gallium/auxiliary/tgsi/tgsi_exec.c
> index 8579d8a..b8de5fb 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_exec.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_exec.c
> @@ -3445,10 +3445,10 @@ micro_udiv(union tgsi_exec_channel *dst,
>              const union tgsi_exec_channel *src0,
>              const union tgsi_exec_channel *src1)
>   {
> -   dst->u[0] = src0->u[0] / src1->u[0];
> -   dst->u[1] = src0->u[1] / src1->u[1];
> -   dst->u[2] = src0->u[2] / src1->u[2];
> -   dst->u[3] = src0->u[3] / src1->u[3];
> +   dst->u[0] = src1->u[0] ? src0->u[0] / src1->u[0] : -1;
> +   dst->u[1] = src1->u[1] ? src0->u[1] / src1->u[1] : -1;
> +   dst->u[2] = src1->u[2] ? src0->u[2] / src1->u[2] : -1;
> +   dst->u[3] = src1->u[3] ? src0->u[3] / src1->u[3] : -1;

I think we might avoid a MSVC warning if we use ~0u instead of -1.


>   }
>
>   static void
> @@ -3490,10 +3490,10 @@ micro_umod(union tgsi_exec_channel *dst,
>              const union tgsi_exec_channel *src0,
>              const union tgsi_exec_channel *src1)
>   {
> -   dst->u[0] = src0->u[0] % src1->u[0];
> -   dst->u[1] = src0->u[1] % src1->u[1];
> -   dst->u[2] = src0->u[2] % src1->u[2];
> -   dst->u[3] = src0->u[3] % src1->u[3];
> +   dst->u[0] = src1->u[0] ? src0->u[0] % src1->u[0] : -1;
> +   dst->u[1] = src1->u[1] ? src0->u[1] % src1->u[1] : -1;
> +   dst->u[2] = src1->u[2] ? src0->u[2] % src1->u[2] : -1;
> +   dst->u[3] = src1->u[3] ? src0->u[3] % src1->u[3] : -1;
>   }
>
>   static void

Otherwise, for both:  Reviewed-by: Brian Paul <brianp at vmware.com>



More information about the mesa-dev mailing list