From b02c41914314455087394cb9c18408bb91e65a82 Mon Sep 17 00:00:00 2001 From: Duilio Protti Date: Wed, 29 Jun 2016 17:01:46 -0300 Subject: [PATCH] Fixed MMX configuration on 64 bit hosts --- configure.ac | 41 ++++++++++--------- src/cputest.c | 1 + src/renderer.cc | 105 ++++-------------------------------------------- 3 files changed, 31 insertions(+), 116 deletions(-) diff --git a/configure.ac b/configure.ac index bbec4e0..73ffb72 100644 --- a/configure.ac +++ b/configure.ac @@ -69,25 +69,39 @@ else *** using the GNU C compiler. ]) fi - + +AC_CHECK_SIZEOF([size_t]) +AC_MSG_CHECKING([whether compiler is 32 or 64 bit]) +if test x$ac_cv_sizeof_size_t = x8; then + AC_MSG_RESULT([64]) + compiler_width=64 +else + AC_MSG_RESULT([32]) + compiler_width=32 +fi + # Check for library functions. AC_CHECK_FUNCS([floor sqrt]) # Arguments to specify certain features. AC_ARG_ENABLE([mmx], - AS_HELP_STRING([--enable-mmx],[Turn on MMX detection support @<:@default=enabled@:>@]), + AS_HELP_STRING([--enable-mmx],[use MMX if available and if building with a 32 bit compiler @<:@default=enabled@:>@]), [mmx=$enableval], - [mmx=no]) -AC_MSG_CHECKING([whether to enable MMX detection support]) + [mmx=yes]) +AC_MSG_CHECKING([whether to enable MMX]) if test x$mmx = xyes; then - AC_MSG_RESULT([yes]) - AC_DEFINE([MMX_DETECTION], [1], [Activate MMX Extensions support]) + if test x$compiler_width = x32; then + AC_MSG_RESULT([yes]) + AC_DEFINE([MMX_DETECTION], [1], [Activate MMX Extensions support]) + else + AC_MSG_RESULT([no, was requested but feature is not supported with a 64bit compiler]) + fi else AC_MSG_RESULT([no]) fi AC_ARG_ENABLE([debug], - AS_HELP_STRING([--enable-debug],[Turn on debug mode @<:@default=disabled@:>@]), + AS_HELP_STRING([--enable-debug],[turn on debug mode @<:@default=disabled@:>@]), [debug=$enableval], [debug=no]) @@ -107,7 +121,7 @@ if test x"$GCC" = xyes; then fi AC_ARG_ENABLE([vectorization], - AS_HELP_STRING([--enable-vectorization],[Turn on vectorization optimizations (gcc >= 4 only) @<:@default=enabled@:>@]), + AS_HELP_STRING([--enable-vectorization],[turn on vectorization optimizations (gcc >= 4 only) @<:@default=enabled@:>@]), [vectorization=$enableval], [vectorization=yes]) @@ -129,17 +143,6 @@ if test x"$vectorization" = xyes; then ;; *) INF_CFLAGS_EXTRA="${INF_CFLAGS_EXTRA} -ftree-vectorize" - case "$target_cpu" in - i*86|ia64*) - # TODO check for sse2 availability - INF_CFLAGS_EXTRA="${INF_CFLAGS_EXTRA} -msse" - ;; - powerpc|ppc) - INF_CFLAGS_EXTRA="${INF_CFLAGS_EXTRA} -maltivec" - ;; - *) - ;; - esac ;; esac fi diff --git a/src/cputest.c b/src/cputest.c index b6f197c..cab9cc0 100644 --- a/src/cputest.c +++ b/src/cputest.c @@ -2,6 +2,7 @@ #include "cputest.h" #include "glib.h" +// This code is 32-bit only /* ebx saving is necessary for PIC. gcc seems unable to see it alone */ #if MMX_DETECTION diff --git a/src/renderer.cc b/src/renderer.cc index 0fd62ec..c20ce3b 100644 --- a/src/renderer.cc +++ b/src/renderer.cc @@ -70,9 +70,6 @@ static SDL_Thread *thread; static gint32 event_filter(const SDL_Event *event); static void check_events(); static int renderer(void *); -#if MMX_DETECTION -static int renderer_mmx(void *); -#endif static void set_title(void); void renderer_init(void) @@ -121,11 +118,6 @@ void renderer_init(void) SDL_SetEventFilter(event_filter); -#if MMX_DETECTION - if (mm_support_check_and_show() != 0) - thread = SDL_CreateThread(renderer_mmx, NULL); - else -#endif thread = SDL_CreateThread(renderer, NULL); } @@ -410,11 +402,15 @@ static int renderer(void *arg) gint32 frame_length; gint32 fps, new_fps; gint32 t_between_effects, t_between_colors; + gint32 has_mmx = 0; fps = aud_get_int(CFGID, "max_fps"); frame_length = calculate_frame_length_usecs(fps, __LINE__); t_between_effects = aud_get_int(CFGID, "effect_time"); t_between_colors = aud_get_int(CFGID, "palette_time"); +#if MMX_DETECTION + has_mmx = mm_support_check_and_show(); +#endif initializing = FALSE; for (;; ) { /* ever... */ if (!visible) { @@ -437,7 +433,10 @@ static int renderer(void *arg) g_return_val_if_fail(SDL_UnlockMutex(resizing_mutex) >= 0, -1); } auto t_begin = g_get_monotonic_time(); - display_blur(scr_par.width * scr_par.height * current_effect.num_effect); + if (has_mmx) + display_blur_mmx(scr_par.width * scr_par.height * current_effect.num_effect); + else + display_blur(scr_par.width * scr_par.height * current_effect.num_effect); spectral(¤t_effect); curve(¤t_effect); if (t_last_color <= 32) @@ -489,94 +488,6 @@ static int renderer(void *arg) return 0; } -#if MMX_DETECTION -static int renderer_mmx(void *arg) -{ - gint32 render_time, now; - gint32 frame_length; - gint32 idle_time; - gint32 fps, new_fps; - gint32 t_between_effects, t_between_colors; - - fps = aud_get_int(CFGID, "max_fps"); - frame_length = calculate_frame_length(fps, __LINE__); - t_between_effects = aud_get_int(CFGID, "effect_time"); - t_between_colors = aud_get_int(CFGID, "palette_time"); - initializing = FALSE; - for (;; ) { /* ever... */ - if (!visible) { - check_events(); - if (finished) - break; - g_usleep(3000 * frame_length); - continue; - } - check_events(); - if (finished) - break; - if (must_resize) { - display_resize(scr_par.width, scr_par.height); - aud_set_int(CFGID, "width", scr_par.width); - aud_set_int(CFGID, "heigth", scr_par.height); - must_resize = FALSE; - g_return_val_if_fail(SDL_LockMutex(resizing_mutex) >= 0, -1); - resizing = FALSE; - g_return_val_if_fail(SDL_UnlockMutex(resizing_mutex) >= 0, -1); - } - auto t_begin = g_get_monotonic_time(); - display_blur_mmx(scr_par.width * scr_par.height * current_effect.num_effect); - spectral(¤t_effect); - curve(¤t_effect); - if (t_last_color <= 32) - change_color(old_color, color, t_last_color * 8); - next_color(); - next_effect(); - if (t_last_effect % t_between_effects == 0) { -#ifdef INFINITY_DEBUG - if (!mode_interactif) { - display_load_random_effect(¤t_effect); - t_last_effect = 0; - t_between_effects = aud_get_int(CFGID, "effect_time"); - } -#else - display_load_random_effect(¤t_effect); - t_last_effect = 0; - t_between_effects = aud_get_int(CFGID, "effect_time"); -#endif - } - if (t_last_color % t_between_colors == 0) { -#ifdef INFINITY_DEBUG - if (!mode_interactif) { - old_color = color; - color = rand() % NB_PALETTES; - t_last_color = 0; - t_between_colors = aud_get_int(CFGID, "palette_time"); - } -#else - old_color = color; - color = rand() % NB_PALETTES; - t_last_color = 0; - t_between_colors = aud_get_int(CFGID, "palette_time"); -#endif - } - - new_fps = aud_get_int(CFGID, "max_fps"); - if (new_fps != fps) { - fps = new_fps; - frame_length = calculate_frame_length(fps, __LINE__); - } - - auto now = g_get_monotonic_time(); - auto render_time = now - t_begin; - if (render_time < frame_length) { - g_usleep(frame_length - render_time); - } - } - - return 0; -} -#endif /* MMX_DETECTION */ - static void set_title(void) { SDL_WM_SetCaption(current_title, "Infinity");