kwo pushed a commit to branch master. http://git.enlightenment.org/legacy/imlib2.git/commit/?id=273a7aaac34d12670f6249f575e6b703494eff30
commit 273a7aaac34d12670f6249f575e6b703494eff30 Author: Kim Woelders <k...@woelders.dk> Date: Wed Dec 1 18:53:54 2021 +0100 Refactor condition for using assembly functions Makes it easier to override the decision for testing. Setting IMLIB2_ASM_OFF will now disable use of assembly functions. --- src/lib/Makefile.am | 1 + src/lib/asm_c.c | 32 ++++++++++++++++++++++++++++++++ src/lib/asm_c.h | 8 ++++++++ src/lib/blend.c | 7 +++---- src/lib/common.h | 7 ------- src/lib/rotate.c | 3 ++- src/lib/scale.c | 5 +++-- src/lib/x11_rgba.c | 3 ++- 8 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 1fdedc5..7201f45 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -13,6 +13,7 @@ include_HEADERS = Imlib2.h libImlib2_la_SOURCES = \ api.c \ asm.h \ +asm_c.c asm_c.h \ blend.c blend.h \ color_helpers.c color_helpers.h \ colormod.c colormod.h \ diff --git a/src/lib/asm_c.c b/src/lib/asm_c.c new file mode 100644 index 0000000..05540aa --- /dev/null +++ b/src/lib/asm_c.c @@ -0,0 +1,32 @@ +#include "common.h" + +#include "asm_c.h" + +#if defined(DO_MMX_ASM) || defined(DO_AMD64_ASM) +#if DO_MMX_ASM +#define CPUID_MMX (1 << 23) +#define CPUID_XMM (1 << 25) +int __imlib_get_cpuid(void); +#endif + +int +__imlib_do_asm(void) +{ + static char _cpu_can_asm = -1; + + if (_cpu_can_asm < 0) + { + if (getenv("IMLIB2_ASM_OFF")) + _cpu_can_asm = 0; + else +#if DO_MMX_ASM + _cpu_can_asm = !!(__imlib_get_cpuid() & CPUID_MMX); +#elif DO_AMD64_ASM + _cpu_can_asm = 1; // instruction set is always present +#endif + } + + return _cpu_can_asm; +} + +#endif diff --git a/src/lib/asm_c.h b/src/lib/asm_c.h new file mode 100644 index 0000000..46fc9cf --- /dev/null +++ b/src/lib/asm_c.h @@ -0,0 +1,8 @@ +#ifndef ASM_C_H +#define ASM_C_H 1 + +#if defined(DO_MMX_ASM) || defined(DO_AMD64_ASM) +int __imlib_do_asm(void); +#endif + +#endif /* ASM_C_H */ diff --git a/src/lib/blend.c b/src/lib/blend.c index 92521ab..3442090 100644 --- a/src/lib/blend.c +++ b/src/lib/blend.c @@ -1,5 +1,6 @@ #include "common.h" +#include "asm_c.h" #include "blend.h" #include "colormod.h" #include "image.h" @@ -1721,10 +1722,8 @@ __imlib_GetBlendFunction(ImlibOp op, char blend, char merge_alpha, char rgb_src, if (op < OP_COPY || op > OP_RESHADE) return NULL; -#ifdef DO_MMX_ASM - do_mmx = !!(__imlib_get_cpuid() & CPUID_MMX); -#elif DO_AMD64_ASM - do_mmx = 1; // instruction set is always present +#if defined(DO_MMX_ASM) || defined(DO_AMD64_ASM) + do_mmx = __imlib_do_asm(); #endif if (cm && rgb_src && (A_CMOD(cm, 0xff) == 0xff)) diff --git a/src/lib/common.h b/src/lib/common.h index 7dcbc92..ec0ddb4 100644 --- a/src/lib/common.h +++ b/src/lib/common.h @@ -55,13 +55,6 @@ #define PIXEL_G(argb) (((argb) >> 8) & 0xff) #define PIXEL_B(argb) (((argb) ) & 0xff) -#ifdef DO_MMX_ASM -int __imlib_get_cpuid(void); - -#define CPUID_MMX (1 << 23) -#define CPUID_XMM (1 << 25) -#endif - #define CLIP(x, y, w, h, xx, yy, ww, hh) \ if (x < (xx)) { w += (x - (xx)); x = (xx); } \ if (y < (yy)) { h += (y - (yy)); y = (yy); } \ diff --git a/src/lib/rotate.c b/src/lib/rotate.c index 968a5a1..7c9a1d0 100644 --- a/src/lib/rotate.c +++ b/src/lib/rotate.c @@ -1,5 +1,6 @@ #include "common.h" +#include "asm_c.h" #include "blend.h" #include "rotate.h" @@ -211,7 +212,7 @@ __imlib_RotateAA(DATA32 * src, DATA32 * dest, int sow, int sw, int sh, return; #ifdef DO_MMX_ASM - if (__imlib_get_cpuid() & CPUID_MMX) + if (__imlib_do_asm()) { __imlib_mmx_RotateAA(src, dest, sow, sw, sh, dow, dw, dh, x, y, dxh, dyh, dxv, dyv); diff --git a/src/lib/scale.c b/src/lib/scale.c index c6b6bd0..22be22f 100644 --- a/src/lib/scale.c +++ b/src/lib/scale.c @@ -2,6 +2,7 @@ #include <assert.h> +#include "asm_c.h" #include "blend.h" #include "colormod.h" #include "image.h" @@ -318,7 +319,7 @@ __imlib_ScaleAARGBA(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy, int *yapoints; #ifdef DO_MMX_ASM - if (__imlib_get_cpuid() & CPUID_MMX) + if (__imlib_do_asm()) { __imlib_Scale_mmx_AARGBA(isi, dest, dxx, dyy, dx, dy, dw, dh, dow, sow); return; @@ -979,7 +980,7 @@ __imlib_ScaleAARGB(ImlibScaleInfo * isi, DATA32 * dest, int dxx, int dyy, int *yapoints; #ifdef DO_MMX_ASM - if (__imlib_get_cpuid() & CPUID_MMX) + if (__imlib_do_asm()) { __imlib_Scale_mmx_AARGBA(isi, dest, dxx, dyy, dx, dy, dw, dh, dow, sow); return; diff --git a/src/lib/x11_rgba.c b/src/lib/x11_rgba.c index e2e8d65..f2d9425 100644 --- a/src/lib/x11_rgba.c +++ b/src/lib/x11_rgba.c @@ -2,6 +2,7 @@ #include <X11/Xlib.h> +#include "asm_c.h" #include "x11_context.h" #include "x11_rgba.h" @@ -4824,7 +4825,7 @@ __imlib_GetRGBAFunction(int depth, else { #ifdef DO_MMX_ASM - if (__imlib_get_cpuid() && CPUID_MMX) + if (__imlib_do_asm()) { if ((rm == 0xf800) && (gm == 0x7e0) && (bm == 0x1f)) return __imlib_mmx_rgb565_fast; --