Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t 1/4] lib/igt_matrix: Unroll and inline igt_matrix_transform()
@ 2018-06-06 20:16 Ville Syrjala
  2018-06-06 20:16 ` [igt-dev] [PATCH i-g-t 2/4] lib/igt_color_encoding: Use the m(row, col) macro to address the matrix cells Ville Syrjala
                   ` (7 more replies)
  0 siblings, 8 replies; 15+ messages in thread
From: Ville Syrjala @ 2018-06-06 20:16 UTC (permalink / raw)
  To: igt-dev

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Using the current igt_matrix for NV12 conversion ends up being
about 4x as slow as the current non-igt_matrix based code. Unrolling
and inlining igt_matrix_transform() improves that factor to ~1.5x.

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_matrix.c | 25 -------------------------
 lib/igt_matrix.h | 43 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/lib/igt_matrix.c b/lib/igt_matrix.c
index 3fa6c96cae8a..35a9c321defd 100644
--- a/lib/igt_matrix.c
+++ b/lib/igt_matrix.c
@@ -24,8 +24,6 @@
 #include "igt_core.h"
 #include "igt_matrix.h"
 
-#define m(row, col) ((col) * 4 + (row))
-
 /**
  * SECTION:igt_matrix
  * @short_description: Matrix math library
@@ -110,29 +108,6 @@ struct igt_mat4 igt_matrix_translate(float x, float y, float z)
 	return ret;
 }
 
-/**
- * igt_matrix_transform:
- *
- * Transform the vector @v by the matrix @m. @m is on the left,
- * @v on the right.
- *
- * Returns:
- * The transformed vector.
- */
-struct igt_vec4 igt_matrix_transform(const struct igt_mat4 *m,
-				     const struct igt_vec4 *v)
-{
-	struct igt_vec4 ret = {};
-
-	for (int row = 0; row < 4; row++) {
-		for (int i = 0; i < 4; i++) {
-			ret.d[row] += m->d[m(row, i)] * v->d[i];
-		}
-	}
-
-	return ret;
-}
-
 /**
  * igt_matrix_multiply:
  *
diff --git a/lib/igt_matrix.h b/lib/igt_matrix.h
index 33acb815197b..7a2b9ad8b573 100644
--- a/lib/igt_matrix.h
+++ b/lib/igt_matrix.h
@@ -44,13 +44,52 @@ struct igt_mat4 {
 	float d[16];
 };
 
+#define m(row, col) ((col) * 4 + (row))
+
 void igt_matrix_print(const struct igt_mat4 *m);
 struct igt_mat4 igt_matrix_identity(void);
 struct igt_mat4 igt_matrix_scale(float x, float y, float z);
 struct igt_mat4 igt_matrix_translate(float x, float y, float z);
-struct igt_vec4 igt_matrix_transform(const struct igt_mat4 *m,
-				     const struct igt_vec4 *v);
 struct igt_mat4 igt_matrix_multiply(const struct igt_mat4 *a,
 				    const struct igt_mat4 *b);
 
+/**
+ * igt_matrix_transform:
+ *
+ * Transform the vector @v by the matrix @m. @m is on the left,
+ * @v on the right.
+ *
+ * Returns:
+ * The transformed vector.
+ */
+static inline struct igt_vec4
+igt_matrix_transform(const struct igt_mat4 *m,
+		     const struct igt_vec4 *v)
+{
+	struct igt_vec4 ret = {
+		.d = { m->d[m(0, 0)] * v->d[0] +
+		       m->d[m(0, 1)] * v->d[1] +
+		       m->d[m(0, 2)] * v->d[2] +
+		       m->d[m(0, 3)] * v->d[3],
+
+		       m->d[m(1, 0)] * v->d[0] +
+		       m->d[m(1, 1)] * v->d[1] +
+		       m->d[m(1, 2)] * v->d[2] +
+		       m->d[m(1, 3)] * v->d[3],
+
+		       m->d[m(2, 0)] * v->d[0] +
+		       m->d[m(2, 1)] * v->d[1] +
+		       m->d[m(2, 2)] * v->d[2] +
+		       m->d[m(2, 3)] * v->d[3],
+
+		       m->d[m(3, 0)] * v->d[0] +
+		       m->d[m(3, 1)] * v->d[1] +
+		       m->d[m(3, 2)] * v->d[2] +
+		       m->d[m(3, 3)] * v->d[3],
+		},
+	};
+
+	return ret;
+}
+
 #endif /* __IGT_MATRIX_H__ */
-- 
2.16.4

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-06-07 16:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-06 20:16 [igt-dev] [PATCH i-g-t 1/4] lib/igt_matrix: Unroll and inline igt_matrix_transform() Ville Syrjala
2018-06-06 20:16 ` [igt-dev] [PATCH i-g-t 2/4] lib/igt_color_encoding: Use the m(row, col) macro to address the matrix cells Ville Syrjala
2018-06-06 20:40   ` Chris Wilson
2018-06-06 20:16 ` [igt-dev] [PATCH i-g-t 3/4] lib/igt_color_encoding: Appease c90 Ville Syrjala
2018-06-06 20:42   ` Chris Wilson
2018-06-07 11:43   ` [igt-dev] [PATCH i-g-t v2 " Ville Syrjala
2018-06-07 11:45     ` Chris Wilson
2018-06-07 12:06       ` Ville Syrjälä
2018-06-06 20:16 ` [igt-dev] [PATCH i-g-t 4/4] lib/igt_fb: Round to nearest when clamping rgb Ville Syrjala
2018-06-07  8:20   ` Maarten Lankhorst
2018-06-06 20:39 ` [igt-dev] [PATCH i-g-t 1/4] lib/igt_matrix: Unroll and inline igt_matrix_transform() Chris Wilson
2018-06-06 20:45 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] " Patchwork
2018-06-06 21:40 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-06-07 12:08 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/4] lib/igt_matrix: Unroll and inline igt_matrix_transform() (rev2) Patchwork
2018-06-07 16:25 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox