[igt-dev] [PATCH i-g-t 5/8] lib: Add igt_matrix

Ville Syrjälä ville.syrjala at linux.intel.com
Wed Feb 28 14:57:09 UTC 2018


On Tue, Feb 27, 2018 at 09:33:13PM +0000, Chris Wilson wrote:
> Quoting Ville Syrjala (2018-02-27 21:21:17)
> > +#include "igt_core.h"
> > +#include "igt_matrix.h"
> > +
> > +/**
> > + * SECTION:igt_matrix
> > + * @short_description: Matrix math library
> > + * @title: Matrix
> > + * @include: igt.h
> > + *
> > + * This library contains helper functions for basic matrix math.
> > + * The library operates on #igt_mat4 and #igt_vec4 structures.
> > + */
> > +
> > +/**
> > + * igt_matrix_print:
> > + * @m: the matrix
> > + *
> > + * Print out the matrix elements.
> > + */
> > +void igt_matrix_print(const struct igt_mat4 *m)
> > +{
> > +       for (int row = 0; row < 4; row++) {
> > +               igt_info("|");
> > +               for (int col = 0; col < 4; col++) {
> > +                       igt_info("%4.4f,", m->d[col * 4 + row]);
> 
> #define m(row, col) ((col) * 4 + (row)) ?

Seems like a sensible idea.

> 
> > +               }
> > +               igt_info("|\n");
> > +       }
> > +}
> > +
> > +/**
> > + * igt_matrix_identity:
> > + *
> > + * Returns:
> > + * An identity matrix.
> > + */
> > +struct igt_mat4 igt_matrix_identity(void)
> > +{
> > +       struct igt_mat4 ret = {
> > +               .d[0 * 4 + 0] = 1.0f,
> > +               .d[1 * 4 + 1] = 1.0f,
> > +               .d[2 * 4 + 2] = 1.0f,
> > +               .d[3 * 4 + 3] = 1.0f,
> > +       };
> 
> static ?

Also const I suppose.

I've not actually checked what kind of a job the compiler does when you
return big blobs like this from functions. Should probably look into
that to make sure the resulting code is not totally insane.

> 
> Didn't spot any typos.
> -Chris

-- 
Ville Syrjälä
Intel OTC


More information about the igt-dev mailing list