gegl r2220 - in trunk: . gegl gegl/operation operations/common operations/generated



Author: ok
Date: Tue Apr 22 22:32:27 2008
New Revision: 2220
URL: http://svn.gnome.org/viewvc/gegl?rev=2220&view=rev

Log:
* gegl/gegl-plugin.h: renamed gegl4float to g4float.
* gegl/operation/gegl-operation-processors.c:
(gegl_class_register_alternate_vfunc): code simplification and
cleanup.
Migrated with API:
* operations/common/brightness-contrast.c:
(gegl_chant_class_init):
* operations/common/invert.c:
(gegl_chant_class_init):
* operations/generated/other-blend.rb:
* operations/generated/svg-12-porter-duff.rb:


Modified:
   trunk/ChangeLog
   trunk/gegl/gegl-plugin.h
   trunk/gegl/operation/gegl-operation-processors.c
   trunk/operations/common/brightness-contrast.c
   trunk/operations/common/invert.c
   trunk/operations/generated/other-blend.rb
   trunk/operations/generated/svg-12-porter-duff.rb

Modified: trunk/gegl/gegl-plugin.h
==============================================================================
--- trunk/gegl/gegl-plugin.h	(original)
+++ trunk/gegl/gegl-plugin.h	Tue Apr 22 22:32:27 2008
@@ -86,27 +86,53 @@
 const gchar * gegl_extension_handler_get      (const gchar *extension);
 
 
-#define CHECK_GCC_VECTORS defined(__GNUC__) && (__GNUC__ >= 4)
+#if defined(__GNUC__) && (__GNUC__ >= 4)
+#define HAS_G4FLOAT 1
+#include <math.h>
+
+typedef float g4float __attribute__ ((vector_size (4*sizeof(float))));
+
+#define g4float_a(a)      ((float *)(&a))
+#define g4floatR(a)       g4float_a(a)[0]
+#define g4floatG(a)       g4float_a(a)[1]
+#define g4floatB(a)       g4float_a(a)[2]
+#define g4floatA(a)       g4float_a(a)[3]
+#define g4float(a,b,c,d)  ((g4float){a,b,c,d})
+#define g4float_all(val)  g4float(val,val,val,val)
+#define g4float_zero      g4float_all(0.0)
+#define g4float_one       g4float_all(1.0)
+#define g4float_half      g4float_all(0.5)
+#define g4float_half      g4float_all(0.5)
+#define g4float_mul(a,val)  g4float_all(val)*(a)
+
+#ifdef USE_SSE
+
+#define g4float_sqrt(v)     __builtin_ia32_sqrtps((v))
+#define g4float_max(a,b)    __builtin_ia32_maxps((a,b))
+#define g4float_min(a,b)    __builtin_ia32_minps((a,b))
+#define g4float_rcp(a,b)    __builtin_ia32_rcpps((v))
 
-#if CHECK_GCC_VECTORS
-#define USE_GCC_VECTORS 1
-
-typedef float Gegl4float __attribute__ ((vector_size (4*sizeof(float))));
-
-#define Gegl4float_a(a)      ((float *)(&a))
-#define Gegl4floatR(a)       Gegl4float_a(a)[0]
-#define Gegl4floatG(a)       Gegl4float_a(a)[1]
-#define Gegl4floatB(a)       Gegl4float_a(a)[2]
-#define Gegl4floatA(a)       Gegl4float_a(a)[3]
-#define Gegl4float(a,b,c,d)  ((Gegl4float){a,b,c,d})
-#define Gegl4float_all(val)  Gegl4float(val,val,val,val)
-#define Gegl4float_zero      Gegl4float_all(0.0)
-#define Gegl4float_one       Gegl4float_all(1.0)
-#define Gegl4float_half      Gegl4float_all(0.5)
-
-
-#define Gegl4float_mul(vec,val)  ((vec) * Gegl4float_all(val))
+#else
 
