[igt-dev] [PATCH i-g-t 5/8] lib: Add igt_matrix
Ville Syrjälä
ville.syrjala at linux.intel.com
Wed Feb 28 15:01:45 UTC 2018
On Wed, Feb 28, 2018 at 04:57:09PM +0200, Ville Syrjälä wrote:
> 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.
I guess in this case we could just return a pointer instead of
a copy. But that wouldn't be consistent with the rest of the api
so not sure if it's worth it.
--
Ville Syrjälä
Intel OTC
More information about the igt-dev
mailing list