[babl/wip/rishi/cie-simd: 1/3] CIE: Add an SSE2 version of "YA float" to "CIE L float"



commit 3d3d5f5a60fc3844a14aeac7c89298e7151ad5d6
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue May 15 13:38:25 2018 +0200

    CIE: Add an SSE2 version of "YA float" to "CIE L float"
    
    On an Intel i7 Haswell, it now takes 0.039s to convert a 15 megapixel
    buffer from "YA float" to "CIE L float" instead of the earlier 0.082s.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=795686

 extensions/CIE.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/extensions/CIE.c b/extensions/CIE.c
index b93b055..fc0c66c 100644
--- a/extensions/CIE.c
+++ b/extensions/CIE.c
@@ -1124,6 +1124,47 @@ lab_r_to_f_sse2 (__m128 r)
 }
 
 static void
+Yaf_to_Lf_sse2 (const Babl *conversion, const float *src, float *dst, long samples)
+{
+  long i = 0;
+  long remainder;
+
+  if (((uintptr_t) src % 16) + ((uintptr_t) dst % 16) == 0)
+    {
+      const long n = (samples / 4) * 4;
+
+      for ( ; i < n; i += 4)
+        {
+          __m128 YaYa0 = _mm_load_ps (src);
+          __m128 YaYa1 = _mm_load_ps (src + 4);
+
+          __m128 Y = _mm_shuffle_ps (YaYa0, YaYa1, _MM_SHUFFLE (2, 0, 2, 0));
+
+          __m128 fy = lab_r_to_f_sse2 (Y);
+
+          __m128 L = _mm_sub_ps (_mm_mul_ps (_mm_set1_ps (116.0f), fy), _mm_set1_ps (16.0f));
+
+          _mm_store_ps (dst, L);
+
+          src += 8;
+          dst += 4;
+        }
+    }
+
+  remainder = samples - i;
+  while (remainder--)
+    {
+      float yr = src[0];
+      float L  = yr > LAB_EPSILON ? 116.0f * _cbrtf (yr) - 16 : LAB_KAPPA * yr;
+
+      dst[0] = L;
+
+      src += 2;
+      dst += 1;
+    }
+}
+
+static void
 rgbaf_to_Lf_sse2 (const Babl *conversion, const float *src, float *dst, long samples)
 {
   const Babl *space = babl_conversion_get_source_space (conversion);
@@ -1474,7 +1515,12 @@ conversions (void)
         "linear", rgbaf_to_Labaf_sse2,
         NULL
       );
-
+      babl_conversion_new (
+        babl_format ("YA float"),
+        babl_format ("CIE L float"),
+        "linear", Yaf_to_Lf_sse2,
+        NULL
+      );
       babl_conversion_new (
         babl_format ("RGBA float"),
         babl_format ("CIE L float"),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]