+#define g4float_sqrt(v)     g4float(sqrt(g4floatR(v)),\
+                                    sqrt(g4floatG(v)),\
+                                    sqrt(g4floatB(v)),\
+                                    sqrt(g4floatA(v)))
+#define g4float_rcp(v)      g4float(1.0/(g4floatR(v)),\
+                                    1.0/(g4floatG(v)),\
+                                    1.0/(g4floatB(v)),\
+                                    1.0/(g4floatA(v)))
+#define g4float_max(a,b)   g4float(\
+                               gfloat4R(a)>gfloat4R(b)?gfloat4R(a):gfloat4R(b),\
+                               gfloat4G(a)>gfloat4G(b)?gfloat4G(a):gfloat4G(b),\
+                               gfloat4B(a)>gfloat4B(b)?gfloat4B(a):gfloat4B(b),\
+                               gfloat4A(a)>gfloat4A(b)?gfloat4A(a):gfloat4A(b))
+#define g4float_min(a,b)   g4float(\
+                               gfloat4R(a)<gfloat4R(b)?gfloat4R(a):gfloat4R(b),\
+                               gfloat4G(a)<gfloat4G(b)?gfloat4G(a):gfloat4G(b),\
+                               gfloat4B(a)<gfloat4B(b)?gfloat4B(a):gfloat4B(b),\
+                               gfloat4A(a)<gfloat4A(b)?gfloat4A(a):gfloat4A(b))
+#endif
 
 #endif
 

Modified: trunk/gegl/operation/gegl-operation-processors.c
==============================================================================
--- trunk/gegl/operation/gegl-operation-processors.c	(original)
+++ trunk/gegl/operation/gegl-operation-processors.c	Tue Apr 22 22:32:27 2008
@@ -108,81 +108,54 @@
                  g_type_name (G_TYPE_FROM_CLASS (cclass)));
     }
 
-#ifdef USE_SSE
-  /* always look for sse ops */
-#else
-  if (g_getenv ("GEGL_QUALITY"))
-#endif
     {
       const gchar *quality  = g_getenv ("GEGL_QUALITY");
-      GCallback fast        = NULL;
-      GCallback good        = NULL;
-      GCallback reference   = NULL;
-      GCallback gcc_vectors = NULL;
-#ifdef USE_SSE
-      GCallback sse       = NULL;
+      gint fast        = 0;
+      gint good        = 0;
+      gint reference   = 0;
+      gint g4f         = 0;
+
+      gint choice = 0;
+
+      /* if no quality is specified, look for good, which also includes the
+       * g4float implementation */
       if (quality == NULL)
-        quality = "sse";
-#endif
+        quality = "good";
 
       for (i=0;i<MAX_PROCESSOR;i++)
         {
           const gchar *string = data->string[i];
-          GCallback    cb     = data->callback[i];
+          GCallback cb = data->callback[i];
 
           if (string && cb!=NULL)
             {
               if (g_str_equal (string, "fast"))
-                fast = cb;
-              if (g_str_equal (string, "gcc-vectors"))
-                gcc_vectors = cb;
+                fast = i;
+              if (g_str_equal (string, "g4float"))
+                g4f = i;
               else if (g_str_equal (string, "good"))
-                good = cb;
-#ifdef USE_SSE
-              else if (g_str_equal (string, "sse"))
-                sse = cb;
-#endif
+                good = i;
               else if (g_str_equal (string, "reference"))
-                reference = cb;
+                reference = i;
             }
         }
+      reference = 0;
+      g_assert (data->callback[reference]);
 
-      g_assert (reference);
-      if (g_str_equal (quality, "fast"))
+      if (g_str_equal (quality, "good")||
+          g_str_equal (quality, "fast"))
         {
-#ifdef USE_SSE
-          GEGL_NOTE(PROCESSOR, "Setting %s callback for %s", fast?"fast":sse?"sse":gcc_vectors?"gcc-vectors":good?"good":"reference",
-          g_type_name (G_TYPE_FROM_CLASS (cclass)));
-          *vfunc_ptr = fast?fast:sse?sse:gcc_vectors?gcc_vectors:good?good:reference;
-#else
-          GEGL_NOTE(PROCESSOR, "Setting %s callback for %s", fast?"fast":gcc_vectors?"gcc-vectors":good?"good":"reference",
-          g_type_name (G_TYPE_FROM_CLASS (cclass)));
-          *vfunc_ptr = fast?fast:gcc_vectors?gcc_vectors:good?good:reference;
-#endif
+          if (good) choice = good;
+          if (g4f) choice = g4f;
         }
-      else if (g_str_equal (quality, "good"))
-        {
-#ifdef USE_SSE
-          GEGL_NOTE(PROCESSOR, "Setting %s callback for %s", sse?"sse":gcc_vectors?"gcc-vectors":good?"good":"reference",
-           g_type_name (G_TYPE_FROM_CLASS (cclass)));
-          *vfunc_ptr = sse?sse:gcc_vectors?gcc_vectors:good?good:reference;
-#else
-          GEGL_NOTE(PROCESSOR, "Setting %s callback for %s", gcc_vectors?"gcc-vectors":good?"good":"reference",
-           g_type_name (G_TYPE_FROM_CLASS (cclass)));
-          *vfunc_ptr = gcc_vectors?"gcc-vectors":good?good:reference;
-#endif
-        }
-      else
+      if (g_str_equal (quality, "fast"))
         {
-          /* best */
-#ifdef USE_SSE
-          if (sse && gegl_cpu_accel_get_support () & GEGL_CPU_ACCEL_X86_SSE)
-            GEGL_NOTE(PROCESSOR, "Setting sse processor for %s", g_type_name (G_TYPE_FROM_CLASS (cclass)));
-          *vfunc_ptr = sse?sse:reference;
-#else
-          *vfunc_ptr = reference;
-#endif
+          if (good) choice = good;
+          if (g4f) choice = g4f;
         }
+
+      GEGL_NOTE(PROCESSOR, "Using %s implementation for %s", data->string[choice], g_type_name (G_TYPE_FROM_CLASS (cclass)));
+      *vfunc_ptr = data->callback[choice];
     }
 }
 

