# HG changeset patch
# User Edouard Gomez <[EMAIL PROTECTED]>
# Date 1209654405 -7200
# Node ID 9bf0268fa0d3839f408bceae30b255cc1d89b8ad
# Parent  f02d11363569a1a8459f87cba839b32d70024756
color: do not use align attribute

The problem with the align attribute is that it's not reliable
across gcc versions and platforms. All versions seem to align
correctly .ro or .bss data but they almost all fail at aligning
vars on stack.

It's quite hard to determine what gcc version+target does the
alignment right or not. So better use our own, this should
help a windows build (anyone compiling on win32 ?)

Batched fixes:
- Use a custom alignment macro for vers on the stack
- Turn the top variable into a const global for both SSE and 3DNow code.

diff --git a/src/rawstudio.h b/src/rawstudio.h
--- a/src/rawstudio.h
+++ b/src/rawstudio.h
@@ -22,6 +22,7 @@
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <lcms.h>
+#include <stdint.h>
 #include "dcraw_api.h"
 #include "rs-arch.h"
 #include "rs-cms.h"
@@ -107,6 +108,14 @@
 #define align(x)
 #define __deprecated
 #endif
+
+/* The problem with the align GNU extension, is that it doesn't work
+ * reliably with local variables, depending on versions and targets.
+ * So better use a tricky define to ensure alignment even in these
+ * cases. */
+#define RS_DECLARE_ALIGNED(type, name, sizex, sizey, alignment) \
+       type name##_s[(sizex)*(sizey)+(alignment)-1];   \
+       type * name = (type *)(((uintptr_t)name##_s+(alignment - 
1))&~((uintptr_t)(alignment)-1))
 
 typedef struct _RSStore RSStore;
 
diff --git a/src/rs-color-transform.c b/src/rs-color-transform.c
--- a/src/rs-color-transform.c
+++ b/src/rs-color-transform.c
@@ -457,35 +457,32 @@
 }
 
 #if defined (__i386__) || defined (__x86_64__)
+static const gfloat top[4] align(16) = {65535.f, 65535.f, 65535.f, 65535.f};
+
 COLOR_TRANSFORM(transform_nocms8_sse)
 {
        register glong r,g,b;
        gint destoffset;
        gint col;
-       gfloat top[4] align(16) = {65535.0, 65535.0, 65535.0, 65535.0};
-       gfloat mat[12] align(16) = {
-               rct->priv->color_matrix.coeff[0][0],
-               rct->priv->color_matrix.coeff[1][0],
-               rct->priv->color_matrix.coeff[2][0],
-               RLUM * (rct->priv->color_matrix.coeff[0][0]
-                       + rct->priv->color_matrix.coeff[0][1]
-                       + rct->priv->color_matrix.coeff[0][2]),
-               rct->priv->color_matrix.coeff[0][1],
-               rct->priv->color_matrix.coeff[1][1],
-               rct->priv->color_matrix.coeff[2][1],
-               GLUM * (rct->priv->color_matrix.coeff[1][0]
-                       + rct->priv->color_matrix.coeff[1][1]
-                       + rct->priv->color_matrix.coeff[1][2]),
-               rct->priv->color_matrix.coeff[0][2],
-               rct->priv->color_matrix.coeff[1][2],
-               rct->priv->color_matrix.coeff[2][2],
-               BLUM * (rct->priv->color_matrix.coeff[2][0]
-                       + rct->priv->color_matrix.coeff[2][1]
-                       + rct->priv->color_matrix.coeff[2][2])
-       };
+       RS_DECLARE_ALIGNED(gfloat, mat, 4, 3, 16);
 
        if ((rct==NULL) || (width<1) || (height<1) || (in == NULL) || 
(in_rowstride<8) || (out == NULL) || (out_rowstride<1))
                return;
+
+       mat[0] = rct->priv->color_matrix.coeff[0][0];
+       mat[1] = rct->priv->color_matrix.coeff[1][0];
+       mat[2] = rct->priv->color_matrix.coeff[2][0];
+       mat[3] = 0.f;
+
+       mat[4] = rct->priv->color_matrix.coeff[0][1];
+       mat[5] = rct->priv->color_matrix.coeff[1][1];
+       mat[6] = rct->priv->color_matrix.coeff[2][1];
+       mat[7] = 0.f;
+
+       mat[8]  = rct->priv->color_matrix.coeff[0][2];
+       mat[9]  = rct->priv->color_matrix.coeff[1][2];
+       mat[10] = rct->priv->color_matrix.coeff[2][2];
+       mat[11] = 0.f;
 
        asm volatile (
                "movups (%2), %%xmm2\n\t" /* rs->pre_mul */
@@ -495,7 +492,7 @@
                "movaps (%1), %%xmm6\n\t" /* top */
                "pxor %%mm7, %%mm7\n\t" /* 0x0 */
                :
-               : "r" (mat), "r" (top), "r" (rct->priv->pre_mul)
+               : "r" (&mat[0]), "r" (&top[0]), "r" (rct->priv->pre_mul)
                : "memory"
        );
        while(height--)
@@ -565,25 +562,25 @@
        gint destoffset;
        gint col;
        register glong r=0,g=0,b=0;
-       gfloat mat[12] align(8);
-       gfloat top[2] align(8);
+       RS_DECLARE_ALIGNED(gfloat, mat, 4, 3, 8);
+
+       if ((rct==NULL) || (width<1) || (height<1) || (in == NULL) || 
(in_rowstride<8) || (out == NULL) || (out_rowstride<1))
+               return;
+
        mat[0] = rct->priv->color_matrix.coeff[0][0];
        mat[1] = rct->priv->color_matrix.coeff[0][1];
        mat[2] = rct->priv->color_matrix.coeff[0][2];
-       mat[3] = 0.0;
+       mat[3] = 0.f;
+
        mat[4] = rct->priv->color_matrix.coeff[1][0];
        mat[5] = rct->priv->color_matrix.coeff[1][1];
        mat[6] = rct->priv->color_matrix.coeff[1][2];
-       mat[7] = 0.0;
-       mat[8] = rct->priv->color_matrix.coeff[2][0];
-       mat[9] = rct->priv->color_matrix.coeff[2][1];
+       mat[7] = 0.f;
+
+       mat[8]  = rct->priv->color_matrix.coeff[2][0];
+       mat[9]  = rct->priv->color_matrix.coeff[2][1];
        mat[10] = rct->priv->color_matrix.coeff[2][2];
-       mat[11] = 0.0;
-       top[0] = 65535.0;
-       top[1] = 65535.0;
-
-       if ((rct==NULL) || (width<1) || (height<1) || (in == NULL) || 
(in_rowstride<8) || (out == NULL) || (out_rowstride<1))
-               return;
+       mat[11] = 0.f;
 
        asm volatile (
                "femms\n\t"
@@ -592,7 +589,7 @@
                "movq 8(%0), %%mm3\n\t" /* pre_mul B | pre_mul G2 */
                "movq (%1), %%mm6\n\t" /* 65535.0 | 65535.0 */
                :
-               : "r" (rct->priv->pre_mul), "r" (&top)
+               : "r" (rct->priv->pre_mul), "r" (&top[0])
        );
        while(height--)
        {
@@ -655,7 +652,7 @@
                                "pf2id %%mm5, %%mm5\n\t"
                                "movd %%mm5, %3\n\t"
                                : "+r" (s), "+r" (r), "+r" (g), "+r" (b)
-                               : "r" (&mat)
+                               : "r" (&mat[0])
                        );
                        d[destoffset++] = rct->priv->table8[r];
                        d[destoffset++] = rct->priv->table8[g];
@@ -673,23 +670,25 @@
        register glong r,g,b;
        gint destoffset;
        gint col;
-       gfloat top[4] align(16) = {65535.0, 65535.0, 65535.0, 65535.0};
-       gfloat mat[12] align(16) = {
-               rct->priv->color_matrix.coeff[0][0],
-               rct->priv->color_matrix.coeff[1][0],
-               rct->priv->color_matrix.coeff[2][0],
-               0.0,
-               rct->priv->color_matrix.coeff[0][1],
-               rct->priv->color_matrix.coeff[1][1],
-               rct->priv->color_matrix.coeff[2][1],
-               0.0,
-               rct->priv->color_matrix.coeff[0][2],
-               rct->priv->color_matrix.coeff[1][2],
-               rct->priv->color_matrix.coeff[2][2],
-               0.0 };
+       RS_DECLARE_ALIGNED(gfloat, mat, 4, 3, 16);
 
        if ((rct==NULL) || (width<1) || (height<1) || (in == NULL) || 
(in_rowstride<8) || (out == NULL) || (out_rowstride<1))
                return;
+
+       mat[0] = rct->priv->color_matrix.coeff[0][0];
+       mat[1] = rct->priv->color_matrix.coeff[1][0];
+       mat[2] = rct->priv->color_matrix.coeff[2][0];
+       mat[3] = 0.f;
+
+       mat[4] = rct->priv->color_matrix.coeff[0][1];
+       mat[5] = rct->priv->color_matrix.coeff[1][1];
+       mat[6] = rct->priv->color_matrix.coeff[2][1];
+       mat[7] = 0.f;
+
+       mat[8]  = rct->priv->color_matrix.coeff[0][2];
+       mat[9]  = rct->priv->color_matrix.coeff[1][2];
+       mat[10] = rct->priv->color_matrix.coeff[2][2];
+       mat[11] = 0.f;
 
        asm volatile (
                "movups (%2), %%xmm2\n\t" /* rs->pre_mul */
@@ -699,7 +698,7 @@
                "movaps (%1), %%xmm6\n\t" /* top */
                "pxor %%mm7, %%mm7\n\t" /* 0x0 */
                :
-               : "r" (mat), "r" (top), "r" (rct->priv->pre_mul)
+               : "r" (&mat[0]), "r" (&top[0]), "r" (rct->priv->pre_mul)
                : "memory"
        );
        while(height--)
@@ -769,25 +768,25 @@
        gint destoffset;
        gint col;
        register glong r=0,g=0,b=0;
-       gfloat mat[12] align(8);
-       gfloat top[2] align(8);
+       RS_DECLARE_ALIGNED(gfloat, mat, 4, 3, 8);
+
+       if ((rct==NULL) || (width<1) || (height<1) || (in == NULL) || 
(in_rowstride<8) || (out == NULL) || (out_rowstride<1))
+               return;
+
        mat[0] = rct->priv->color_matrix.coeff[0][0];
        mat[1] = rct->priv->color_matrix.coeff[0][1];
        mat[2] = rct->priv->color_matrix.coeff[0][2];
-       mat[3] = 0.0;
+       mat[3] = 0.f;
+
        mat[4] = rct->priv->color_matrix.coeff[1][0];
        mat[5] = rct->priv->color_matrix.coeff[1][1];
        mat[6] = rct->priv->color_matrix.coeff[1][2];
-       mat[7] = 0.0;
-       mat[8] = rct->priv->color_matrix.coeff[2][0];
-       mat[9] = rct->priv->color_matrix.coeff[2][1];
+       mat[7] = 0.f;
+
+       mat[8]  = rct->priv->color_matrix.coeff[2][0];
+       mat[9]  = rct->priv->color_matrix.coeff[2][1];
        mat[10] = rct->priv->color_matrix.coeff[2][2];
-       mat[11] = 0.0;
-       top[0] = 65535.0;
-       top[1] = 65535.0;
-
-       if ((rct==NULL) || (width<1) || (height<1) || (in == NULL) || 
(in_rowstride<8) || (out == NULL) || (out_rowstride<1))
-               return;
+       mat[11] = 0.f;
 
        asm volatile (
                "femms\n\t"
@@ -796,7 +795,7 @@
                "movq 8(%0), %%mm3\n\t" /* pre_mul B | pre_mul G2 */
                "movq (%1), %%mm6\n\t" /* 65535.0 | 65535.0 */
                :
-               : "r" (rct->priv->pre_mul), "r" (&top)
+               : "r" (rct->priv->pre_mul), "r" (&top[0])
        );
        while(height--)
        {
@@ -858,7 +857,7 @@
                                "pf2id %%mm5, %%mm5\n\t"
                                "movd %%mm5, %3\n\t"
                                : "+r" (s), "+r" (r), "+r" (g), "+r" (b)
-                               : "r" (&mat)
+                               : "r" (&mat[0])
                        );
                        buffer[destoffset++] = rct->priv->table16[r];
                        buffer[destoffset++] = rct->priv->table16[g];

_______________________________________________
Rawstudio-dev mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-dev

Reply via email to