[Rawstudio-dev] [PATCH 2 of 7] x86_port: Isolate completly i386 code

Edouard Gomez ed.gomez at free.fr
Wed Sep 27 23:54:53 CEST 2006


3 files changed, 59 insertions(+), 20 deletions(-)
src/color.h     |   15 ++++++++++++++
src/rawstudio.c |    6 +++++
src/rs-render.c |   58 ++++++++++++++++++++++++++++++++++++-------------------


# HG changeset patch
# User Edouard Gomez <ed.gomez at free.fr>
# Date 1159392773 -7200
# Node ID dbdfa1fb6d1d5b426e14c6798e8990f270e2426c
# Parent  ff7039ae4a7fde63a42064f170a20b035aca2716
x86_port: Isolate completly i386 code

Since x86_64 reports cpu features, some code may think that functions
are available but they're not. By design, they're empty. That's bad
because nothing happens then. A better solution is to simply really
isolate i386 code from the C implementation only. That way, until a
function is ported, its C counterpart will be used.

diff -r ff7039ae4a7f -r dbdfa1fb6d1d src/color.h
--- a/src/color.h	Wed Sep 27 23:32:53 2006 +0200
+++ b/src/color.h	Wed Sep 27 23:32:53 2006 +0200
@@ -26,6 +26,8 @@
 #define GAMMA 2.2 /* this is ONLY used to render the histogram */
 
 #define _MAX(in, max) if (in>max) max=in