Modified: trunk/operations/common/brightness-contrast.c
==============================================================================
--- trunk/operations/common/brightness-contrast.c	(original)
+++ trunk/operations/common/brightness-contrast.c	Tue Apr 22 22:32:27 2008
@@ -108,7 +108,7 @@
 }
 
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
 
 static gboolean
 process_gcc_vectors (GeglOperation *op,
@@ -117,19 +117,19 @@
                      glong          samples)
 {
   GeglChantO *o = GEGL_CHANT_PROPERTIES (op);
-  Gegl4float *in  = in_buf;
-  Gegl4float *out = out_buf;
+  g4float *in  = in_buf;
+  g4float *out = out_buf;
 
   /* add 0.5 to brightness here to make the logic in the innerloop tighter
    */
-  Gegl4float  brightness = Gegl4float_all(o->brightness + 0.5);
-  Gegl4float  contrast   = Gegl4float_all(o->contrast);
-  Gegl4float  half       = Gegl4float_half;
+  g4float  brightness = g4float_all(o->brightness + 0.5);
+  g4float  contrast   = g4float_all(o->contrast);
+  g4float  half       = g4float_half;
     
   while (--samples)
     {
       *out = (*in - half) * contrast + brightness;
-      Gegl4floatA(*out)=Gegl4floatA(*in);
+      g4floatA(*out)=g4floatA(*in);
       in  ++;
       out ++;
     }
@@ -169,13 +169,13 @@
   operation_class->description = _("Changes the light level and contrast.");
 
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
   /* add conditionally compiled variation of process(), gegl should be able
    * to determine which is fastest and hopefully if any implementation is
    * broken and not conforming to the reference implementation.
    */
   gegl_operation_class_add_processor (operation_class,
-                                      G_CALLBACK (process_gcc_vectors), "gcc-vectors");
+                                      G_CALLBACK (process_gcc_vectors), "g4float");
 #endif
 }
 

