diff --git a/ChangeLog b/ChangeLog index 9ae0d67371..1fbbb64330 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,32 @@ +2006-06-02 Sven Neumann + + Moved the CPU detection code to libgimpbase (see bug #342860): + + * app/base/Makefile.am + * app/base/cpu-accel.[ch] + * app/base/test-cpu-accel.c: removed here... + + * libgimpbase/Makefile.am + * libgimpbase/gimpbase.h + * libgimpbase/gimpcpuaccel.[ch] + + * libgimpbase/test-cpu-accel.c: ... and added here again with + some API changes. + + * app/composite/Makefile.am + * app/composite/make-installer.py: changed accordingly. + + * app/composite/gimp-composite-*-installer.c: regenerated. + + * libgimp/gimp.c (gimp_main): call gimp_set_use_cpu_accel(). + 2006-06-01 Michael Natterer * cursors/Makefile.am * cursors/modifier-bad.png * cursors/xbm/modifier-bad-mask.xbm - * cursors/xbm/modifier-bad.xbm: new "bad" cursor - modifier. Replaces the "bad" cursor. + * cursors/xbm/modifier-bad.xbm: new "bad" cursor modifier. + Replaces the "bad" cursor. * cursors/gimp-tool-cursors.xcf: added it here too. diff --git a/app/base/.cvsignore b/app/base/.cvsignore index ae7ba5f48a..9a8991c881 100644 --- a/app/base/.cvsignore +++ b/app/base/.cvsignore @@ -4,4 +4,3 @@ Makefile.in .libs *.lo libappbase.la -test-cpu-accel diff --git a/app/base/Makefile.am b/app/base/Makefile.am index 5ad174336b..6f9791230e 100644 --- a/app/base/Makefile.am +++ b/app/base/Makefile.am @@ -20,8 +20,6 @@ libappbase_a_SOURCES = \ cpercep.h \ curves.c \ curves.h \ - cpu-accel.c \ - cpu-accel.h \ gimphistogram.c \ gimphistogram.h \ gimplut.c \ @@ -61,12 +59,6 @@ AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\"Gimp-Base\" \ @GTHREAD_CFLAGS@ -AM_CCASFLAGS = \ - -I$(top_builddir) \ - -I$(top_srcdir) \ - -I$(top_builddir)/app \ - -I$(top_srcdir)/app - INCLUDES = \ -I$(top_builddir) \ -I$(top_srcdir) \ @@ -75,24 +67,16 @@ INCLUDES = \ $(GLIB_CFLAGS) \ -I$(includedir) -TESTS = test-cpu-accel - -test_cpu_accel_SOURCES = test-cpu-accel.c - -test_cpu_accel_LDADD = \ - libappbase.a \ - $(GLIB_LIBS) EXTRA_DIST = makefile.msc -EXTRA_PROGRAMS = test-cpu-accel # # rules to generate built sources # # setup autogeneration dependencies gen_sources = xgen-bec -CLEANFILES = $(EXTRA_PROGRAMS) $(gen_sources) +CLEANFILES = $(gen_sources) $(srcdir)/base-enums.c: $(srcdir)/base-enums.h $(GIMP_MKENUMS) $(GIMP_MKENUMS) \ diff --git a/app/base/cpu-accel.c b/app/base/cpu-accel.c deleted file mode 100644 index 8d049e38b3..0000000000 --- a/app/base/cpu-accel.c +++ /dev/null @@ -1,485 +0,0 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* - * x86 bits Copyright (C) Manish Singh - */ - -/* - * PPC CPU acceleration detection was taken from DirectFB but seems to be - * originating from mpeg2dec with the following copyright: - * - * Copyright (C) 1999-2001 Aaron Holtzman - */ - -#include "config.h" - -#include -#include -#include - -#include - -#include "cpu-accel.h" - -#if defined(ARCH_X86) && defined(USE_MMX) && defined(__GNUC__) - -#define HAVE_ACCEL 1 - -typedef enum -{ - ARCH_X86_VENDOR_NONE, - ARCH_X86_VENDOR_INTEL, - ARCH_X86_VENDOR_AMD, - ARCH_X86_VENDOR_CENTAUR, - ARCH_X86_VENDOR_CYRIX, - ARCH_X86_VENDOR_NSC, - ARCH_X86_VENDOR_TRANSMETA, - ARCH_X86_VENDOR_NEXGEN, - ARCH_X86_VENDOR_RISE, - ARCH_X86_VENDOR_UMC, - ARCH_X86_VENDOR_SIS, - ARCH_X86_VENDOR_UNKNOWN = 0xff -} X86Vendor; - -enum -{ - ARCH_X86_INTEL_FEATURE_MMX = 1 << 23, - ARCH_X86_INTEL_FEATURE_XMM = 1 << 25, - ARCH_X86_INTEL_FEATURE_XMM2 = 1 << 26, - - ARCH_X86_AMD_FEATURE_MMXEXT = 1 << 22, - ARCH_X86_AMD_FEATURE_3DNOW = 1 << 31, - - ARCH_X86_CENTAUR_FEATURE_MMX = 1 << 23, - ARCH_X86_CENTAUR_FEATURE_MMXEXT = 1 << 24, - ARCH_X86_CENTAUR_FEATURE_3DNOW = 1 << 31, - - ARCH_X86_CYRIX_FEATURE_MMX = 1 << 23, - ARCH_X86_CYRIX_FEATURE_MMXEXT = 1 << 24 -}; - -enum -{ - ARCH_X86_INTEL_FEATURE_PNI = 1 << 0 -}; - -#if !defined(ARCH_X86_64) && (defined(PIC) || defined(__PIC__)) -#define cpuid(op,eax,ebx,ecx,edx) \ - __asm__ ("movl %%ebx, %%esi\n\t" \ - "cpuid\n\t" \ - "xchgl %%ebx,%%esi" \ - : "=a" (eax), \ - "=S" (ebx), \ - "=c" (ecx), \ - "=d" (edx) \ - : "0" (op)) -#else -#define cpuid(op,eax,ebx,ecx,edx) \ - __asm__ ("cpuid" \ - : "=a" (eax), \ - "=b" (ebx), \ - "=c" (ecx), \ - "=d" (edx) \ - : "0" (op)) -#endif - - -static X86Vendor -arch_get_vendor (void) -{ - guint32 eax, ebx, ecx, edx; - gchar id[16]; - -#ifndef ARCH_X86_64 - /* Only need to check this on ia32 */ - __asm__ ("pushfl\n\t" - "pushfl\n\t" - "popl %0\n\t" - "movl %0,%1\n\t" - "xorl $0x200000,%0\n\t" - "pushl %0\n\t" - "popfl\n\t" - "pushfl\n\t" - "popl %0\n\t" - "popfl" - : "=a" (eax), - "=c" (ecx) - : - : "cc"); - - if (eax == ecx) - return ARCH_X86_VENDOR_NONE; -#endif - - cpuid (0, eax, ebx, ecx, edx); - - if (eax == 0) - return ARCH_X86_VENDOR_NONE; - - *(int *)&id[0] = ebx; - *(int *)&id[4] = edx; - *(int *)&id[8] = ecx; - - id[12] = '\0'; - -#ifdef ARCH_X86_64 - if (strcmp (id, "AuthenticAMD") == 0) - return ARCH_X86_VENDOR_AMD; - else if (strcmp (id, "GenuineIntel") == 0) - return ARCH_X86_VENDOR_INTEL; -#else - if (strcmp (id, "GenuineIntel") == 0) - return ARCH_X86_VENDOR_INTEL; - else if (strcmp (id, "AuthenticAMD") == 0) - return ARCH_X86_VENDOR_AMD; - else if (strcmp (id, "CentaurHauls") == 0) - return ARCH_X86_VENDOR_CENTAUR; - else if (strcmp (id, "CyrixInstead") == 0) - return ARCH_X86_VENDOR_CYRIX; - else if (strcmp (id, "Geode by NSC") == 0) - return ARCH_X86_VENDOR_NSC; - else if (strcmp (id, "GenuineTMx86") == 0 || - strcmp (id, "TransmetaCPU") == 0) - return ARCH_X86_VENDOR_TRANSMETA; - else if (strcmp (id, "NexGenDriven") == 0) - return ARCH_X86_VENDOR_NEXGEN; - else if (strcmp (id, "RiseRiseRise") == 0) - return ARCH_X86_VENDOR_RISE; - else if (strcmp (id, "UMC UMC UMC ") == 0) - return ARCH_X86_VENDOR_UMC; - else if (strcmp (id, "SiS SiS SiS ") == 0) - return ARCH_X86_VENDOR_SIS; -#endif - - return ARCH_X86_VENDOR_UNKNOWN; -} - -static guint32 -arch_accel_intel (void) -{ - guint32 caps = 0; - -#ifdef USE_MMX - { - guint32 eax, ebx, ecx, edx; - - cpuid (1, eax, ebx, ecx, edx); - - if ((edx & ARCH_X86_INTEL_FEATURE_MMX) == 0) - return 0; - - caps = CPU_ACCEL_X86_MMX; - -#ifdef USE_SSE - if (edx & ARCH_X86_INTEL_FEATURE_XMM) - caps |= CPU_ACCEL_X86_SSE | CPU_ACCEL_X86_MMXEXT; - - if (edx & ARCH_X86_INTEL_FEATURE_XMM2) - caps |= CPU_ACCEL_X86_SSE2; - - if (ecx & ARCH_X86_INTEL_FEATURE_PNI) - caps |= CPU_ACCEL_X86_SSE3; -#endif /* USE_SSE */ - } -#endif /* USE_MMX */ - - return caps; -} - -static guint32 -arch_accel_amd (void) -{ - guint32 caps; - - caps = arch_accel_intel (); - -#ifdef USE_MMX - { - guint32 eax, ebx, ecx, edx; - - cpuid (0x80000000, eax, ebx, ecx, edx); - - if (eax < 0x80000001) - return caps; - -#ifdef USE_SSE - cpuid (0x80000001, eax, ebx, ecx, edx); - - if (edx & ARCH_X86_AMD_FEATURE_3DNOW) - caps |= CPU_ACCEL_X86_3DNOW; - - if (edx & ARCH_X86_AMD_FEATURE_MMXEXT) - caps |= CPU_ACCEL_X86_MMXEXT; -#endif /* USE_SSE */ - } -#endif /* USE_MMX */ - - return caps; -} - -static guint32 -arch_accel_centaur (void) -{ - guint32 caps; - - caps = arch_accel_intel (); - -#ifdef USE_MMX - { - guint32 eax, ebx, ecx, edx; - - cpuid (0x80000000, eax, ebx, ecx, edx); - - if (eax < 0x80000001) - return caps; - - cpuid (0x80000001, eax, ebx, ecx, edx); - - if (edx & ARCH_X86_CENTAUR_FEATURE_MMX) - caps |= CPU_ACCEL_X86_MMX; - -#ifdef USE_SSE - if (edx & ARCH_X86_CENTAUR_FEATURE_3DNOW) - caps |= CPU_ACCEL_X86_3DNOW; - - if (edx & ARCH_X86_CENTAUR_FEATURE_MMXEXT) - caps |= CPU_ACCEL_X86_MMXEXT; -#endif /* USE_SSE */ - } -#endif /* USE_MMX */ - - return caps; -} - -static guint32 -arch_accel_cyrix (void) -{ - guint32 caps; - - caps = arch_accel_intel (); - -#ifdef USE_MMX - { - guint32 eax, ebx, ecx, edx; - - cpuid (0, eax, ebx, ecx, edx); - - if (eax != 2) - return caps; - - cpuid (0x80000001, eax, ebx, ecx, edx); - - if (edx & ARCH_X86_CYRIX_FEATURE_MMX) - caps |= CPU_ACCEL_X86_MMX; - -#ifdef USE_SSE - if (edx & ARCH_X86_CYRIX_FEATURE_MMXEXT) - caps |= CPU_ACCEL_X86_MMXEXT; -#endif /* USE_SSE */ - } -#endif /* USE_MMX */ - - return caps; -} - -#ifdef USE_SSE -static jmp_buf sigill_return; - -static void -sigill_handler (gint n) -{ - longjmp (sigill_return, 1); -} - -static gboolean -arch_accel_sse_os_support (void) -{ - if (setjmp (sigill_return)) - { - return FALSE; - } - else - { - signal (SIGILL, sigill_handler); - __asm__ __volatile__ ("xorps %xmm0, %xmm0"); - signal (SIGILL, SIG_DFL); - } - - return TRUE; -} -#endif /* USE_SSE */ - -static guint32 -arch_accel (void) -{ - guint32 caps; - X86Vendor vendor; - - vendor = arch_get_vendor (); - - switch (vendor) - { - case ARCH_X86_VENDOR_NONE: - caps = 0; - break; - - case ARCH_X86_VENDOR_AMD: - caps = arch_accel_amd (); - break; - - case ARCH_X86_VENDOR_CENTAUR: - caps = arch_accel_centaur (); - break; - - case ARCH_X86_VENDOR_CYRIX: - case ARCH_X86_VENDOR_NSC: - caps = arch_accel_cyrix (); - break; - - /* check for what Intel speced, even if UNKNOWN */ - default: - caps = arch_accel_intel (); - break; - } - -#ifdef USE_SSE - if ((caps & CPU_ACCEL_X86_SSE) && !arch_accel_sse_os_support ()) - caps &= ~(CPU_ACCEL_X86_SSE | CPU_ACCEL_X86_SSE2); -#endif - - return caps; -} - -#endif /* ARCH_X86 && USE_MMX && __GNUC__ */ - - -#if defined(ARCH_PPC) && defined (USE_ALTIVEC) - -#if defined(HAVE_ALTIVEC_SYSCTL) - -#include - -#define HAVE_ACCEL 1 - -static guint32 -arch_accel (void) -{ - gint sels[2] = { CTL_HW, HW_VECTORUNIT }; - gboolean has_vu = FALSE; - gsize length = sizeof(has_vu); - gint err; - - err = sysctl (sels, 2, &has_vu, &length, NULL, 0); - - if (err == 0 && has_vu) - return CPU_ACCEL_PPC_ALTIVEC; - - return 0; -} - -#elif defined(__GNUC__) - -#define HAVE_ACCEL 1 - -static sigjmp_buf jmpbuf; -static volatile sig_atomic_t canjump = 0; - -static void -sigill_handler (gint sig) -{ - if (!canjump) - { - signal (sig, SIG_DFL); - raise (sig); - } - - canjump = 0; - siglongjmp (jmpbuf, 1); -} - -static guint32 -arch_accel (void) -{ - signal (SIGILL, sigill_handler); - - if (sigsetjmp (jmpbuf, 1)) - { - signal (SIGILL, SIG_DFL); - return 0; - } - - canjump = 1; - - asm volatile ("mtspr 256, %0\n\t" - "vand %%v0, %%v0, %%v0" - : - : "r" (-1)); - - signal (SIGILL, SIG_DFL); - - return CPU_ACCEL_PPC_ALTIVEC; -} -#endif /* __GNUC__ */ - -#endif /* ARCH_PPC && USE_ALTIVEC */ - - -guint32 -cpu_accel (void) -{ -#ifdef HAVE_ACCEL - static guint32 accel = ~0U; - - if (accel != ~0U) - return accel; - - accel = arch_accel (); - - return accel; - -#else /* !HAVE_ACCEL */ - return 0; -#endif -} - -void -cpu_accel_print_results (void) -{ - g_printerr ("Testing CPU features...\n"); - -#ifdef ARCH_X86 - g_printerr (" mmx : %s\n", - (cpu_accel() & CPU_ACCEL_X86_MMX) ? "yes" : "no"); - g_printerr (" 3dnow : %s\n", - (cpu_accel() & CPU_ACCEL_X86_3DNOW) ? "yes" : "no"); - g_printerr (" mmxext : %s\n", - (cpu_accel() & CPU_ACCEL_X86_MMXEXT) ? "yes" : "no"); - g_printerr (" sse : %s\n", - (cpu_accel() & CPU_ACCEL_X86_SSE) ? "yes" : "no"); - g_printerr (" sse2 : %s\n", - (cpu_accel() & CPU_ACCEL_X86_SSE2) ? "yes" : "no"); - g_printerr (" sse3 : %s\n", - (cpu_accel() & CPU_ACCEL_X86_SSE3) ? "yes" : "no"); -#endif -#ifdef ARCH_PPC - g_printerr (" altivec : %s\n", - (cpu_accel() & CPU_ACCEL_PPC_ALTIVEC) ? "yes" : "no"); -#endif - g_printerr ("\n"); -} diff --git a/app/base/cpu-accel.h b/app/base/cpu-accel.h deleted file mode 100644 index 9871a29e05..0000000000 --- a/app/base/cpu-accel.h +++ /dev/null @@ -1,48 +0,0 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* - * CPU acceleration detection was taken from DirectFB but seems to be - * originating from mpeg2dec with the following copyright: - * - * Copyright (C) 1999-2001 Aaron Holtzman - */ - -#ifndef __CPU_ACCEL_H__ -#define __CPU_ACCEL_H__ - - -/* x86 accelerations */ -#define CPU_ACCEL_X86_MMX 0x80000000 -#define CPU_ACCEL_X86_3DNOW 0x40000000 -#define CPU_ACCEL_X86_MMXEXT 0x20000000 -#define CPU_ACCEL_X86_SSE 0x10000000 -#define CPU_ACCEL_X86_SSE2 0x08000000 -#define CPU_ACCEL_X86_SSE3 0x02000000 - -/* powerpc accelerations */ -#define CPU_ACCEL_PPC_ALTIVEC 0x04000000 - - -guint32 cpu_accel (void) G_GNUC_CONST; - -void cpu_accel_print_results (void); - - -#endif /* __CPU_ACCEL_H__ */ - diff --git a/app/base/test-cpu-accel.c b/app/base/test-cpu-accel.c deleted file mode 100644 index 2c64a72810..0000000000 --- a/app/base/test-cpu-accel.c +++ /dev/null @@ -1,31 +0,0 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include - -#include "cpu-accel.h" - - -int -main (void) -{ - cpu_accel_print_results (); - return 0; -} diff --git a/app/composite/Makefile.am b/app/composite/Makefile.am index 009380fe9d..7cc53c6020 100644 --- a/app/composite/Makefile.am +++ b/app/composite/Makefile.am @@ -1,5 +1,6 @@ ## Process this file with automake to produce Makefile.in +libgimpbase = $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la libgimpcolor = $(top_builddir)/libgimpcolor/libgimpcolor-$(GIMP_API_VERSION).la AM_CPPFLAGS = \ @@ -133,8 +134,8 @@ gimp_composite_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) @@ -147,8 +148,8 @@ gimp_composite_mmx_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_mmx_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) gimp_composite_sse_test_SOURCES = \ @@ -160,8 +161,8 @@ gimp_composite_sse_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_sse_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) gimp_composite_sse2_test_SOURCES = \ @@ -173,8 +174,8 @@ gimp_composite_sse2_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_sse2_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) @@ -187,8 +188,8 @@ gimp_composite_3dnow_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_3dnow_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) @@ -201,8 +202,8 @@ gimp_composite_altivec_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_altivec_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) gimp_composite_vis_test_SOURCES = \ @@ -214,6 +215,6 @@ gimp_composite_vis_test_DEPENDENCIES = $(gimpcomposite_dependencies) gimp_composite_vis_test_LDADD = \ libappcomposite.a \ - ../base/libappbase.a \ $(libgimpcolor) \ + $(libgimpbase) \ $(GLIB_LIBS) diff --git a/app/composite/gimp-composite-3dnow-installer.c b/app/composite/gimp-composite-3dnow-installer.c index 43b4cec515..ca7cc90580 100644 --- a/app/composite/gimp-composite-3dnow-installer.c +++ b/app/composite/gimp-composite-3dnow-installer.c @@ -1,11 +1,11 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include +#include "libgimpbase/gimpbase.h" #include "base/base-types.h" -#include "base/cpu-accel.h" #include "gimp-composite.h" #include "gimp-composite-3dnow.h" @@ -23,7 +23,7 @@ gboolean gimp_composite_3dnow_init (void) { #if defined(COMPILE_3DNOW_IS_OKAY) - if (cpu_accel () & CPU_ACCEL_X86_3DNOW) + if (gimp_cpu_accel_get_support () & GIMP_CPU_ACCEL_X86_3DNOW) { return (TRUE); } diff --git a/app/composite/gimp-composite-altivec-installer.c b/app/composite/gimp-composite-altivec-installer.c index ee1bd44379..e5e5b6013f 100644 --- a/app/composite/gimp-composite-altivec-installer.c +++ b/app/composite/gimp-composite-altivec-installer.c @@ -1,53 +1,20 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include +#include "libgimpbase/gimpbase.h" #include "base/base-types.h" -#include "base/cpu-accel.h" #include "gimp-composite.h" #include "gimp-composite-altivec.h" -static const struct install_table { - GimpCompositeOperation mode; - GimpPixelFormat A; - GimpPixelFormat B; - GimpPixelFormat D; - void (*function)(GimpCompositeContext *); -} _gimp_composite_altivec[] = { -#if defined(COMPILE_ALTIVEC_IS_OKAY) - { GIMP_COMPOSITE_MULTIPLY, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_multiply_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_SCREEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_screen_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_DIFFERENCE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_difference_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_ADDITION, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_addition_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_SUBTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_subtract_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_DARKEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_darken_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_LIGHTEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_lighten_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_DIVIDE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_divide_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_DODGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_dodge_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_GRAIN_EXTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_grain_extract_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_GRAIN_MERGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_grain_merge_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_BLEND, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_blend_rgba8_rgba8_rgba8_altivec }, - { GIMP_COMPOSITE_SWAP, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, gimp_composite_swap_rgba8_rgba8_rgba8_altivec }, -#endif - { 0, 0, 0, 0, NULL } -}; gboolean gimp_composite_altivec_install (void) { - static const struct install_table *t = _gimp_composite_altivec; - - if (gimp_composite_altivec_init ()) - { - for (t = &_gimp_composite_altivec[0]; t->function != NULL; t++) - { - gimp_composite_function[t->mode][t->A][t->B][t->D] = t->function; - } - return (TRUE); - } + /* nothing to do */ return (FALSE); } @@ -56,7 +23,7 @@ gboolean gimp_composite_altivec_init (void) { #if defined(COMPILE_ALTIVEC_IS_OKAY) - if (cpu_accel () & CPU_ACCEL_PPC_ALTIVEC) + if (gimp_cpu_accel_get_support () & GIMP_CPU_ACCEL_PPC_ALTIVEC) { return (TRUE); } diff --git a/app/composite/gimp-composite-altivec-test.c b/app/composite/gimp-composite-altivec-test.c index 788442afda..24e2545cfc 100644 --- a/app/composite/gimp-composite-altivec-test.c +++ b/app/composite/gimp-composite-altivec-test.c @@ -64,149 +64,6 @@ gimp_composite_altivec_test (int iterations, int n_pixels) va8M[i].a = i; } - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_ADDITION, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_ADDITION, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_addition_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("addition", &generic_ctx, &special_ctx)) - { - printf("addition_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("addition_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_BLEND, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_BLEND, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_blend_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("blend", &generic_ctx, &special_ctx)) - { - printf("blend_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("blend_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_DARKEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_DARKEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_darken_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("darken", &generic_ctx, &special_ctx)) - { - printf("darken_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("darken_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_DIFFERENCE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_DIFFERENCE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_difference_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("difference", &generic_ctx, &special_ctx)) - { - printf("difference_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("difference_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_DIVIDE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_DIVIDE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_divide_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("divide", &generic_ctx, &special_ctx)) - { - printf("divide_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("divide_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_DODGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_DODGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_dodge_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("dodge", &generic_ctx, &special_ctx)) - { - printf("dodge_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("dodge_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_GRAIN_EXTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_GRAIN_EXTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_grain_extract_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("grain_extract", &generic_ctx, &special_ctx)) - { - printf("grain_extract_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("grain_extract_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_GRAIN_MERGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_GRAIN_MERGE, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_grain_merge_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("grain_merge", &generic_ctx, &special_ctx)) - { - printf("grain_merge_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("grain_merge_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_LIGHTEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_LIGHTEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_lighten_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("lighten", &generic_ctx, &special_ctx)) - { - printf("lighten_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("lighten_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_MULTIPLY, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_MULTIPLY, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_multiply_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("multiply", &generic_ctx, &special_ctx)) - { - printf("multiply_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("multiply_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SCREEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SCREEN, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_screen_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("screen", &generic_ctx, &special_ctx)) - { - printf("screen_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("screen_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SUBTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SUBTRACT, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_subtract_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("subtract", &generic_ctx, &special_ctx)) - { - printf("subtract_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("subtract_rgba8_rgba8_rgba8", ft0, ft1); - - gimp_composite_context_init (&special_ctx, GIMP_COMPOSITE_SWAP, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D2); - gimp_composite_context_init (&generic_ctx, GIMP_COMPOSITE_SWAP, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, GIMP_PIXELFORMAT_RGBA8, n_pixels, (unsigned char *) rgba8A, (unsigned char *) rgba8B, (unsigned char *) rgba8B, (unsigned char *) rgba8D1); - ft0 = gimp_composite_regression_time_function (iterations, gimp_composite_dispatch, &generic_ctx); - ft1 = gimp_composite_regression_time_function (iterations, gimp_composite_swap_rgba8_rgba8_rgba8_altivec, &special_ctx); - if (gimp_composite_regression_compare_contexts ("swap", &generic_ctx, &special_ctx)) - { - printf("swap_rgba8_rgba8_rgba8 failed\n"); - return (1); - } - gimp_composite_regression_timer_report ("swap_rgba8_rgba8_rgba8", ft0, ft1); #endif return (0); } diff --git a/app/composite/gimp-composite-generic-installer.c b/app/composite/gimp-composite-generic-installer.c index bbfc8cacf0..deb449d174 100644 --- a/app/composite/gimp-composite-generic-installer.c +++ b/app/composite/gimp-composite-generic-installer.c @@ -1,9 +1,9 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include #include "base/base-types.h" #include "gimp-composite.h" diff --git a/app/composite/gimp-composite-mmx-installer.c b/app/composite/gimp-composite-mmx-installer.c index cc49de27c8..face38e81b 100644 --- a/app/composite/gimp-composite-mmx-installer.c +++ b/app/composite/gimp-composite-mmx-installer.c @@ -1,11 +1,11 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include +#include "libgimpbase/gimpbase.h" #include "base/base-types.h" -#include "base/cpu-accel.h" #include "gimp-composite.h" #include "gimp-composite-mmx.h" @@ -56,7 +56,7 @@ gboolean gimp_composite_mmx_init (void) { #if defined(COMPILE_MMX_IS_OKAY) - if (cpu_accel () & CPU_ACCEL_X86_MMX) + if (gimp_cpu_accel_get_support () & GIMP_CPU_ACCEL_X86_MMX) { return (TRUE); } diff --git a/app/composite/gimp-composite-sse-installer.c b/app/composite/gimp-composite-sse-installer.c index e0553e7ca8..f663d42e30 100644 --- a/app/composite/gimp-composite-sse-installer.c +++ b/app/composite/gimp-composite-sse-installer.c @@ -1,11 +1,11 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include +#include "libgimpbase/gimpbase.h" #include "base/base-types.h" -#include "base/cpu-accel.h" #include "gimp-composite.h" #include "gimp-composite-sse.h" @@ -54,9 +54,9 @@ gboolean gimp_composite_sse_init (void) { #if defined(COMPILE_SSE_IS_OKAY) - guint32 cpu = cpu_accel (); + GimpCpuAccelFlags cpu = gimp_cpu_accel_get_support (); - if (cpu & CPU_ACCEL_X86_SSE || cpu & CPU_ACCEL_X86_MMXEXT) + if (cpu & GIMP_CPU_ACCEL_X86_SSE || cpu & GIMP_CPU_ACCEL_X86_MMXEXT) { return (TRUE); } diff --git a/app/composite/gimp-composite-sse2-installer.c b/app/composite/gimp-composite-sse2-installer.c index 837dd8421d..f5337d4be8 100644 --- a/app/composite/gimp-composite-sse2-installer.c +++ b/app/composite/gimp-composite-sse2-installer.c @@ -1,11 +1,11 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include +#include "libgimpbase/gimpbase.h" #include "base/base-types.h" -#include "base/cpu-accel.h" #include "gimp-composite.h" #include "gimp-composite-sse2.h" @@ -50,7 +50,7 @@ gboolean gimp_composite_sse2_init (void) { #if defined(COMPILE_SSE2_IS_OKAY) - if (cpu_accel () & CPU_ACCEL_X86_SSE2) + if (gimp_cpu_accel_get_support () & GIMP_CPU_ACCEL_X86_SSE2) { return (TRUE); } diff --git a/app/composite/gimp-composite-vis-installer.c b/app/composite/gimp-composite-vis-installer.c index 9afa2d3048..980fe87ca8 100644 --- a/app/composite/gimp-composite-vis-installer.c +++ b/app/composite/gimp-composite-vis-installer.c @@ -1,9 +1,9 @@ /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */ /* REGENERATE BY USING make-installer.py */ #include "config.h" -#include #include #include +#include #include "base/base-types.h" #include "gimp-composite.h" diff --git a/app/composite/make-installer.py b/app/composite/make-installer.py index 4cd0bf4483..aa97a01bc3 100755 --- a/app/composite/make-installer.py +++ b/app/composite/make-installer.py @@ -459,13 +459,13 @@ def gimp_composite_installer_install3(fpout, name, requirements=[], cpu_feature= if len(cpu_feature) >= 2: features = [] for f in cpu_feature: - features.append('cpu & CPU_ACCEL_%s' % f) + features.append('cpu & GIMP_CPU_ACCEL_%s' % f) feature_test = ' || '.join(features) - print >>fpout, ' guint32 cpu = cpu_accel ();' + print >>fpout, ' GimpCpuAccelFlags cpu = gimp_cpu_accel_get_support ();' print >>fpout, '' else: - feature_test = 'cpu_accel () & CPU_ACCEL_%s' % cpu_feature[0] + feature_test = 'gimp_cpu_accel_get_support () & GIMP_CPU_ACCEL_%s' % cpu_feature[0] print >>fpout, ' if (%s)' % feature_test print >>fpout, ' {' @@ -506,12 +506,12 @@ def gimp_composite_cfile(fpout, name, function_table, requirements=[], cpu_featu print >>fpout, '/* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT */' print >>fpout, '/* REGENERATE BY USING make-installer.py */' print >>fpout, '#include "config.h"' - print >>fpout, '#include ' print >>fpout, '#include ' print >>fpout, '#include ' - print >>fpout, '#include "base/base-types.h"' + print >>fpout, '#include ' if cpu_feature: - print >>fpout, '#include "base/cpu-accel.h"' + print >>fpout, '#include "libgimpbase/gimpbase.h"' + print >>fpout, '#include "base/base-types.h"' print >>fpout, '#include "gimp-composite.h"' print >>fpout, '' print >>fpout, '#include "%s.h"' % (filenameify(name)) diff --git a/libgimp/gimp.c b/libgimp/gimp.c index 3b02fcb291..6b0e161d04 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -391,6 +391,8 @@ gimp_main (const GimpPlugInInfo *info, gimp_base_init (&vtable); } + gimp_cpu_accel_set_use (gimp_use_cpu_accel ()); + /* initialize i18n support */ diff --git a/libgimpbase/.cvsignore b/libgimpbase/.cvsignore index 59dc2e88b0..f5005d1dd9 100644 --- a/libgimpbase/.cvsignore +++ b/libgimpbase/.cvsignore @@ -9,3 +9,4 @@ _libs gimpversion.h *.lib *.exp +test-cpu-accel diff --git a/libgimpbase/Makefile.am b/libgimpbase/Makefile.am index ba3dc31108..ff1c81d443 100644 --- a/libgimpbase/Makefile.am +++ b/libgimpbase/Makefile.am @@ -54,6 +54,10 @@ AM_CPPFLAGS = \ @BINRELOC_CFLAGS@ \ @GTHREAD_CFLAGS@ +AM_CCASFLAGS = \ + -I$(top_builddir) \ + -I$(top_srcdir) + INCLUDES = \ -I$(top_srcdir) \ $(GLIB_CFLAGS) \ @@ -84,6 +88,8 @@ libgimpbase_sources = \ gimpbase-private.h \ gimpchecks.c \ gimpchecks.h \ + gimpcpuaccel.c \ + gimpcpuaccel.h \ gimpdatafiles.c \ gimpdatafiles.h \ gimpenv.c \ @@ -147,13 +153,31 @@ install-data-local: install-ms-lib install-libtool-import-lib uninstall-local: uninstall-ms-lib uninstall-libtool-import-lib +# +# test programs, not to be built by default and never installed +# + +TESTS = test-cpu-accel + +test_cpu_accel_SOURCES = test-cpu-accel.c + +test_cpu_accel_DEPENDENCIES = \ + $(top_builddir)/libgimpbase/libgimpbase-$(GIMP_API_VERSION).la + +test_cpu_accel_LDADD = \ + $(GLIB_LIBS) \ + $(test_cpu_accel_DEPENDENCIES) + + +EXTRA_PROGRAMS = test-cpu-accel + # # rules to generate built sources # gen_sources = xgen-bec -CLEANFILES = $(gen_sources) +CLEANFILES = $(EXTRA_PROGRAMS) $(gen_sources) $(srcdir)/gimpbaseenums.c: $(srcdir)/gimpbaseenums.h $(GIMP_MKENUMS) $(GIMP_MKENUMS) \ diff --git a/libgimpbase/gimpbase.h b/libgimpbase/gimpbase.h index 73807b4ed0..5dc360747e 100644 --- a/libgimpbase/gimpbase.h +++ b/libgimpbase/gimpbase.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/libgimpbase/gimpcpuaccel.c b/libgimpbase/gimpcpuaccel.c index 8d049e38b3..871e45b499 100644 --- a/libgimpbase/gimpcpuaccel.c +++ b/libgimpbase/gimpcpuaccel.c @@ -1,19 +1,20 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ /* @@ -35,12 +36,50 @@ #include -#include "cpu-accel.h" +#include "gimpcpuaccel.h" + + +static GimpCpuAccelFlags cpu_accel (void); G_GNUC_CONST + + +static gboolean use_cpu_accel = TRUE; + + +/** + * gimp_cpu_accel_get_support: + * + * Query for CPU acceleration support. + * + * Return value: #GimpCpuAccelFlags as supported by the CPU. + * + * Since: GIMP 2.4 + */ +GimpCpuAccelFlags +gimp_cpu_accel_get_support (void) +{ + return use_cpu_accel ? cpu_accel () : GIMP_CPU_ACCEL_NONE; +} + +/** + * gimp_cpu_accel_set_use: + * @use: whether to use CPU acceleration features or not + * + * This function is for internal use only. + * + * Since: GIMP 2.4 + */ +void +gimp_cpu_accel_set_use (gboolean use) +{ + use_cpu_accel = use ? TRUE : FALSE; +} + #if defined(ARCH_X86) && defined(USE_MMX) && defined(__GNUC__) #define HAVE_ACCEL 1 + typedef enum { ARCH_X86_VENDOR_NONE, @@ -184,17 +223,17 @@ arch_accel_intel (void) if ((edx & ARCH_X86_INTEL_FEATURE_MMX) == 0) return 0; - caps = CPU_ACCEL_X86_MMX; + caps = GIMP_CPU_ACCEL_X86_MMX; #ifdef USE_SSE if (edx & ARCH_X86_INTEL_FEATURE_XMM) - caps |= CPU_ACCEL_X86_SSE | CPU_ACCEL_X86_MMXEXT; + caps |= GIMP_CPU_ACCEL_X86_SSE | GIMP_CPU_ACCEL_X86_MMXEXT; if (edx & ARCH_X86_INTEL_FEATURE_XMM2) - caps |= CPU_ACCEL_X86_SSE2; + caps |= GIMP_CPU_ACCEL_X86_SSE2; if (ecx & ARCH_X86_INTEL_FEATURE_PNI) - caps |= CPU_ACCEL_X86_SSE3; + caps |= GIMP_CPU_ACCEL_X86_SSE3; #endif /* USE_SSE */ } #endif /* USE_MMX */ @@ -222,10 +261,10 @@ arch_accel_amd (void) cpuid (0x80000001, eax, ebx, ecx, edx); if (edx & ARCH_X86_AMD_FEATURE_3DNOW) - caps |= CPU_ACCEL_X86_3DNOW; + caps |= GIMP_CPU_ACCEL_X86_3DNOW; if (edx & ARCH_X86_AMD_FEATURE_MMXEXT) - caps |= CPU_ACCEL_X86_MMXEXT; + caps |= GIMP_CPU_ACCEL_X86_MMXEXT; #endif /* USE_SSE */ } #endif /* USE_MMX */ @@ -252,14 +291,14 @@ arch_accel_centaur (void) cpuid (0x80000001, eax, ebx, ecx, edx); if (edx & ARCH_X86_CENTAUR_FEATURE_MMX) - caps |= CPU_ACCEL_X86_MMX; + caps |= GIMP_CPU_ACCEL_X86_MMX; #ifdef USE_SSE if (edx & ARCH_X86_CENTAUR_FEATURE_3DNOW) - caps |= CPU_ACCEL_X86_3DNOW; + caps |= GIMP_CPU_ACCEL_X86_3DNOW; if (edx & ARCH_X86_CENTAUR_FEATURE_MMXEXT) - caps |= CPU_ACCEL_X86_MMXEXT; + caps |= GIMP_CPU_ACCEL_X86_MMXEXT; #endif /* USE_SSE */ } #endif /* USE_MMX */ @@ -286,11 +325,11 @@ arch_accel_cyrix (void) cpuid (0x80000001, eax, ebx, ecx, edx); if (edx & ARCH_X86_CYRIX_FEATURE_MMX) - caps |= CPU_ACCEL_X86_MMX; + caps |= GIMP_CPU_ACCEL_X86_MMX; #ifdef USE_SSE if (edx & ARCH_X86_CYRIX_FEATURE_MMXEXT) - caps |= CPU_ACCEL_X86_MMXEXT; + caps |= GIMP_CPU_ACCEL_X86_MMXEXT; #endif /* USE_SSE */ } #endif /* USE_MMX */ @@ -359,8 +398,8 @@ arch_accel (void) } #ifdef USE_SSE - if ((caps & CPU_ACCEL_X86_SSE) && !arch_accel_sse_os_support ()) - caps &= ~(CPU_ACCEL_X86_SSE | CPU_ACCEL_X86_SSE2); + if ((caps & GIMP_CPU_ACCEL_X86_SSE) && !arch_accel_sse_os_support ()) + caps &= ~(GIMP_CPU_ACCEL_X86_SSE | GIMP_CPU_ACCEL_X86_SSE2); #endif return caps; @@ -388,7 +427,7 @@ arch_accel (void) err = sysctl (sels, 2, &has_vu, &length, NULL, 0); if (err == 0 && has_vu) - return CPU_ACCEL_PPC_ALTIVEC; + return GIMP_CPU_ACCEL_PPC_ALTIVEC; return 0; } @@ -433,14 +472,14 @@ arch_accel (void) signal (SIGILL, SIG_DFL); - return CPU_ACCEL_PPC_ALTIVEC; + return GIMP_CPU_ACCEL_PPC_ALTIVEC; } #endif /* __GNUC__ */ #endif /* ARCH_PPC && USE_ALTIVEC */ -guint32 +static GimpCpuAccelFlags cpu_accel (void) { #ifdef HAVE_ACCEL @@ -451,35 +490,9 @@ cpu_accel (void) accel = arch_accel (); - return accel; + return (GimpCpuAccelFlags) accel; #else /* !HAVE_ACCEL */ - return 0; + return GIMP_CPU_ACCEL_NONE; #endif } - -void -cpu_accel_print_results (void) -{ - g_printerr ("Testing CPU features...\n"); - -#ifdef ARCH_X86 - g_printerr (" mmx : %s\n", - (cpu_accel() & CPU_ACCEL_X86_MMX) ? "yes" : "no"); - g_printerr (" 3dnow : %s\n", - (cpu_accel() & CPU_ACCEL_X86_3DNOW) ? "yes" : "no"); - g_printerr (" mmxext : %s\n", - (cpu_accel() & CPU_ACCEL_X86_MMXEXT) ? "yes" : "no"); - g_printerr (" sse : %s\n", - (cpu_accel() & CPU_ACCEL_X86_SSE) ? "yes" : "no"); - g_printerr (" sse2 : %s\n", - (cpu_accel() & CPU_ACCEL_X86_SSE2) ? "yes" : "no"); - g_printerr (" sse3 : %s\n", - (cpu_accel() & CPU_ACCEL_X86_SSE3) ? "yes" : "no"); -#endif -#ifdef ARCH_PPC - g_printerr (" altivec : %s\n", - (cpu_accel() & CPU_ACCEL_PPC_ALTIVEC) ? "yes" : "no"); -#endif - g_printerr ("\n"); -} diff --git a/libgimpbase/gimpcpuaccel.h b/libgimpbase/gimpcpuaccel.h index 9871a29e05..7c4f1f4d54 100644 --- a/libgimpbase/gimpcpuaccel.h +++ b/libgimpbase/gimpcpuaccel.h @@ -1,48 +1,52 @@ -/* The GIMP -- an image manipulation program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. * - * This program is distributed in the hope that it will be useful, + * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ -/* - * CPU acceleration detection was taken from DirectFB but seems to be - * originating from mpeg2dec with the following copyright: - * - * Copyright (C) 1999-2001 Aaron Holtzman - */ +#ifndef __GIMP_CPU_ACCEL_H__ +#define __GIMP_CPU_ACCEL_H__ -#ifndef __CPU_ACCEL_H__ -#define __CPU_ACCEL_H__ +G_BEGIN_DECLS -/* x86 accelerations */ -#define CPU_ACCEL_X86_MMX 0x80000000 -#define CPU_ACCEL_X86_3DNOW 0x40000000 -#define CPU_ACCEL_X86_MMXEXT 0x20000000 -#define CPU_ACCEL_X86_SSE 0x10000000 -#define CPU_ACCEL_X86_SSE2 0x08000000 -#define CPU_ACCEL_X86_SSE3 0x02000000 +typedef enum +{ + GIMP_CPU_ACCEL_NONE = 0x0, -/* powerpc accelerations */ -#define CPU_ACCEL_PPC_ALTIVEC 0x04000000 + /* x86 accelerations */ + GIMP_CPU_ACCEL_X86_MMX = 0x80000000, + GIMP_CPU_ACCEL_X86_3DNOW = 0x40000000, + GIMP_CPU_ACCEL_X86_MMXEXT = 0x20000000, + GIMP_CPU_ACCEL_X86_SSE = 0x10000000, + GIMP_CPU_ACCEL_X86_SSE2 = 0x08000000, + GIMP_CPU_ACCEL_X86_SSE3 = 0x02000000, + + /* powerpc accelerations */ + GIMP_CPU_ACCEL_PPC_ALTIVEC = 0x04000000 +} GimpCpuAccelFlags; -guint32 cpu_accel (void) G_GNUC_CONST; - -void cpu_accel_print_results (void); +GimpCpuAccelFlags gimp_cpu_accel_get_support (void); -#endif /* __CPU_ACCEL_H__ */ +/* for internal use only */ +void gimp_cpu_accel_set_use (gboolean use); + +G_END_DECLS + +#endif /* __GIMP_CPU_ACCEL_H__ */ diff --git a/libgimpbase/test-cpu-accel.c b/libgimpbase/test-cpu-accel.c new file mode 100644 index 0000000000..5c0349f135 --- /dev/null +++ b/libgimpbase/test-cpu-accel.c @@ -0,0 +1,48 @@ +/* A small test program for the CPU detection code */ + +#include "config.h" + +#include + +#include + +#include "gimpcpuaccel.h" + + +static void +cpu_accel_print_results (void) +{ + GimpCpuAccelFlags support; + + g_printerr ("Testing CPU features...\n"); + + support = gimp_cpu_accel_get_support (); + +#ifdef ARCH_X86 + g_printerr (" mmx : %s\n", + (support & GIMP_CPU_ACCEL_X86_MMX) ? "yes" : "no"); + g_printerr (" 3dnow : %s\n", + (support & GIMP_CPU_ACCEL_X86_3DNOW) ? "yes" : "no"); + g_printerr (" mmxext : %s\n", + (support & GIMP_CPU_ACCEL_X86_MMXEXT) ? "yes" : "no"); + g_printerr (" sse : %s\n", + (support & GIMP_CPU_ACCEL_X86_SSE) ? "yes" : "no"); + g_printerr (" sse2 : %s\n", + (support & GIMP_CPU_ACCEL_X86_SSE2) ? "yes" : "no"); + g_printerr (" sse3 : %s\n", + (support & GIMP_CPU_ACCEL_X86_SSE3) ? "yes" : "no"); +#endif +#ifdef ARCH_PPC + g_printerr (" altivec : %s\n", + (support & GIMP_CPU_ACCEL_PPC_ALTIVEC) ? "yes" : "no"); +#endif + g_printerr ("\n"); +} + +int +main (void) +{ + cpu_accel_print_results (); + + return EXIT_SUCCESS; +}