+
+#ifdef __i386__
 #define _MAX_CMOV(in, max) \
 asm volatile (\
 	"cmpl	%1, %0\n\t"\
@@ -33,8 +35,11 @@ asm volatile (\
 	:"+r" (max)\
 	:"r" (in)\
 )
+#endif
 
 #define _CLAMP(in, max) if (in>max) in=max
+
+#ifdef __i386__
 #define _CLAMP_CMOV(in, max) \
 asm volatile (\
 	"cmpl	%0, %1\n\t"\
@@ -42,8 +47,11 @@ asm volatile (\
 	:"+r" (in)\
 	:"r" (max)\
 )
+#endif
 
 #define _CLAMP65535(a) a = MAX(MIN(65535,a),0)
+
+#ifdef __i386__
 #define _CLAMP65535_CMOV(value) \
 asm volatile (\
 	"xorl %%ecx, %%ecx\n\t"\
@@ -56,9 +64,12 @@ asm volatile (\
 	:\
 	:"%ecx"\
 )
+#endif
 
 #define _CLAMP65535_TRIPLET(a, b, c) \
 a = MAX(MIN(65535,a),0);b = MAX(MIN(65535,b),0);c = MAX(MIN(65535,c),0)
+
+#ifdef __i386__
 #define _CLAMP65535_TRIPLET_CMOV(a, b, c) \
 asm volatile (\
 	"xorl %%ecx, %%ecx\n\t"\
@@ -79,8 +90,11 @@ asm volatile (\
 	:\
 	:"%ecx"\
 )
+#endif
 
 #define _CLAMP255(a) a = MAX(MIN(255,a),0)
+
+#ifdef __i386__
 #define _CLAMP255_CMOV(value) \
 asm volatile (\
 	"xorl %%ecx, %%ecx\n\t"\
@@ -93,6 +107,7 @@ asm volatile (\
 	:\
 	:"%ecx"\
 )
+#endif
 
 #define COLOR_BLACK(c) do { c.red=0; c.green=0; c.blue=0; } while (0)
 
diff -r ff7039ae4a7f -r dbdfa1fb6d1d src/rawstudio.c
--- a/src/rawstudio.c	Wed Sep 27 23:32:53 2006 +0200
+++ b/src/rawstudio.c	Wed Sep 27 23:32:53 2006 +0200
@@ -45,7 +45,9 @@
 #include "rs-render.h"
 #include "x86_cpu.h"
 
+#if defined (__i386__) || defined (__x86_64__)
 guint cpuflags = 0;
+#endif
 gushort loadtable[65536];
 
 static cmsHPROFILE genericLoadProfile = NULL;
@@ -1322,15 +1324,19 @@ rs_cms_prepare_transforms(RS_BLOB *rs)
 	if (gamma != 1.0)
 	{
 		make_gammatable16(loadtable, gamma);
+#ifdef __i386__
 		if (cpuflags & _MMX)
 			cmsSetUserFormatters(loadTransform, TYPE_RGB_16, mycms_unroll_rgb4_w_loadtable, TYPE_RGB_16, mycms_pack_rgb4_w);
 		else
+#endif
 			cmsSetUserFormatters(loadTransform, TYPE_RGB_16, mycms_unroll_rgb_w_loadtable, TYPE_RGB_16, mycms_pack_rgb4_w);
 	}
 	else
+#ifdef __i386__
 		if (cpuflags & _MMX)
 			cmsSetUserFormatters(loadTransform, TYPE_RGB_16, mycms_unroll_rgb4_w, TYPE_RGB_16, mycms_pack_rgb4_w);
 		else
+#endif
 			cmsSetUserFormatters(loadTransform, TYPE_RGB_16, mycms_unroll_rgb_w, TYPE_RGB_16, mycms_pack_rgb4_w);
 
 	if (rs->displayProfile)
diff -r ff7039ae4a7f -r dbdfa1fb6d1d src/rs-render.c
--- a/src/rs-render.c	Wed Sep 27 23:32:53 2006 +0200
+++ b/src/rs-render.c	Wed Sep 27 23:32:53 2006 +0200
@@ -29,15 +29,21 @@
 	void func(RS_PHOTO *photo, gint width, gint height, gushort *in, \
 	gint in_rowstride, gint in_channels, guchar *out, gint out_rowstride, void *profile);
 
+DECL_RENDER(rs_render_cms)
+DECL_RENDER(rs_render_nocms)
+
+#ifdef __i386__
 DECL_RENDER(rs_render_cms_sse)
 DECL_RENDER(rs_render_cms_3dnow)
-DECL_RENDER(rs_render_cms)
 DECL_RENDER(rs_render_nocms_sse)
 DECL_RENDER(rs_render_nocms_3dnow)
-DECL_RENDER(rs_render_nocms)
-
+#endif
+
+void rs_render_histogram_table_c(RS_PHOTO *photo, RS_IMAGE16 *input, guint *table);
+
+#ifdef __i386__
 void rs_render_histogram_table_cmov(RS_PHOTO *photo, RS_IMAGE16 *input, guint *table);
-void rs_render_histogram_table_c(RS_PHOTO *photo, RS_IMAGE16 *input, guint *table);
+#endif
 
 guchar previewtable8[65536];
 gushort previewtable16[65536];
@@ -45,31 +51,39 @@ void
 void
 rs_render_select(gboolean cms)
 {
+#if defined (__i386__) ||  defined (__x86_64__)
 	extern gint cpuflags;
+#endif
 
 	rs_render_previewtable(1.0); /* make sure previewtables are ready */
 
 	if (cms)
 	{
+#ifdef __i386__
 		if (cpuflags & _SSE)
 			rs_render = rs_render_cms_sse;
 		else if (cpuflags & _3DNOW)
 			rs_render = rs_render_cms_3dnow;
 		else
+#endif
 			rs_render = rs_render_cms;
 	}
 	else
 	{
+#ifdef __i386__
 		if (cpuflags & _SSE)
 			rs_render = rs_render_nocms_sse;
 		else if (cpuflags & _3DNOW)
 			rs_render = rs_render_nocms_3dnow;
 		else
+#endif
 			rs_render = rs_render_nocms;
 	}
+#ifdef __i386__
 	if (cpuflags & _CMOV)
 		rs_render_histogram_table = rs_render_histogram_table_cmov;
 	else
+#endif
 		rs_render_histogram_table = rs_render_histogram_table_c;
 	return;
 }
@@ -100,11 +114,12 @@ rs_render_previewtable(const gdouble con
 	}
 }
 
+#ifdef __i386__
+
 void
 rs_render_cms_sse(RS_PHOTO *photo, gint width, gint height, gushort *in,
 	gint in_rowstride, gint in_channels, guchar *out, gint out_rowstride, void *profile)
 {
-#ifdef __i386__
 	gushort *buffer = g_malloc(width*3*sizeof(gushort));
 	register gint r,g,b;
 	gint destoffset;
@@ -192,7 +207,6 @@ rs_render_cms_sse(RS_PHOTO *photo, gint 
 	}
 	asm volatile("emms\n\t");
 	g_free(buffer);
-#endif
 	return;
 }
 
@@ -200,7 +214,6 @@ rs_render_cms_3dnow(RS_PHOTO *photo, gin
 rs_render_cms_3dnow(RS_PHOTO *photo, gint width, gint height, gushort *in,
 	gint in_rowstride, gint in_channels, guchar *out, gint out_rowstride, void *profile)
 {
-#ifdef __i386__
 	gushort *buffer = g_malloc(width*3*sizeof(gushort));
 	gint destoffset;
 	gint col;
@@ -300,9 +313,10 @@ rs_render_cms_3dnow(RS_PHOTO *photo, gin
 	}
 	asm volatile ("femms\n\t");
 	g_free(buffer);
-#endif
-	return;
-}
+	return;
+}
+
+#endif /* __i386__ */
 
 void
 rs_render_cms(RS_PHOTO *photo, gint width, gint height, gushort *in,
@@ -347,11 +361,12 @@ rs_render_cms(RS_PHOTO *photo, gint widt
 	return;
 }
 
+#ifdef __i386__
+
 void
 rs_render_nocms_sse(RS_PHOTO *photo, gint width, gint height, gushort *in,
 	gint in_rowstride, gint in_channels, guchar *out, gint out_rowstride, void *profile)
 {
-#ifdef __i386__
 	register gint r,g,b;
 	gint destoffset;
 	gint col;
@@ -437,7 +452,6 @@ rs_render_nocms_sse(RS_PHOTO *photo, gin
 		}
 	}
 	asm volatile("emms\n\t");
-#endif
 	return;
 }
 
@@ -445,7 +459,6 @@ rs_render_nocms_3dnow(RS_PHOTO *photo, g
 rs_render_nocms_3dnow(RS_PHOTO *photo, gint width, gint height, gushort *in,
 	gint in_rowstride, gint in_channels, guchar *out, gint out_rowstride, void *profile)
 {
-#ifdef __i386__
 	gint destoffset;
 	gint col;
 	register gint r=0,g=0,b=0;
@@ -543,9 +556,12 @@ rs_render_nocms_3dnow(RS_PHOTO *photo, g
 		}
 	}
 	asm volatile ("femms\n\t");
-#endif
-	return;
-}
+
+	return;
+}
+
+#endif /* __i386__ */
+
 void
 rs_render_nocms(RS_PHOTO *photo, gint width, gint height, gushort *in,
 	gint in_rowstride, gint in_channels, guchar *out, gint out_rowstride, void *profile)
@@ -587,10 +603,11 @@ rs_render_nocms(RS_PHOTO *photo, gint wi
 	return;
 }
 
+#ifdef __i386__
+
 void
 rs_render_histogram_table_cmov(RS_PHOTO *photo, RS_IMAGE16 *input, guint *table)
 {
-#ifdef __i386__
 	gint y,x;
 	gint srcoffset;
 	gint r,g,b,rr,gg,bb;
@@ -627,9 +644,10 @@ rs_render_histogram_table_cmov(RS_PHOTO 
 			srcoffset+=input->pixelsize;
 		}
 	}
-#endif
-	return;
-}
+	return;
+}
+
+#endif
 
 void
 rs_render_histogram_table_c(RS_PHOTO *photo, RS_IMAGE16 *input, guint *table)



More information about the Rawstudio-dev mailing list