Modified: trunk/operations/common/invert.c
==============================================================================
--- trunk/operations/common/invert.c	(original)
+++ trunk/operations/common/invert.c	Tue Apr 22 22:32:27 2008
@@ -54,22 +54,22 @@
   return TRUE;
 }
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
 static gboolean
-process_sse (GeglOperation *op,
+process_g4f (GeglOperation *op,
              void          *in_buf,
              void          *out_buf,
              glong          samples)
 {
-  Gegl4float *in  = in_buf;
-  Gegl4float *out = out_buf;
-  Gegl4float  one = Gegl4float_one;
+  g4float *in  = in_buf;
+  g4float *out = out_buf;
+  g4float  one = g4float_one;
 
   while (--samples)
     {
-      gfloat a= Gegl4float_a(*in)[3];
+      gfloat a= g4float_a(*in)[3];
       *out = one - *in;
-      Gegl4float_a(*out)[3]=a;
+      g4float_a(*out)[3]=a;
       in  ++;
       out ++;
     }
@@ -94,9 +94,9 @@
      "Inverts the components (except alpha), the result is the"
      " corresponding \"negative\" image.";
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
   gegl_operation_class_add_processor (operation_class,
-                                      G_CALLBACK (process_sse), "gcc-vectors");
+                                      G_CALLBACK (process_g4f), "g4float");
 #endif
 }
 

Modified: trunk/operations/generated/other-blend.rb
==============================================================================
--- trunk/operations/generated/other-blend.rb	(original)
+++ trunk/operations/generated/other-blend.rb	Tue Apr 22 22:32:27 2008
@@ -35,11 +35,11 @@
 #       Alias for porter-duff src-over
       ['normal',  'cA + cB * (1 - aA)',
                   'aA + aB - aA * aB',
-                  '*D = *A + *B * (Gegl4float_one - Gegl4float_all(Gegl4float_a(*A)[3]))'],
+                  '*D = *A + *B * (g4float_one - g4float_all(g4float_a(*A)[3]))'],
 #       Alias for porter-duff src-over
       ['over',    'cA + cB * (1 - aA)',
                   'aA + aB - aA * aB',
-                  '*D = *A + *B * (Gegl4float_one - Gegl4float_all(Gegl4float_a(*A)[3]))'],
+                  '*D = *A + *B * (g4float_one - g4float_all(g4float_a(*A)[3]))'],
     ]
 
 file_head1 = '
@@ -90,9 +90,9 @@
   point_composer_class->process = process;
   operation_class->prepare = prepare;
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
   gegl_operation_class_add_processor (operation_class,
-                                      G_CALLBACK (process_gegl4float), "gcc-vectors");
+                                      G_CALLBACK (process_gegl4float), "g4float");
 #endif
 
 '
