Patch: Optimizing Matrix routines by hand

Kristian Høgsberg krh at bitplanet.net
Thu Feb 3 07:18:02 PST 2011


On Mon, Jan 31, 2011 at 1:15 PM, Carl-Philip Haensch
<Carl-Philip.Haensch at mailbox.tu-dresden.de> wrote:
> Hi,
>
> I wrote a patch that optimizes matrix scale and translate because i doubt
> gcc will find the shortest path through an invocation, three loops and a
> memory writeback per strcpy by itself.

These matrix routines aren't a performance bottleneck right now, so
I'd like to keep them as simple as possible to not challenge my linear
algebra skills unnecessarily.

Kristian

> diff --git a/compositor/compositor.c b/compositor/compositor.c
> index 9d7c330..e571b12 100644
> --- a/compositor/compositor.c
> +++ b/compositor/compositor.c
> @@ -87,21 +87,20 @@ wlsc_matrix_multiply(struct wlsc_matrix *m, const struct
> wlsc_matrix *n)
>  static void
>  wlsc_matrix_translate(struct wlsc_matrix *matrix, GLfloat x, GLfloat y,
> GLfloat z)
>  {
> -       struct wlsc_matrix translate = {
> -               { 1, 0, 0, 0,  0, 1, 0, 0,  0, 0, 1, 0,  x, y, z, 1 }
> -       };
> -
> -       wlsc_matrix_multiply(matrix, &translate);
> +       matrix->d[12] += x;
> +       matrix->d[13] += y;
> +       matrix->d[14] += z;
>  }
>
>  static void
>  wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat
> z)
>  {
> -       struct wlsc_matrix scale = {
> -               { x, 0, 0, 0,  0, y, 0, 0,  0, 0, z, 0,  0, 0, 0, 1 }
> -       };
> -
> -       wlsc_matrix_multiply(matrix, &scale);
> +       int i;
> +       for(i = 0; i < 4; i++) {
> +               matrix->d[0 + 4 * i] *= x;
> +               matrix->d[1 + 4 * i] *= y;
> +               matrix->d[2 + 4 * i] *= z;
> +       }
>  }
>
>  static void
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>


More information about the wayland-devel mailing list