@@ -154,7 +154,7 @@
   return TRUE;
 }
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
 
 static gboolean
 process_gegl4float (GeglOperation *op,
@@ -163,11 +163,11 @@
                     void          *out_buf,
                     glong          n_pixels)
 {
-  Gegl4float *A = aux_buf;
-  Gegl4float *B = in_buf;
-  Gegl4float *D = out_buf;
+  g4float *A = aux_buf;
+  g4float *B = in_buf;
+  g4float *D = out_buf;
 
-  if (B==NULL)
+  if (B==NULL || n_pixels == 0)
     return TRUE;
 
   while (--n_pixels)

Modified: trunk/operations/generated/svg-12-porter-duff.rb
==============================================================================
--- trunk/operations/generated/svg-12-porter-duff.rb	(original)
+++ trunk/operations/generated/svg-12-porter-duff.rb	Tue Apr 22 22:32:27 2008
@@ -34,7 +34,7 @@
 a = [
       ['clear',         '0.0',
                         '0.0',
-                        '*D = Gegl4float_zero'],
+                        '*D = g4float_zero'],
       ['src',           'cA',
                         'aA',
                         '*D = *A'],
@@ -43,29 +43,29 @@
                         '*D = *B'],
       ['src_over',      'cA + cB * (1 - aA)',
                         'aA + aB - aA * aB',
-                        '*D = *A + Gegl4float_mul (*B, 1.0 - Gegl4floatA(*A))'],
+                        '*D = *A + g4float_mul (*B, 1.0 - g4floatA(*A))'],
       ['dst_over',      'cB + cA * (1 - aB)',
                         'aA + aB - aA * aB',
-                        '*D = *B + Gegl4float_mul (*A, 1.0 - Gegl4floatA(*B))'],
+                        '*D = *B + g4float_mul (*A, 1.0 - g4floatA(*B))'],
       ['src_in',        'cA * aB',  # this one had special treatment wrt rectangles in deleted file porter-duff.rb before the svg ops came in, perhaps that was with good reason? /pippin
                         'aA * aB',
-                        '*D = Gegl4float_mul(*A,  Gegl4floatA(*B))'],
+                        '*D = g4float_mul(*A,  g4floatA(*B))'],
       ['dst_in',        'cB * aA', # <- XXX: typo?
                         'aA * aB', 
-                        '*D = Gegl4float_mul (*B, Gegl4floatA(*A))'],
+                        '*D = g4float_mul (*B, g4floatA(*A))'],
       ['src_out',       'cA * (1 - aB)',
                         'aA * (1 - aB)',
-                        '*D = Gegl4float_mul (*A, 1.0 - Gegl4floatA(*B))'],
+                        '*D = g4float_mul (*A, 1.0 - g4floatA(*B))'],
       ['dst_out',       'cB * (1 - aA)',
                         'aB * (1 - aA)',
-                        '*D = Gegl4float_mul (*B, 1.0 - Gegl4floatA(*A))'],
+                        '*D = g4float_mul (*B, 1.0 - g4floatA(*A))'],
       ['src_atop',      'cA * aB + cB * (1 - aA)',
                         'aB',
-                         '*D = Gegl4float_mul (*A, Gegl4floatA(*B)) + Gegl4float_mul (*B, 1.0 - Gegl4floatA(*A));Gegl4floatA(*D)=Gegl4floatA(*B)'],
+                         '*D = g4float_mul (*A, g4floatA(*B)) + g4float_mul (*B, 1.0 - g4floatA(*A));g4floatA(*D)=g4floatA(*B)'],
 
       ['dst_atop',      'cB * aA + cA * (1 - aB)',
                         'aA',
-                         '*D = Gegl4float_mul (*B, Gegl4floatA(*A)) + Gegl4float_mul (*A, 1.0 - Gegl4floatA(*B));Gegl4floatA(*D)=Gegl4floatA(*A)'],
+                         '*D = g4float_mul (*B, g4floatA(*A)) + g4float_mul (*A, 1.0 - g4floatA(*B));g4floatA(*D)=g4floatA(*A)'],
       ['xor',           'cA * (1 - aB)+ cB * (1 - aA)',
                         'aA + aB - 2 * aA * aB',
                         '*D = *A * *B'] # FIXME this is wrong
@@ -119,9 +119,9 @@
   point_composer_class->process = process;
   operation_class->prepare = prepare;
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
   gegl_operation_class_add_processor (operation_class,
-                                      G_CALLBACK (process_gegl4float), "gcc-vectors");
+                                      G_CALLBACK (process_gegl4float), "g4float");
 #endif
 
 '
@@ -183,7 +183,7 @@
   return TRUE;
 }
 
-#ifdef USE_GCC_VECTORS
+#ifdef HAS_G4FLOAT
 
 static gboolean
 process_gegl4float (GeglOperation *op,
@@ -192,13 +192,13 @@
                     void          *out_buf,
                     glong          n_pixels)
 {
-  Gegl4float *A = aux_buf;
-  Gegl4float *B = in_buf;
-  Gegl4float *D = out_buf;
+  g4float *A = aux_buf;
+  g4float *B = in_buf;
+  g4float *D = out_buf;
 
-  if (B==NULL)
+  if (B==NULL || n_pixels == 0)
     return TRUE;
-
+    
   while (--n_pixels)
     {
       #{sse_formula};



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